/** * Increases the counter by length, if not null. */ public static void inc(AccessCounter counter, int length) { if (counter != null) counter.inc(length); }
/** * Increases the counter by one, if not null. */ public static void inc(AccessCounter counter) { if (counter != null) counter.inc(); }
/** * Increases the counter by one, if not null. */ public static void inc(AccessCounter counter) { if (counter != null) counter.inc(); }
/** * Increases the counter by length, if not null. */ public static void inc(AccessCounter counter, int length) { if (counter != null) counter.inc(length); }
public static void int8(long value, OutputStream stream, AccessCounter counter) throws IOException { stream.write((int) value); inc(counter); }
public static void int8(long value, OutputStream stream, AccessCounter counter) throws IOException { stream.write((int) value); inc(counter); }
public static int uint16(InputStream in, AccessCounter counter) throws IOException { inc(counter, 2); return in.read() << 8 | in.read(); }
public static byte[] bytes(InputStream in, int count, AccessCounter counter) throws IOException { byte[] result = new byte[count]; int off = 0; while (off < count) { int read = in.read(result, off, count - off); if (read < 0) { throw new IOException("Unexpected end of stream, wanted to read " + count + " bytes but only got " + off); } off += read; } inc(counter, count); return result; }
public static byte[] bytes(InputStream stream, int count, AccessCounter counter) throws IOException { byte[] result = new byte[count]; int off = 0; while (off < count) { int read = stream.read(result, off, count - off); if (read < 0) { throw new IOException("Unexpected end of stream, wanted to read " + count + " bytes but only got " + off); } off += read; } inc(counter, count); return result; }
public static int uint16(InputStream stream, AccessCounter counter) throws IOException { inc(counter, 2); return stream.read() * 256 + stream.read(); }
public static void int16(long value, OutputStream stream, AccessCounter counter) throws IOException { stream.write(ByteBuffer.allocate(2).putShort((short) value).array()); inc(counter, 2); }
public static void int32(long value, OutputStream stream, AccessCounter counter) throws IOException { stream.write(ByteBuffer.allocate(4).putInt((int) value).array()); inc(counter, 4); }
public static void int32(long value, OutputStream stream, AccessCounter counter) throws IOException { stream.write(ByteBuffer.allocate(4).putInt((int) value).array()); inc(counter, 4); }
public static void int64(long value, OutputStream stream, AccessCounter counter) throws IOException { stream.write(ByteBuffer.allocate(8).putLong(value).array()); inc(counter, 8); }
public static long uint32(InputStream in, AccessCounter counter) throws IOException { inc(counter, 4); return in.read() << 24 | in.read() << 16 | in.read() << 8 | in.read(); }
public static void varInt(long value, OutputStream stream, AccessCounter counter) throws IOException { ByteBuffer buffer = ByteBuffer.allocate(9); varInt(value, buffer); buffer.flip(); stream.write(buffer.array(), 0, buffer.limit()); inc(counter, buffer.limit()); }
public static long int64(InputStream in, AccessCounter counter) throws IOException { inc(counter, 8); return ByteBuffer.wrap(bytes(in, 8)).getLong(); }
public static int int32(InputStream stream, AccessCounter counter) throws IOException { inc(counter, 4); return ByteBuffer.wrap(bytes(stream, 4)).getInt(); }
public static long int64(InputStream stream, AccessCounter counter) throws IOException { inc(counter, 8); return ByteBuffer.wrap(bytes(stream, 8)).getLong(); }
public static int int32(InputStream in, AccessCounter counter) throws IOException { inc(counter, 4); return ByteBuffer.wrap(bytes(in, 4)).getInt(); }