Hi guys,
I wrote this a few days ago for my MMORPG.
You can read and write Strings, etc in a Input- or OutputStream with bytes.
Have fun, feel free to add something!package com.verficon.io; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class ByteStream { private byte[] buffer; private int pos; public static ByteStream create() { final ByteStream s = new ByteStream(); s.buffer = new byte[1024]; return s; } public boolean readBuffer(final InputStream is) throws IOException { return is.read(buffer) != -1; } public byte readByte() { checkBuffer(); return buffer[pos++]; } public void writeByte(final byte b) { checkBuffer(); buffer[pos++] = b; } private void checkBuffer() { if (pos >= buffer.length) pos = 0; } public String readString() { final byte length = readByte(); final byte[] b = new byte[length]; for (int i = 0; i < length; i++) { b[i] = readByte(); } return new String(b); } public void writeString(final String s) { final byte[] b = s.getBytes(); writeByte((byte) b.length); for (int i = 0; i < b.length; i++) { writeByte(b[i]); } } public void flushBuffer(final OutputStream os) throws IOException { os.write(buffer); buffer = new byte[1024]; } }
Feel free to click the 'Thank' button
Download as External Java Libary: http://www.multiupload.com/AIRXTDUHFZ