List of usage examples for java.nio ByteOrder BIG_ENDIAN
ByteOrder BIG_ENDIAN
To view the source code for java.nio ByteOrder BIG_ENDIAN.
Click Source Link
From source file:io.warp10.quasar.encoder.QuasarTokenEncoder.java
public String getTokenIdent(String token, byte[] tokenSipHashkey) { long ident = SipHashInline.hash24_palindromic(tokenSipHashkey, token.getBytes()); ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.order(ByteOrder.BIG_ENDIAN); buffer.putLong(ident);/*w w w. j a va2 s .c o m*/ return Hex.encodeHexString(buffer.array()); }
From source file:ome.io.bioformats.BfPyramidPixelBuffer.java
/** * Creates a new series for the destination metadata store. * @param metadata Metadata store and retrieve implementation. * @param pixels Source pixels set./*from ww w. j a v a2s.c o m*/ * @param series Destination series. * @param sizeX Destination X width. Not necessarily * <code>Pixels.SizeX</code>. * @param sizeY Destination Y height. Not necessarily * <code>Pixels.SizeY</code>. * @throws EnumerationException */ private void createSeries(int series, int sizeX, int sizeY) throws EnumerationException { metadata.setImageID("Image:" + series, series); metadata.setPixelsID("Pixels: " + series, series); metadata.setPixelsBinDataBigEndian(byteOrder == ByteOrder.BIG_ENDIAN ? true : false, series, 0); metadata.setPixelsDimensionOrder(DimensionOrder.XYZCT, series); metadata.setPixelsType(ome.xml.model.enums.PixelType.fromString(pixels.getPixelsType().getValue()), series); metadata.setPixelsSizeX(new PositiveInteger(sizeX), series); metadata.setPixelsSizeY(new PositiveInteger(sizeY), series); metadata.setPixelsSizeZ(new PositiveInteger(1), series); metadata.setPixelsSizeC(new PositiveInteger(1), series); int totalPlanes = pixels.getSizeZ() * pixels.getSizeC() * pixels.getSizeT(); metadata.setPixelsSizeT(new PositiveInteger(totalPlanes), series); metadata.setChannelID("Channel:" + series, series, 0); metadata.setChannelSamplesPerPixel(new PositiveInteger(1), series, 0); if (log.isDebugEnabled()) { log.debug(String.format("Added series %d %dx%dx%d", series, sizeX, sizeY, totalPlanes)); } }
From source file:io.warp10.quasar.encoder.QuasarTokenEncoder.java
private ByteBuffer toByteBuffer(String strUUID) { ByteBuffer buffer = ByteBuffer.allocate(16); buffer.order(ByteOrder.BIG_ENDIAN); UUID uuid = UUID.fromString(strUUID); buffer.putLong(uuid.getMostSignificantBits()); buffer.putLong(uuid.getLeastSignificantBits()); buffer.position(0);//from w ww. j a va2 s . c om return buffer; }
From source file:nl.salp.warcraft4j.casc.cdn.EncodingFileParser.java
private EncodingFileHeader parseHeader(DataReader reader) throws DataReadingException, DataParsingException, CascParsingException { String magicString = reader.readNext(DataTypeFactory.getFixedLengthString(2, StandardCharsets.US_ASCII)); if (!MAGIC_STRING.equals(magicString)) { throw new CascParsingException( format("Encoding file starts with magic string %s instead of %s", magicString, MAGIC_STRING)); }/*from w ww . j a va 2 s. c o m*/ byte[] unknown1 = reader.readNext(DataTypeFactory.getByteArray(3)); int unknown2 = reader.readNext(DataTypeFactory.getUnsignedShort(), ByteOrder.LITTLE_ENDIAN); int unknown3 = reader.readNext(DataTypeFactory.getUnsignedShort(), ByteOrder.LITTLE_ENDIAN); long segmentCount = reader.readNext(DataTypeFactory.getUnsignedInteger(), ByteOrder.BIG_ENDIAN); long unknown4 = reader.readNext(DataTypeFactory.getUnsignedInteger(), ByteOrder.BIG_ENDIAN); byte unknown5 = reader.readNext(DataTypeFactory.getByte()); long segmentOffset = reader.readNext(DataTypeFactory.getUnsignedInteger(), ByteOrder.BIG_ENDIAN); return new EncodingFileHeader(magicString, unknown1, unknown2, unknown3, segmentCount, unknown4, unknown5, segmentOffset); }
From source file:io.github.msdk.io.mzdata.MzDataSaxHandler.java
/** * {@inheritDoc}// w w w . j a v a 2 s . co m * * endElement() */ @SuppressWarnings("null") public void endElement(String namespaceURI, String sName, String qName) throws SAXException { if (canceled) throw new SAXException("Parsing Cancelled"); // <spectrumInstrument> if (qName.equalsIgnoreCase("spectrumInstrument")) { spectrumInstrumentFlag = false; } // <precursor> if (qName.equalsIgnoreCase("precursor")) { precursorFlag = false; } // <spectrum> if (qName.equalsIgnoreCase("spectrum")) { spectrumInstrumentFlag = false; // Auto-detect whether this scan is centroided MsSpectrumType spectrumType = SpectrumTypeDetectionAlgorithm.detectSpectrumType(mzBuffer, intensityBuffer, peaksCount); // Create a new scan MsFunction msFunction = MSDKObjectBuilder.getMsFunction(msLevel); MsScan newScan = MSDKObjectBuilder.getMsScan(dataStore, scanNumber, msFunction); newScan.setDataPoints(mzBuffer, intensityBuffer, peaksCount); newScan.setSpectrumType(spectrumType); newScan.setPolarity(polarity); if (retentionTime != null) { ChromatographyInfo chromInfo = MSDKObjectBuilder.getChromatographyInfo1D(SeparationType.UNKNOWN, retentionTime); newScan.setChromatographyInfo(chromInfo); } if (precursorMz != null) { IsolationInfo isolation = MSDKObjectBuilder.getIsolationInfo(Range.singleton(precursorMz), null, precursorMz, precursorCharge, null); newScan.getIsolations().add(isolation); } // Add the scan to the file newRawFile.addScan(newScan); parsedScans++; } // <mzArrayBinary> if (qName.equalsIgnoreCase("mzArrayBinary")) { mzArrayBinaryFlag = false; // Allocate space for the whole array if (mzBuffer.length < peaksCount) mzBuffer = new double[peaksCount * 2]; byte[] peakBytes = Base64.decodeBase64(charBuffer.toString().getBytes()); ByteBuffer currentMzBytes = ByteBuffer.wrap(peakBytes); if (endian.equals("big")) { currentMzBytes = currentMzBytes.order(ByteOrder.BIG_ENDIAN); } else { currentMzBytes = currentMzBytes.order(ByteOrder.LITTLE_ENDIAN); } for (int i = 0; i < peaksCount; i++) { if (precision == null || precision.equals("32")) mzBuffer[i] = (double) currentMzBytes.getFloat(); else mzBuffer[i] = currentMzBytes.getDouble(); } } // <intenArrayBinary> if (qName.equalsIgnoreCase("intenArrayBinary")) { intenArrayBinaryFlag = false; // Allocate space for the whole array if (intensityBuffer.length < peaksCount) intensityBuffer = new float[peaksCount * 2]; byte[] peakBytes = Base64.decodeBase64(charBuffer.toString().getBytes()); ByteBuffer currentIntensityBytes = ByteBuffer.wrap(peakBytes); if (endian.equals("big")) { currentIntensityBytes = currentIntensityBytes.order(ByteOrder.BIG_ENDIAN); } else { currentIntensityBytes = currentIntensityBytes.order(ByteOrder.LITTLE_ENDIAN); } for (int i = 0; i < peaksCount; i++) { if (precision == null || precision.equals("32")) intensityBuffer[i] = currentIntensityBytes.getFloat(); else intensityBuffer[i] = (float) currentIntensityBytes.getDouble(); } } }
From source file:nl.salp.warcraft4j.casc.cdn.local.LocalIndexFileParser.java
/** * Read and parse an {@link IndexEntry}. * * @param reader The reader to read the entry data from. * * @return The parsed entry.// w w w .ja va 2 s .co m * * @throws DataReadingException When reading the entry data failed. * @throws DataParsingException When parsing the entry data failed. */ private IndexEntry parseEntry(DataReader reader) throws DataReadingException, DataParsingException { byte[] fileKey = reader.readNext(DataTypeFactory.getByteArray(9)); short indexInfoHigh = reader.readNext(DataTypeFactory.getUnsignedByte()); long indexInfoLow = reader.readNext(DataTypeFactory.getUnsignedInteger(), ByteOrder.BIG_ENDIAN); long fileSize = reader.readNext(DataTypeFactory.getUnsignedInteger(), ByteOrder.LITTLE_ENDIAN); IndexEntry entry = new LocalIndexEntry(new FileKey(fileKey), indexInfoHigh, indexInfoLow, fileSize); return entry; }
From source file:ubic.gemma.core.loader.expression.arrayDesign.AffyChipTypeExtractor.java
private static String parseGenericCCHeader(DataInputStream str) throws IOException { /*/*from ww w.java 2 s . com*/ * acquisition data, intensity data etc. Usually "intensity data" for the first header. */ String datatypeIdentifier = readString(str); AffyChipTypeExtractor.log.debug(datatypeIdentifier); String guid = readString(str); AffyChipTypeExtractor.log.debug(guid); // we just need to read thsee off, even if we aren't using it. @SuppressWarnings("unused") String createDate = readUnicodeString(str); // blank? @SuppressWarnings("unused") String locale = readUnicodeString(str); // e.g. en-US int numKeyValuePairs = readIntBigEndian(str); // e.g. 55 String result = null; for (int i = 0; i < numKeyValuePairs; i++) { String name = readUnicodeString(str); byte[] value = readBytes(str); String type = readUnicodeString(str); Object v; switch (type) { case "text/x-calvin-float": { FloatBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asFloatBuffer(); float[] array = new float[intBuf.remaining()]; intBuf.get(array); break; } case "text/plain": case "text/ascii": // text/ascii is undocumented, but needed. v = new String(value, "US-ASCII"); String vv = new String(((String) v).getBytes(), "UTF-16").trim(); if (name.equals("affymetrix-array-type")) { return vv; } break; case "text-x-calvin-unsigned-integer-8": { ShortBuffer intBuf = ByteBuffer.wrap(value).asShortBuffer(); short[] array = new short[intBuf.remaining()]; intBuf.get(array); break; } case "text/x-calvin-integer-16": { IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer(); // wrong? int[] array = new int[intBuf.remaining()]; intBuf.get(array); break; } case "text/x-calvin-integer-32": { IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer(); int[] array = new int[intBuf.remaining()]; intBuf.get(array); break; } case "text/x-calvin-unsigned-integer-8": { ShortBuffer intBuf = ByteBuffer.wrap(value).asShortBuffer(); short[] array = new short[intBuf.remaining()]; intBuf.get(array); break; } case "text/x-calvin-unsigned-integer-16": { IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer();// wrong? int[] array = new int[intBuf.remaining()]; intBuf.get(array); break; } case "text/x-calvin-unsigned-integer-32": { IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer(); int[] array = new int[intBuf.remaining()]; intBuf.get(array); break; } default: throw new IOException("Unknown mime type:" + type); } } @SuppressWarnings("unused") int numParentHeaders = readIntBigEndian(str); return result; }
From source file:io.warp10.continuum.gts.GTSDecoder.java
/** * Attempt to read the next measurement and associated metadata (timestamp, location, elevation) * @return true if a measurement was successfully read, false if none were left in the buffer. *///from w ww . j a va 2 s . c om public boolean next() { // // Update position prior to reading the next value, etc so we can // this.position = this.buffer.position(); if (!buffer.hasRemaining()) { return false; } this.nextCalled = true; // // Read timestamp/type flag // byte tsTypeFlag = buffer.get(); // // Check if we encountered encrypted data // if (GTSEncoder.FLAGS_ENCRYPTED == (tsTypeFlag & GTSEncoder.FLAGS_MASK_ENCRYPTED)) { // // Extract encrypted length // int enclen = (int) Varint.decodeUnsignedLong(buffer); // // If there is no decryption key, simply skip the encrypted data // and call next recursively. // if (null == wrappingKey) { buffer.position(buffer.position() + enclen); // WARNING(hbs): if there are many encrypted chunks this may lead to a stack overflow return next(); } byte[] encrypted = new byte[enclen]; buffer.get(encrypted); // // Decrypt the encrypted data // AESWrapEngine engine = new AESWrapEngine(); CipherParameters params = new KeyParameter(this.wrappingKey); engine.init(false, params); try { byte[] decrypted = engine.unwrap(encrypted, 0, encrypted.length); // // Unpad the decrypted data // PKCS7Padding padding = new PKCS7Padding(); int padcount = padding.padCount(decrypted); // // Replace the current buffer with a new one containing the // decrypted data followed by any remaining data in the original // buffer. // ByteBuffer bb = ByteBuffer.allocate(decrypted.length - padcount + this.buffer.remaining()); bb.put(decrypted, 0, decrypted.length - padcount); bb.put(this.buffer); bb.flip(); this.buffer = bb; } catch (InvalidCipherTextException icte) { // FIXME(hbs): log this somewhere... // // Skip the encrypted chunk we failed to decrypt // } // // Call next recursively // // WARNING(hbs): we may hit StackOverflow in some cases return next(); } // // Read location/elevation flag if needed // byte locElevFlag = 0x0; if (GTSEncoder.FLAGS_CONTINUATION == (tsTypeFlag & GTSEncoder.FLAGS_CONTINUATION)) { if (!buffer.hasRemaining()) { return false; } locElevFlag = buffer.get(); } // // Read timestamp // switch (tsTypeFlag & GTSEncoder.FLAGS_MASK_TIMESTAMP) { case GTSEncoder.FLAGS_TIMESTAMP_RAW_ABSOLUTE: { ByteOrder order = buffer.order(); buffer.order(ByteOrder.BIG_ENDIAN); previousLastTimestamp = lastTimestamp; lastTimestamp = buffer.getLong(); buffer.order(order); } break; //case GTSEncoder.FLAGS_TIMESTAMP_ZIGZAG_ABSOLUTE: // previousLastTimestamp = lastTimestamp; // lastTimestamp = Varint.decodeSignedLong(buffer); // break; case GTSEncoder.FLAGS_TIMESTAMP_EQUALS_BASE: previousLastTimestamp = lastTimestamp; lastTimestamp = baseTimestamp; break; case GTSEncoder.FLAGS_TIMESTAMP_ZIGZAG_DELTA_BASE: { long delta = Varint.decodeSignedLong(buffer); previousLastTimestamp = lastTimestamp; lastTimestamp = baseTimestamp + delta; } break; case GTSEncoder.FLAGS_TIMESTAMP_ZIGZAG_DELTA_PREVIOUS: { long delta = Varint.decodeSignedLong(buffer); previousLastTimestamp = lastTimestamp; lastTimestamp = lastTimestamp + delta; } break; default: throw new RuntimeException("Invalid timestamp format."); } // // Read location/elevation // if (GTSEncoder.FLAGS_LOCATION == (locElevFlag & GTSEncoder.FLAGS_LOCATION)) { if (GTSEncoder.FLAGS_LOCATION_IDENTICAL != (locElevFlag & GTSEncoder.FLAGS_LOCATION_IDENTICAL)) { if (GTSEncoder.FLAGS_LOCATION_GEOXPPOINT_ZIGZAG_DELTA == (locElevFlag & GTSEncoder.FLAGS_LOCATION_GEOXPPOINT_ZIGZAG_DELTA)) { long delta = Varint.decodeSignedLong(buffer); previousLastGeoXPPoint = lastGeoXPPoint; lastGeoXPPoint = lastGeoXPPoint + delta; } else { ByteOrder order = buffer.order(); buffer.order(ByteOrder.BIG_ENDIAN); previousLastGeoXPPoint = lastGeoXPPoint; lastGeoXPPoint = buffer.getLong(); buffer.order(order); } } } else { previousLastGeoXPPoint = lastGeoXPPoint; lastGeoXPPoint = GeoTimeSerie.NO_LOCATION; } if (GTSEncoder.FLAGS_ELEVATION == (locElevFlag & GTSEncoder.FLAGS_ELEVATION)) { if (GTSEncoder.FLAGS_ELEVATION_IDENTICAL != (locElevFlag & GTSEncoder.FLAGS_ELEVATION_IDENTICAL)) { boolean zigzag = GTSEncoder.FLAGS_ELEVATION_ZIGZAG == (locElevFlag & GTSEncoder.FLAGS_ELEVATION_ZIGZAG); long encoded; if (zigzag) { encoded = Varint.decodeSignedLong(buffer); } else { ByteOrder order = buffer.order(); buffer.order(ByteOrder.BIG_ENDIAN); encoded = buffer.getLong(); buffer.order(order); } if (GTSEncoder.FLAGS_ELEVATION_DELTA_PREVIOUS == (locElevFlag & GTSEncoder.FLAGS_ELEVATION_DELTA_PREVIOUS)) { previousLastElevation = lastElevation; lastElevation = lastElevation + encoded; } else { previousLastElevation = lastElevation; lastElevation = encoded; } } } else { previousLastElevation = lastElevation; lastElevation = GeoTimeSerie.NO_ELEVATION; } // // Extract value // switch (tsTypeFlag & GTSEncoder.FLAGS_MASK_TYPE) { case GTSEncoder.FLAGS_TYPE_LONG: lastType = TYPE.LONG; if (GTSEncoder.FLAGS_VALUE_IDENTICAL != (tsTypeFlag & GTSEncoder.FLAGS_VALUE_IDENTICAL)) { long encoded; if (GTSEncoder.FLAGS_LONG_ZIGZAG == (tsTypeFlag & GTSEncoder.FLAGS_LONG_ZIGZAG)) { encoded = Varint.decodeSignedLong(buffer); } else { ByteOrder order = buffer.order(); buffer.order(ByteOrder.BIG_ENDIAN); encoded = buffer.getLong(); buffer.order(order); } if (GTSEncoder.FLAGS_LONG_DELTA_PREVIOUS == (tsTypeFlag & GTSEncoder.FLAGS_LONG_DELTA_PREVIOUS)) { previousLastLongValue = lastLongValue; lastLongValue = lastLongValue + encoded; } else { previousLastLongValue = lastLongValue; lastLongValue = encoded; } } else { previousLastLongValue = lastLongValue; } break; case GTSEncoder.FLAGS_TYPE_DOUBLE: lastType = TYPE.DOUBLE; if (GTSEncoder.FLAGS_VALUE_IDENTICAL != (tsTypeFlag & GTSEncoder.FLAGS_VALUE_IDENTICAL)) { if (GTSEncoder.FLAGS_DOUBLE_IEEE754 == (tsTypeFlag & GTSEncoder.FLAGS_DOUBLE_IEEE754)) { ByteOrder order = buffer.order(); buffer.order(ByteOrder.BIG_ENDIAN); previousLastDoubleValue = lastDoubleValue; lastDoubleValue = buffer.getDouble(); previousLastBDValue = lastBDValue; lastBDValue = null; buffer.order(order); } else { int scale = buffer.get(); long unscaled = Varint.decodeSignedLong(buffer); previousLastBDValue = lastBDValue; lastBDValue = new BigDecimal(new BigInteger(Long.toString(unscaled)), scale); } } else { previousLastDoubleValue = lastDoubleValue; previousLastBDValue = lastBDValue; } break; case GTSEncoder.FLAGS_TYPE_STRING: lastType = TYPE.STRING; if (GTSEncoder.FLAGS_VALUE_IDENTICAL != (tsTypeFlag & GTSEncoder.FLAGS_VALUE_IDENTICAL)) { // Decode String length long len = Varint.decodeUnsignedLong(buffer); // Prevent excessive allocation if (len > buffer.remaining()) { throw new RuntimeException("Invalid string length."); } byte[] utf8 = new byte[(int) len]; // Read String UTF8 representation buffer.get(utf8); previousLastStringValue = lastStringValue; lastStringValue = new String(utf8, Charsets.UTF_8); } else { previousLastStringValue = lastStringValue; } break; case GTSEncoder.FLAGS_TYPE_BOOLEAN: if (GTSEncoder.FLAGS_DELETE_MARKER == (tsTypeFlag & GTSEncoder.FLAGS_MASK_TYPE_FLAGS)) { lastType = TYPE.UNDEFINED; } else { lastType = TYPE.BOOLEAN; if (GTSEncoder.FLAGS_BOOLEAN_VALUE_TRUE == (tsTypeFlag & GTSEncoder.FLAGS_MASK_TYPE_FLAGS)) { lastBooleanValue = true; } else if (GTSEncoder.FLAGS_BOOLEAN_VALUE_FALSE == (tsTypeFlag & GTSEncoder.FLAGS_MASK_TYPE_FLAGS)) { lastBooleanValue = false; } else { throw new RuntimeException("Invalid boolean value."); } //lastBooleanValue = GTSEncoder.FLAGS_BOOLEAN_VALUE == (tsTypeFlag & GTSEncoder.FLAGS_BOOLEAN_VALUE); } break; default: throw new RuntimeException("Invalid type encountered!"); } return true; }
From source file:xbird.storage.io.RemoteVarSegments.java
private byte[] recvResponse(final ByteChannel channel, final ByteBuffer rcvBuf) throws IOException { ByteBuffer tmpBuf = ByteBuffer.allocate(4); NIOUtils.readFully(channel, tmpBuf, 4); tmpBuf.flip();/*from w w w .ja v a 2 s .com*/ int datalen = tmpBuf.getInt(); final ByteBuffer buf = truncateBuffer(rcvBuf, datalen); NIOUtils.readFully(channel, buf, datalen); buf.flip(); if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) { buf.order(ByteOrder.BIG_ENDIAN); } final byte[] b = new byte[datalen]; buf.get(b); if (buf != rcvBuf) { _rbufPool.returnObject(buf); } return b; }
From source file:ubic.gemma.core.analysis.preprocess.batcheffects.AffyScanDateExtractor.java
private int readIntBigEndian(DataInputStream dis) throws IOException { byte[] buf = new byte[4]; for (int i = 0; i < buf.length; i++) { buf[i] = dis.readByte();//from w w w.j a va2s.c om } return ByteBuffer.wrap(buf).order(ByteOrder.BIG_ENDIAN).getInt(); }