List of usage examples for java.nio ByteBuffer getInt
public abstract int getInt();
From source file:com.buaa.cfs.common.oncrpc.XDR.java
public static boolean isLastFragment(byte[] mark) { ByteBuffer b = ByteBuffer.wrap(mark); int n = b.getInt(); return (n & 0x80000000) != 0; }
From source file:org.eclipse.packagedrone.utils.rpm.app.Dumper.java
private static void dumpHeader(final String string, final InputHeader<? extends RpmBaseTag> header, final Function<Integer, Object> func, final boolean sorted) { System.out.println(string);/* w w w. ja v a 2 s . co m*/ System.out.println("================================="); Set<Entry<Integer, HeaderValue>> data; if (sorted) { data = new TreeMap<>(header.getRawTags()).entrySet(); } else { data = header.getRawTags().entrySet(); } for (final Map.Entry<Integer, HeaderValue> entry : data) { Object tag = func.apply(entry.getKey()); if (tag == null) { tag = entry.getKey(); } System.out.format("%20s - %s%n", tag, Rpms.dumpValue(entry.getValue())); if (entry.getKey() == 62 || entry.getKey() == 63) { final ByteBuffer buf = ByteBuffer.wrap((byte[]) entry.getValue().getValue()); System.out.format("Immutable - tag: %s, type: %s, position: %s, count: %s%n", buf.getInt(), buf.getInt(), buf.getInt(), buf.getInt()); } } }
From source file:com.ebay.pulsar.analytics.cache.MemcachedCache.java
private static byte[] deserializeValue(NamedKey key, byte[] bytes) { ByteBuffer buf = ByteBuffer.wrap(bytes); final int keyLength = buf.getInt(); byte[] keyBytes = new byte[keyLength]; buf.get(keyBytes);/*w w w . j a v a 2 s . c o m*/ byte[] value = new byte[buf.remaining()]; buf.get(value); Preconditions.checkState(Arrays.equals(keyBytes, key.toByteArray()), "Keys do not match, possible hash collision?"); return value; }
From source file:com.nridge.core.base.std.BufUtl.java
/** * Retrieves a <i>String</i> value stored within the body of the * <code>ByteBuffer</code> object. * * @param aBuffer Packet byte buffer object. * @return A <i>String</i> object. *//*from w ww .j a v a 2 s. c om*/ public static String getString(ByteBuffer aBuffer) { int strLength; StringBuilder strBuilder; strLength = aBuffer.getInt(); if (strLength > 0) strBuilder = new StringBuilder(strLength + 10); else strBuilder = new StringBuilder(); for (int i = 0; i < strLength; i++) strBuilder.append(aBuffer.getChar()); return strBuilder.toString(); }
From source file:ConversionUtil.java
public static int convertToInt(byte[] array) { ByteBuffer buffer = ByteBuffer.wrap(array); return buffer.getInt(); /*/*from www. ja v a 2 s . c om*/ int value = 0; for (int i =0;i<array.length; ++i) { int offset = (array.length -i-1) *8; value += (array[i] << offset); // bytes[i] = (byte)((value & (0xff << offset)) >>> offset); } return value; **/ }
From source file:org.bimserver.collada.SupportFunctions.java
public static List<String> intBufferToStringList(ByteBuffer buffer, Format formatter) { List<Integer> list = new ArrayList<Integer>(); while (buffer.hasRemaining()) list.add(new Integer(buffer.getInt())); // Get the data as a list of String objects. return SupportFunctions.listToStringList(list, formatter); }
From source file:org.apache.myriad.state.utils.ByteBufferSupport.java
public static Protos.SlaveID toSlaveId(ByteBuffer bb) { int size = bb.getInt(); if (size > 0) { try {//from w w w .j a v a 2 s. c o m return Protos.SlaveID.parseFrom(getBytes(bb, size)); } catch (Exception e) { throw new RuntimeException("ByteBuffer not in expected format," + " failed to parse SlaveId bytes", e); } } else { return null; } }
From source file:org.apache.myriad.state.utils.ByteBufferSupport.java
public static Protos.TaskStatus toTaskStatus(ByteBuffer bb) { int size = bb.getInt(); if (size > 0) { try {/*from w w w .j a v a 2s . c o m*/ return Protos.TaskStatus.parseFrom(getBytes(bb, size)); } catch (Exception e) { throw new RuntimeException( "ByteBuffer not in expected format," + " failed to parse TaskStatus bytes", e); } } else { return null; } }
From source file:org.apache.myriad.state.utils.ByteBufferSupport.java
public static Protos.ExecutorInfo toExecutorInfo(ByteBuffer bb) { int size = bb.getInt(); if (size > 0) { try {/* w w w . j av a 2 s . com*/ return Protos.ExecutorInfo.parseFrom(getBytes(bb, size)); } catch (Exception e) { throw new RuntimeException( "ByteBuffer not in expected format," + " failed to parse ExecutorInfo bytes", e); } } else { return null; } }
From source file:org.apache.myriad.state.utils.ByteBufferSupport.java
public static ByteBuffer createBuffer(ByteBuffer bb) { return fillBuffer(getBytes(bb, bb.getInt())); }