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

com.faker.android.paker.SafeString Maven / Gradle / Ivy

There is a newer version: 1.0.38
Show newest version
package com.faker.android.paker;


import com.google.common.io.LittleEndianDataInputStream;
import com.google.common.io.LittleEndianDataOutputStream;

import java.io.IOException;

class SafeString {


    public SafeString(){
    }

    public static void write(LittleEndianDataOutputStream stream, String s) throws IOException {
        byte bt[] = s.getBytes();
        stream.writeInt(bt.length);
        stream.write(bt);
    }

    public static String read(LittleEndianDataInputStream stream) throws IOException {
         int len = stream.readInt();
         byte[] buf = new byte[len];
         int retLen = stream.read(buf, 0, len);
         if (retLen != len){
             throw new IOException("File Length Not Enougth");
         }
         return new String(buf);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy