protected boolean readBoolean(byte[] content) throws IOException { boolean value = ByteUtils.convertBooleanFromBytes(content, index); index += 1; return value; }
protected double readDouble(byte[] content) throws IOException { double value = ByteUtils.convertDoubleFromBytes(content, index); index += 8; return value; }
protected float readFloat(byte[] content) throws IOException { float value = ByteUtils.convertFloatFromBytes(content, index); index += 4; return value; }
protected int readInt(byte[] content) throws IOException { byte[] bytes = inflateFrom(content, index); index += 1 + bytes.length; bytes = ByteUtils.rightAlignBytes(bytes, 4); int value = ByteUtils.convertIntFromBytes(bytes); if (value == BinaryOutputCapsule.NULL_OBJECT || value == BinaryOutputCapsule.DEFAULT_OBJECT) index -= 4; return value; }
protected long readLong(byte[] content) throws IOException { byte[] bytes = inflateFrom(content, index); index += 1 + bytes.length; bytes = ByteUtils.rightAlignBytes(bytes, 8); long value = ByteUtils.convertLongFromBytes(bytes); return value; }
protected static byte[] inflateFrom(byte[] contents, int index) { byte firstByte = contents[index]; if (firstByte == BinaryOutputCapsule.NULL_OBJECT) return ByteUtils.convertToBytes(BinaryOutputCapsule.NULL_OBJECT); else if (firstByte == BinaryOutputCapsule.DEFAULT_OBJECT) return ByteUtils.convertToBytes(BinaryOutputCapsule.DEFAULT_OBJECT); else if (firstByte == 0) return new byte[0]; else { byte[] rVal = new byte[firstByte]; for (int x = 0; x < rVal.length; x++) rVal[x] = contents[x + 1 + index]; return rVal; } }
public static int convertIntFromBytes(byte[] byteArray) { return convertIntFromBytes(byteArray, 0); }
public static long convertLongFromBytes(byte[] bytes) { return convertLongFromBytes(bytes, 0); }
protected short readShort(byte[] content) throws IOException { short value = ByteUtils.convertShortFromBytes(content, index); index += 2; return value; }
int maybeSignature = ByteUtils.readInt(bis); if (maybeSignature == FormatVersion.SIGNATURE){ formatVersion = ByteUtils.readInt(bis); numClasses = ByteUtils.readInt(bis); classHierarchyVersions = new int[classHierarchySize]; for (int j = 0; j < classHierarchySize; j++){ classHierarchyVersions[j] = ByteUtils.readInt(bis); int classLength = ByteUtils.readInt(bis); String className = readString(bis, classLength); int fields = ByteUtils.readInt(bis); bytes += (8 + aliasWidth + classLength); int fieldNameLength = ByteUtils.readInt(bis); String fieldName = readString(bis, fieldNameLength); BinaryClassField bcf = new BinaryClassField(fieldName, fieldAlias, fieldType); int numLocs = ByteUtils.readInt(bis); bytes = 4; locationTable.clear(); for(int i = 0; i < numLocs; i++) { int id = ByteUtils.readInt(bis); int loc = ByteUtils.readInt(bis); locationTable.put(id, loc); bytes += 8;
public static byte[] convertToBytes(double n) { long bits = Double.doubleToLongBits(n); return convertToBytes(bits); }
public static float convertFloatFromBytes(byte[] byteArray, int offset) { // Convert it to an int int number = convertIntFromBytes(byteArray, offset); return Float.intBitsToFloat(number); }
protected int readInt(byte[] content) throws IOException { byte[] bytes = inflateFrom(content, index); index += 1 + bytes.length; bytes = ByteUtils.rightAlignBytes(bytes, 4); int value = ByteUtils.convertIntFromBytes(bytes); if (value == BinaryOutputCapsule.NULL_OBJECT || value == BinaryOutputCapsule.DEFAULT_OBJECT) index -= 4; return value; }
protected long readLong(byte[] content) throws IOException { byte[] bytes = inflateFrom(content, index); index += 1 + bytes.length; bytes = ByteUtils.rightAlignBytes(bytes, 8); long value = ByteUtils.convertLongFromBytes(bytes); return value; }
public static double convertDoubleFromBytes(byte[] bytes, int offset) { // Convert it to a double long bits = convertLongFromBytes(bytes, offset); return Double.longBitsToDouble(bits); }
public static short convertShortFromBytes(byte[] byteArray) { return convertShortFromBytes(byteArray, 0); }
int maybeSignature = ByteUtils.readInt(bis); if (maybeSignature == FormatVersion.SIGNATURE){ formatVersion = ByteUtils.readInt(bis); numClasses = ByteUtils.readInt(bis); classHierarchyVersions = new int[classHierarchySize]; for (int j = 0; j < classHierarchySize; j++){ classHierarchyVersions[j] = ByteUtils.readInt(bis); int classLength = ByteUtils.readInt(bis); String className = readString(bis, classLength); int fields = ByteUtils.readInt(bis); bytes += (8 + aliasWidth + classLength); int fieldNameLength = ByteUtils.readInt(bis); String fieldName = readString(bis, fieldNameLength); BinaryClassField bcf = new BinaryClassField(fieldName, fieldAlias, fieldType); int numLocs = ByteUtils.readInt(bis); bytes = 4; locationTable.clear(); for(int i = 0; i < numLocs; i++) { int id = ByteUtils.readInt(bis); int loc = ByteUtils.readInt(bis); locationTable.put(id, loc); bytes += 8;
public static byte[] convertToBytes(float f) { int temp = Float.floatToIntBits(f); return convertToBytes(temp); }
protected static byte[] deflate(byte[] bytes) { int size = bytes.length; if (size == 4) { int possibleMagic = ByteUtils.convertIntFromBytes(bytes); if (possibleMagic == NULL_OBJECT) return NULL_BYTES; else if (possibleMagic == DEFAULT_OBJECT) return DEFAULT_BYTES; } for (int x = 0; x < bytes.length; x++) { if (bytes[x] != 0) break; size--; } if (size == 0) return new byte[1]; byte[] rVal = new byte[1 + size]; rVal[0] = (byte) size; for (int x = 1; x < rVal.length; x++) rVal[x] = bytes[bytes.length - size - 1 + x]; return rVal; }
protected int readInt(byte[] content) throws IOException { byte[] bytes = inflateFrom(content, index); index += 1 + bytes.length; bytes = ByteUtils.rightAlignBytes(bytes, 4); int value = ByteUtils.convertIntFromBytes(bytes); if (value == BinaryOutputCapsule.NULL_OBJECT || value == BinaryOutputCapsule.DEFAULT_OBJECT) index -= 4; return value; }