/** * Converts a byte array with 4 elements to a float. Used to put floats into a byte[] payload in a convenient * and fast way by shifting without using streams (which is kind of slow). Use * {@link net.semanticmetadata.lire.utils.SerializationUtils#toBytes(float)} to encode. * * @param data the input byte array * @return the resulting float * @see net.semanticmetadata.lire.utils.SerializationUtils#toBytes(float) */ public static float toFloat(byte[] data) { return Float.intBitsToFloat(toInt(data)); }
public static int[] toIntArray(byte[] in, int offset, int length) { int[] result = new int[(length >> 2)]; byte[] tmp = new byte[4]; for (int i = 0; i < length >> 2; i++) { System.arraycopy(in, offset + (i * 4), tmp, 0, 4); result[i] = toInt(tmp); } return result; }
/** * Converts a byte array with 4 elements to a float. Used to put floats into a byte[] payload in a convenient * and fast way by shifting without using streams (which is kind of slow). Use * {@link net.semanticmetadata.lire.utils.SerializationUtils#toBytes(float)} to encode. * * @param data the input byte array * @return the resulting float * @see net.semanticmetadata.lire.utils.SerializationUtils#toBytes(float) */ public static float toFloat(byte[] data) { return Float.intBitsToFloat(toInt(data)); }
public static int[] toIntArray(byte[] in, int offset, int length) { int[] result = new int[(length >> 2)]; byte[] tmp = new byte[4]; for (int i = 0; i < length >> 2; i++) { System.arraycopy(in, offset + (i * 4), tmp, 0, 4); result[i] = toInt(tmp); } return result; }
/** * Convenience method to create an int[] array from a byte[] array. * * @param data the byte[] array to decode * @return the decoded int[] */ public static int[] toIntArray(byte[] data) { int[] result = new int[data.length / 4]; byte[] tmp = new byte[4]; for (int i = 0; i < result.length; i++) { System.arraycopy(data, i * 4, tmp, 0, 4); result[i] = toInt(tmp); } return result; }
/** * Convenience method to create an int[] array from a byte[] array. * * @param data the byte[] array to decode * @return the decoded int[] */ public static int[] toIntArray(byte[] data) { int[] result = new int[data.length / 4]; byte[] tmp = new byte[4]; for (int i = 0; i < result.length; i++) { System.arraycopy(data, i * 4, tmp, 0, 4); result[i] = toInt(tmp); } return result; }
public static Cluster[] readClusters(String file) throws IOException { FileInputStream fin = new FileInputStream(file); byte[] tmp = new byte[4]; fin.read(tmp, 0, 4); Cluster[] result = new Cluster[SerializationUtils.toInt(tmp)]; fin.read(tmp, 0, 4); int size = SerializationUtils.toInt(tmp); tmp = new byte[size * 8]; int bytesRead; for (int i = 0; i < result.length; i++) { bytesRead = fin.read(tmp, 0, size * 8); if (bytesRead != size * 8) System.err.println("Didn't read enough bytes ..."); result[i] = new Cluster(); result[i].setByteRepresentation(tmp); } fin.close(); return result; } }
public static Cluster[] readClusters(String file) throws IOException { FileInputStream fin = new FileInputStream(file); byte[] tmp = new byte[4]; fin.read(tmp, 0, 4); Cluster[] result = new Cluster[SerializationUtils.toInt(tmp)]; fin.read(tmp, 0, 4); int size = SerializationUtils.toInt(tmp); tmp = new byte[size * 8]; int bytesRead; for (int i = 0; i < result.length; i++) { bytesRead = fin.read(tmp, 0, size * 8); if (bytesRead != size * 8) System.err.println("Didn't read enough bytes ..."); result[i] = new Cluster(); result[i].setByteRepresentation(tmp); } fin.close(); return result; } }
/** * Converts a byte array with 4 elements to a float. Used to put floats into a byte[] payload in a convenient * and fast way by shifting without using streams (which is kind of slow). Use * {@link net.semanticmetadata.lire.utils.SerializationUtils#toBytes(float)} to encode. * * @param data the input byte array * @return the resulting float * @see net.semanticmetadata.lire.utils.SerializationUtils#toBytes(float) */ public static float toFloat(byte[] data) { return Float.intBitsToFloat(toInt(data)); }
public static int[] toIntArray(byte[] in, int offset, int length) { int[] result = new int[(length >> 2)]; byte[] tmp = new byte[4]; for (int i = 0; i < length >> 2; i++) { System.arraycopy(in, offset + (i * 4), tmp, 0, 4); result[i] = toInt(tmp); } return result; }
/** * Convenience method to create an int[] array from a byte[] array. * * @param data the byte[] array to decode * @return the decoded int[] */ public static int[] toIntArray(byte[] data) { int[] result = new int[data.length / 4]; byte[] tmp = new byte[4]; for (int i = 0; i < result.length; i++) { System.arraycopy(data, i * 4, tmp, 0, 4); result[i] = toInt(tmp); } return result; }
public static Cluster[] readClusters(String file) throws IOException { FileInputStream fin = new FileInputStream(file); byte[] tmp = new byte[4]; fin.read(tmp, 0, 4); Cluster[] result = new Cluster[SerializationUtils.toInt(tmp)]; tmp = new byte[128 * 8]; for (int i = 0; i < result.length; i++) { int bytesRead = fin.read(tmp, 0, 128 * 8); if (bytesRead != 128 * 8) System.err.println("Didn't read enough bytes ..."); result[i] = new Cluster(); result[i].setByteRepresentation(tmp); } fin.close(); return result; }
tmpf = SerializationUtils.toInt(tempIntf); inf.read(tempf, 0, tmpf); while (inf.read(tempIntf, 0, 1) > 0) { tmpf = SerializationUtils.toInt(tempIntf); inf.read(tempf, 0, tmpf); f.setByteArrayRepresentation(tempf, 0, tmpf); tmp = SerializationUtils.toInt(tempInt); in.read(temp, 0, tmp); String filename = new String(temp, 0, tmp); tmp = SerializationUtils.toInt(tempInt); in.read(temp, 0, tmp); f.setByteArrayRepresentation(temp, 0, tmp);
byte[] tempf = new byte[100 * 1024]; while ((tmpf = inf.read(tempIntf, 0, 4)) > 0) { tmpf = SerializationUtils.toInt(tempIntf); inf.read(tempf, 0, tmpf); while (inf.read(tempIntf, 0, 1) > 0) { tmpf = SerializationUtils.toInt(tempIntf); inf.read(tempf, 0, tmpf); f.setByteArrayRepresentation(tempf, 0, tmpf);