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

org.nustaq.offheap.bytez.bytesource.UTFStringByteSource Maven / Gradle / Ivy

Go to download

A fast java serialization drop in-replacement and some serialization based utils such as Structs and OffHeap Memory.

There is a newer version: 3.0.4-jdk17
Show newest version
package org.nustaq.offheap.bytez.bytesource;

import org.nustaq.offheap.bytez.ByteSource;
import org.nustaq.serialization.util.FSTUtil;

import java.io.UnsupportedEncodingException;

/**
 * Created by ruedi on 05/08/15.
 */
public class UTFStringByteSource implements ByteSource {

    byte bytes[];

    public UTFStringByteSource(String key) {
        try {
            bytes = key.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            FSTUtil.rethrow(e);
        }
    }

    @Override
    public byte get(long index) {
        return bytes[((int) index)];
    }

    @Override
    public long length() {
        return bytes.length;
    }

    public UTFStringByteSource padLeft(int keyLen) {
        if ( bytes.length < keyLen ) {
            byte newBytes[] = new byte[keyLen];
            System.arraycopy(bytes,0,newBytes,keyLen-bytes.length,bytes.length);
            bytes = newBytes;
        }
        return this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy