List of usage examples for java.nio ByteBuffer getFloat
public abstract float getFloat();
From source file:edu.umn.msi.tropix.proteomics.conversion.impl.ConversionUtils.java
public static double[] extractDoublesLittleEndian(final byte[] bytes, final boolean is64Bit) { double[] doubles; ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer.order(ByteOrder.LITTLE_ENDIAN); if (is64Bit) { doubles = new double[bytes.length / 8]; for (int i = 0; i < doubles.length; i++) { doubles[i] = byteBuffer.getDouble(); }/*from w w w. j a v a 2 s . c om*/ } else { doubles = new double[bytes.length / 4]; for (int i = 0; i < doubles.length; i++) { doubles[i] = byteBuffer.getFloat(); } } return doubles; }
From source file:org.mcisb.util.math.MathUtils.java
/** * /* ww w. ja v a 2s .c o m*/ * @param encoded * @param bigEndian * @param doublePrecision * @return double[] */ public static double[] decode(final byte[] encoded, final boolean bigEndian, final boolean doublePrecision) { final byte[] bytes = Base64.decode(encoded); ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer = byteBuffer.order(bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); final int limit = byteBuffer.limit(); double[] decoded = new double[((doublePrecision) ? limit / DOUBLE_LENGTH : limit / FLOAT_LENGTH)]; int i = 0; while (byteBuffer.hasRemaining()) { if (doublePrecision) { decoded[i++] = byteBuffer.getDouble(); } else { decoded[i++] = byteBuffer.getFloat(); } } return decoded; }
From source file:com.netflix.aegisthus.pig.AegisthusLoadCaster.java
@Override public Float bytesToFloat(byte[] arg0) throws IOException { if (arg0 == null || arg0.length == 0) { return null; }//from w ww. j a va 2 s. c o m try { byte[] by = hex.decode(arg0); ByteBuffer bb = ByteBuffer.allocate(by.length); bb.put(by); bb.position(0); return bb.getFloat(); } catch (Exception e) { LOG.error("failed to convert " + new String(arg0) + " to float"); return null; } }
From source file:MSUmpire.SpectrumParser.mzXMLReadUnit.java
private void ParsePeakString(ScanData scan, String peakString) throws IOException, DataFormatException { int offset;/*w ww . j a va 2 s . c o m*/ peakString = peakString.replaceAll("\n", ""); byte[] decoded = Base64.decodeBase64(peakString.getBytes()); if ("zlib".equals(scan.compressionType)) { decoded = ZlibUncompressBuffer(decoded); } switch (scan.precision) { case (32): { offset = 0; for (int i = 0; i < scan.PeaksCountString; i++) { byte[] mz = new byte[] { decoded[offset], decoded[offset + 1], decoded[offset + 2], decoded[offset + 3] }; byte[] intensity = new byte[] { decoded[offset + 4], decoded[offset + 5], decoded[offset + 6], decoded[offset + 7] }; ByteBuffer mzBuffer = ByteBuffer.wrap(mz); ByteBuffer intBuffer = ByteBuffer.wrap(intensity); float intensityfloat = intBuffer.getFloat(); float mzfloat = mzBuffer.getFloat(); if (intensityfloat > 0f) { scan.AddPoint(mzfloat, intensityfloat); } mz = null; intensity = null; mzBuffer.clear(); intBuffer.clear(); mzBuffer = null; intBuffer = null; offset += 8; } break; } case (64): { offset = 0; for (int i = 0; i < scan.PeaksCountString; i++) { byte[] mz = new byte[] { decoded[offset], decoded[offset + 1], decoded[offset + 2], decoded[offset + 3], decoded[offset + 4], decoded[offset + 5], decoded[offset + 6], decoded[offset + 7] }; byte[] intensity = new byte[] { decoded[offset + 8], decoded[offset + 9], decoded[offset + 10], decoded[offset + 11], decoded[offset + 12], decoded[offset + 13], decoded[offset + 14], decoded[offset + 15] }; ByteBuffer mzBuffer = ByteBuffer.wrap(mz); ByteBuffer intBuffer = ByteBuffer.wrap(intensity); float intensityfloat = (float) intBuffer.getDouble(); float mzfloat = (float) mzBuffer.getDouble(); if (intensityfloat > 0f) { scan.AddPoint(mzfloat, intensityfloat); } mz = null; intensity = null; mzBuffer.clear(); intBuffer.clear(); mzBuffer = null; intBuffer = null; offset += 16; } break; } } peakString = null; decoded = null; }
From source file:de.unibayreuth.bayeos.goat.table.MassenTableModel.java
public boolean load(ObjektNode objekt, TimeFilter tFilter, StatusFilter sFilter) { try {/*ww w . j a v a 2s . com*/ Vector params = new Vector(); params.add(objekt.getId()); params.add(tFilter.getVector()); params.add(sFilter.getVector()); Vector vReturn = (Vector) xmlClient.execute("MassenTableHandler.getRows", params); // Rows als byte[] byte[] ba = (byte[]) vReturn.elementAt(1); statusList = new ArrayByteList(ba.length / rowLength); vonList = new ArrayIntList(ba.length / rowLength); wertList = new ArrayDoubleList(ba.length / rowLength); ByteBuffer b = ByteBuffer.wrap(ba); while (b.hasRemaining()) { vonList.add(b.getInt()); wertList.add((double) b.getFloat()); statusList.add(b.get()); } vReturn = null; logger.debug("MassenTableModel filled with " + getRowCount() + " records."); return true; } catch (XmlRpcException e) { MsgBox.error(e.getMessage()); return false; } }
From source file:au.org.ala.delta.io.BinFile.java
public float readFloat() { ByteBuffer b = readByteBuffer(4); return b.getFloat(); }
From source file:indexer.DocVector.java
public DocVector(Document doc, int numDimensions, int numIntervals, boolean unused) { // Read the floating point number array from the index BytesRef bytesRef = doc.getBinaryValue(DocVector.FIELD_VEC); ByteBuffer buff = ByteBuffer.wrap(bytesRef.bytes); this.x = new float[numDimensions]; for (int i = 0; i < x.length; i++) { this.x[i] = buff.getFloat(); }// w ww . j a v a 2s . co m this.numDimensions = numDimensions; DocVector.numIntervals = numIntervals; this.docName = doc.get(DocVector.FIELD_ID); }
From source file:au.org.ala.delta.io.BinaryKeyFile.java
public List<Float> readFloatList(int recordNum, int numFloats) { seek(recordOffset(recordNum));// w ww .java2 s . c o m ByteBuffer bb = readByteBuffer(numFloats * SIZE_INT_IN_BYTES); List<Float> retList = new ArrayList<Float>(); for (int i = 0; i < numFloats; i++) { retList.add(bb.getFloat()); } return retList; }
From source file:indexer.DocVector.java
public DocVector(Document doc, int numDimensions, int numIntervals) { // Read the floating point number array from the index BytesRef bytesRef = doc.getBinaryValue(DocVector.FIELD_VEC); ByteBuffer buff = ByteBuffer.wrap(bytesRef.bytes); this.x = new float[numDimensions]; for (int i = 0; i < x.length; i++) { this.x[i] = buff.getFloat(); }// w ww.j av a2 s.co m /* // Read the cell descriptors from the index String[] cellIds = doc.get(FIELD_CELL_ID).split("\\s+"); keys = new Cell[numDimensions]; for (int i=0; i < keys.length; i++) { keys[i] = new Cell(cellIds[i]); } */ this.numDimensions = numDimensions; DocVector.numIntervals = numIntervals; this.docName = doc.get(DocVector.FIELD_ID); quantized = quantize(); }
From source file:indexer.DocVector.java
public DocVector(Document doc, int numDimensions, int numIntervals, SplitCells splitCells) { // Read the floating point number array from the index BytesRef bytesRef = doc.getBinaryValue(DocVector.FIELD_VEC); ByteBuffer buff = ByteBuffer.wrap(bytesRef.bytes); this.x = new float[numDimensions]; for (int i = 0; i < x.length; i++) { this.x[i] = buff.getFloat(); }/*from w ww . j ava2s. c o m*/ // Read the cell descriptors from the index String[] cellIds = doc.get(FIELD_CELL_ID).split("\\s+"); keys = new Cell[numDimensions]; for (int i = 0; i < keys.length; i++) { keys[i] = new Cell(cellIds[i]); } this.numDimensions = numDimensions; DocVector.numIntervals = numIntervals; this.docName = doc.get(DocVector.FIELD_ID); if (splitCells == null) quantized = quantize(); else quantized = quantizeWithSplitCells(splitCells); }