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:edu.hawaii.soest.kilonalu.adam.AdamParser.java
/** * A method that gets the channel one data mimimum as a converted decimal float * * @return channelOneMin - the 2 bytes of the channelOneMin data as a float */// w ww. j a va 2 s .c o m public float getChannelOneMin() { this.channelOneMin.flip(); int channelData = (int) this.channelOneMin.order(ByteOrder.BIG_ENDIAN).getShort(); return getVoltage(channelData); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
private byte[] encodeSimpleMessage(short endpoint, byte command) { final short LENGTH_SIMPLEMESSAGE = 1; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_SIMPLEMESSAGE); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_SIMPLEMESSAGE);// w w w . j a va2s . c o m buf.putShort(endpoint); buf.put(command); return buf.array(); }
From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java
/** * A method that gets the channel two data mimimum as a converted decimal float * * @return channelTwoMin - the 2 bytes of the channelTwoMin data as a float *//*ww w . j ava2 s. c o m*/ public float getChannelTwoMin() { this.channelTwoMin.flip(); int channelData = (int) this.channelTwoMin.order(ByteOrder.BIG_ENDIAN).getShort(); return getVoltage(channelData); }
From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java
/** * A method that gets the channel three data mimimum as a converted decimal float * * @return channelThreeMin - the 2 bytes of the channelThreeMin data as a float *///from w ww.j a v a2 s. c om public float getChannelThreeMin() { this.channelThreeMin.flip(); int channelData = (int) this.channelThreeMin.order(ByteOrder.BIG_ENDIAN).getShort(); return getVoltage(channelData); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
private byte[] encodeMessage(short endpoint, byte type, int cookie, String[] parts) { // Calculate length first int length = LENGTH_PREFIX + 1; if (parts != null) { for (String s : parts) { if (s == null || s.equals("")) { length++; // encode null or empty strings as 0x00 later continue; }// w w w . j a va 2 s .co m length += (1 + s.getBytes().length); } } if (endpoint == ENDPOINT_PHONECONTROL) { length += 4; //for cookie; } // Encode Prefix ByteBuffer buf = ByteBuffer.allocate(length); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort((short) (length - LENGTH_PREFIX)); buf.putShort(endpoint); buf.put(type); if (endpoint == ENDPOINT_PHONECONTROL) { buf.putInt(cookie); } // Encode Pascal-Style Strings if (parts != null) { for (String s : parts) { if (s == null || s.equals("")) { buf.put((byte) 0x00); continue; } int partlength = s.getBytes().length; if (partlength > 255) partlength = 255; buf.put((byte) partlength); buf.put(s.getBytes(), 0, partlength); } } return buf.array(); }
From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java
/** * A method that gets the channel four data mimimum as a converted decimal float * * @return channelFourMin - the 2 bytes of the channelFourMin data as a float */// w w w .j a v a 2s. c om public float getChannelFourMin() { this.channelFourMin.flip(); int channelData = (int) this.channelFourMin.order(ByteOrder.BIG_ENDIAN).getShort(); return getVoltage(channelData); }
From source file:org.apache.hadoop.hbase.filter.SlicedRowFilter.java
public static SlicedRowFilter parseFrom(final byte[] pbBytes) throws DeserializationException { ByteBuffer bb = ByteBuffer.wrap(pbBytes).order(ByteOrder.BIG_ENDIAN); SlicedRowFilter filter = new SlicedRowFilter(); filter.count = bb.getLong();//from w w w . j a v a 2 s. c o m filter.slicesLength = bb.getInt(); int nbounds = bb.getInt(); filter.bounds = new int[nbounds]; for (int i = 0; i < nbounds; i++) { filter.bounds[i] = bb.getInt(); } // // If the first slice starts at offset 0 then we will be able to provide a key hint // if (0 == filter.bounds[0]) { filter.hasHinting = true; } else { filter.hasHinting = false; } filter.rangekeys = new byte[bb.getInt()]; bb.get(filter.rangekeys); filter.slice = new byte[filter.slicesLength]; return filter; }
From source file:ffx.xray.MTZFilter.java
public boolean readFcs(File mtzFile, ReflectionList reflectionlist, DiffractionRefinementData fcdata, CompositeConfiguration properties) { int nread, nignore, nres, nfriedel, ncut; ByteOrder b = ByteOrder.nativeOrder(); FileInputStream fis;/*from w w w . jav a2s.co m*/ DataInputStream dis; StringBuilder sb = new StringBuilder(); try { fis = new FileInputStream(mtzFile); dis = new DataInputStream(fis); byte headeroffset[] = new byte[4]; byte bytes[] = new byte[80]; int offset = 0; // eat "MTZ" title dis.read(bytes, offset, 4); String mtzstr = new String(bytes); // header offset dis.read(headeroffset, offset, 4); // machine stamp dis.read(bytes, offset, 4); ByteBuffer bb = ByteBuffer.wrap(bytes); int stamp = bb.order(ByteOrder.BIG_ENDIAN).getInt(); String stampstr = Integer.toHexString(stamp); switch (stampstr.charAt(0)) { case '1': case '3': if (b.equals(ByteOrder.LITTLE_ENDIAN)) { b = ByteOrder.BIG_ENDIAN; } break; case '4': if (b.equals(ByteOrder.BIG_ENDIAN)) { b = ByteOrder.LITTLE_ENDIAN; } break; } bb = ByteBuffer.wrap(headeroffset); int headeroffseti = bb.order(b).getInt(); // skip to header and parse dis.skipBytes((headeroffseti - 4) * 4); for (Boolean parsing = true; parsing; dis.read(bytes, offset, 80)) { mtzstr = new String(bytes); parsing = parseHeader(mtzstr); } // column identifiers fc = phic = fs = phis = -1; boolean print = true; parseFcColumns(print); if (h < 0 || k < 0 || l < 0) { String message = "Fatal error in MTZ file - no H K L indexes?\n"; logger.log(Level.SEVERE, message); return false; } // reopen to start at beginning fis = new FileInputStream(mtzFile); dis = new DataInputStream(fis); // skip initial header dis.skipBytes(80); float data[] = new float[nColumns]; HKL mate = new HKL(); // read in data ComplexNumber c = new ComplexNumber(); nread = nignore = nres = nfriedel = ncut = 0; for (int i = 0; i < nReflections; i++) { for (int j = 0; j < nColumns; j++) { dis.read(bytes, offset, 4); bb = ByteBuffer.wrap(bytes); data[j] = bb.order(b).getFloat(); } int ih = (int) data[h]; int ik = (int) data[k]; int il = (int) data[l]; boolean friedel = reflectionlist.findSymHKL(ih, ik, il, mate, false); HKL hkl = reflectionlist.getHKL(mate); if (hkl != null) { if (fc > 0 && phic > 0) { c.re(data[fc] * cos(toRadians(data[phic]))); c.im(data[fc] * sin(toRadians(data[phic]))); fcdata.setFc(hkl.index(), c); } if (fs > 0 && phis > 0) { c.re(data[fs] * cos(toRadians(data[phis]))); c.im(data[fs] * sin(toRadians(data[phis]))); fcdata.setFs(hkl.index(), c); } nread++; } else { HKL tmp = new HKL(ih, ik, il); if (!reflectionlist.resolution .inInverseResSqRange(Crystal.invressq(reflectionlist.crystal, tmp))) { nres++; } else { nignore++; } } } sb.append(String.format(" MTZ file type (machine stamp): %s\n", stampstr)); sb.append(String.format(" Fc HKL read in: %d\n", nread)); sb.append(String.format(" Fc HKL read as friedel mates: %d\n", nfriedel)); sb.append(String.format(" Fc HKL NOT read in (too high resolution): %d\n", nres)); sb.append(String.format(" Fc HKL NOT read in (not in internal list?): %d\n", nignore)); sb.append(String.format(" Fc HKL NOT read in (F/sigF cutoff): %d\n", ncut)); sb.append(String.format(" HKL in internal list: %d\n", reflectionlist.hkllist.size())); if (logger.isLoggable(Level.INFO)) { logger.info(sb.toString()); } } catch (EOFException eof) { System.out.println("EOF reached "); return false; } catch (IOException ioe) { System.out.println("IO Exception: " + ioe.getMessage()); return false; } return true; }
From source file:com.healthmarketscience.jackcess.impl.ColumnImpl.java
/** * Writes a numeric value./*from ww w. ja v a 2s . c o m*/ */ private void writeNumericValue(ByteBuffer buffer, Object value) throws IOException { Object inValue = value; try { BigDecimal decVal = toBigDecimal(value); inValue = decVal; int signum = decVal.signum(); if (signum < 0) { decVal = decVal.negate(); } // write sign byte buffer.put((signum < 0) ? NUMERIC_NEGATIVE_BYTE : 0); // adjust scale according to this column type (will cause the an // ArithmeticException if number has too many decimal places) decVal = decVal.setScale(getScale()); // check precision if (decVal.precision() > getPrecision()) { throw new IOException( "Numeric value is too big for specified precision " + getPrecision() + ": " + decVal); } // convert to unscaled BigInteger, big-endian bytes byte[] intValBytes = toUnscaledByteArray(decVal, getType().getFixedSize() - 1); if (buffer.order() != ByteOrder.BIG_ENDIAN) { fixNumericByteOrder(intValBytes); } buffer.put(intValBytes); } catch (ArithmeticException e) { throw (IOException) new IOException("Numeric value '" + inValue + "' out of range").initCause(e); } }
From source file:edu.hawaii.soest.kilonalu.adam.AdamParser.java
/** * A method that gets the channel five data mimimum as a converted decimal float * * @return channelFiveMin - the 2 bytes of the channelFiveMin data as a float *///from ww w .ja v a2 s .c om public float getChannelFiveMin() { this.channelFiveMin.flip(); int channelData = (int) this.channelFiveMin.order(ByteOrder.BIG_ENDIAN).getShort(); return getVoltage(channelData); }