All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.javanut.pronghorn.pipe.util.build.SecretByteSplitter Maven / Gradle / Ivy

Go to download

Ring buffer based queuing utility for applications that require high performance and/or a small footprint. Well suited for embedded and stream based processing.

There is a newer version: 1.1.27
Show newest version
package com.javanut.pronghorn.pipe.util.build;

import java.io.IOException;

public class SecretByteSplitter {

    
    public static  T scramble(CharSequence source, T target) {
        
        int i = source.length();
        while (--i>=0) {
            int x = (int)source.charAt(i);
            if ( x<0 | x>127 ) {
                throw new UnsupportedOperationException();
            }
            //we know that x is a small value 7 bit number            
            try {
                target.append((char)(48+(0xF&(x>>4))));
                target.append((char)(48+(0xF&x) ));                
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return target;
    }
    
    public static  T assemble(CharSequence source, T target) {
        int i = source.length();
        while (--i>=0) {
            int low = source.charAt(i);
            int high= source.charAt(--i);
            
            try {
                target.append((char) ( ((high-48)<<4) | (low-48) )  );
            } catch (IOException e) {
                throw new RuntimeException(e);
            }  
        }
        
        return target;
    }
    
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy