List of usage examples for java.io DataInput readUnsignedByte
int readUnsignedByte() throws IOException;
From source file:com.ibm.jaql.util.BaseUtil.java
/** * @param in// w w w .j a va2s . c o m * @return * @throws IOException */ public static long readVULong(DataInput in) throws IOException { int b = in.readUnsignedByte(); if (b <= 0xf7) { return b; } // 248 <= v <= maxLong b -= 0xf7; long v = 0; do { v = (v << 8) | in.readUnsignedByte(); b--; } while (b > 0); v += 0xf8; return v; }
From source file:com.ibm.jaql.util.BaseUtil.java
/** * @param in//from w w w .ja va 2 s. co m * @return * @throws IOException */ public static int readVUInt(DataInput in) throws IOException { int b = in.readUnsignedByte(); if (b <= 0xfB) { return b; } // 252 <= v <= maxLong b -= 0xfB; int v = 0; do { v = (v << 8) | in.readUnsignedByte(); b--; } while (b > 0); v += 0xFC; return v; }
From source file:CompressedNumber.java
/** * Read a long previously written by writeLong(). * //from w w w . j a va2 s . com * @exception IOException * an exception was thrown by a method on in. */ public static final long readLong(DataInput in) throws IOException { int int_value = in.readUnsignedByte(); if ((int_value & ~0x3f) == 0) { // test for small case first - assuming this is usual case. // this is stored in 2 bytes. return ((int_value << 8) | in.readUnsignedByte()); } else if ((int_value & 0x80) == 0) { // value is stored in 4 bytes. only use low 6 bits from 1st byte. return (((int_value & 0x3f) << 24) | (in.readUnsignedByte() << 16) | (in.readUnsignedByte() << 8) | (in.readUnsignedByte())); } else { // value is stored in 8 bytes. only use low 7 bits from 1st byte. return ((((long) (int_value & 0x7f)) << 56) | (((long) in.readUnsignedByte()) << 48) | (((long) in.readUnsignedByte()) << 40) | (((long) in.readUnsignedByte()) << 32) | (((long) in.readUnsignedByte()) << 24) | (((long) in.readUnsignedByte()) << 16) | (((long) in.readUnsignedByte()) << 8) | (((long) in.readUnsignedByte()))); } }
From source file:CompressedNumber.java
/** * Read an integer previously written by writeInt(). * /* ww w .java 2 s. co m*/ * @exception IOException * an exception was thrown by a method on in. */ public static final int readInt(DataInput in) throws IOException { int value = in.readUnsignedByte(); if ((value & ~0x3f) == 0) { // length is stored in this byte, we also know that the 0x80 bit // was not set, so no need to mask off the sign extension from // the byte to int conversion. // account for 1 byte stored length of field + 1 for all returns return (value); } else if ((value & 0x80) == 0) { // length is stored in 2 bytes. only use low 6 bits from 1st byte. // top 8 bits of 2 byte length is stored in this byte, we also // know that the 0x80 bit was not set, so no need to mask off the // sign extension from the 1st byte to int conversion. Need to // mask the byte in data[offset + 1] to account for possible sign // extension. return (((value & 0x3f) << 8) | in.readUnsignedByte()); } else { // top 8 bits of 4 byte length is stored in this byte, we also // know that the 0x80 bit was set, so need to mask off the // sign extension from the 1st byte to int conversion. Need to // mask the bytes from the next 3 bytes data[offset + 1,2,3] to // account for possible sign extension. // return (((value & 0x7f) << 24) | (in.readUnsignedByte() << 16) | (in.readUnsignedByte() << 8) | (in.readUnsignedByte())); } }
From source file:com.ibm.jaql.util.BaseUtil.java
/** * @param in//from w w w. j av a2 s . com * @return * @throws IOException */ public static long readVSLong(DataInput in) throws IOException { int flip; int b = in.readUnsignedByte(); if (b >= 0x08) { if (b <= 0xf7) { return b - 0x80; } // v >= 120 flip = 0; } else // v <= -121 { flip = 0xff; } b = (b ^ flip) - 0xf7; long v = 0; do { v = (v << 8) | (in.readUnsignedByte() ^ flip); b--; } while (b > 0); v += 120; v ^= (byte) flip; // 0 or -1 as a long -> one's complement for negatives return v; }
From source file:eu.stratosphere.types.StringValue.java
public static final void copyString(DataInput in, DataOutput out) throws IOException { int len = in.readUnsignedByte(); out.writeByte(len);//from w w w. j a va 2s .com if (len >= HIGH_BIT) { int shift = 7; int curr; len = len & 0x7f; while ((curr = in.readUnsignedByte()) >= HIGH_BIT) { out.writeByte(curr); len |= (curr & 0x7f) << shift; shift += 7; } out.writeByte(curr); len |= curr << shift; } // note that the length is one larger than the actual length (length 0 is a null string, not a zero length string) len--; for (int i = 0; i < len; i++) { int c = in.readUnsignedByte(); out.writeByte(c); while (c >= HIGH_BIT) { c = in.readUnsignedByte(); out.writeByte(c); } } }
From source file:eu.stratosphere.types.StringValue.java
public static final String readString(DataInput in) throws IOException { // the length we read is offset by one, because a length of zero indicates a null value int len = in.readUnsignedByte(); if (len == 0) { return null; }/*www . j av a2s . com*/ if (len >= HIGH_BIT) { int shift = 7; int curr; len = len & 0x7f; while ((curr = in.readUnsignedByte()) >= HIGH_BIT) { len |= (curr & 0x7f) << shift; shift += 7; } len |= curr << shift; } // subtract one for the null length len -= 1; final char[] data = new char[len]; for (int i = 0; i < len; i++) { int c = in.readUnsignedByte(); if (c < HIGH_BIT) { data[i] = (char) c; } else { int shift = 7; int curr; c = c & 0x7f; while ((curr = in.readUnsignedByte()) >= HIGH_BIT) { c |= (curr & 0x7f) << shift; shift += 7; } c |= curr << shift; data[i] = (char) c; } } return new String(data, 0, len); }
From source file:bobs.is.compress.sevenzip.SevenZFile.java
private static long readUint64(final DataInput in) throws IOException { // long rather than int as it might get shifted beyond the range of an int final long firstByte = in.readUnsignedByte(); int mask = 0x80; long value = 0; for (int i = 0; i < 8; i++) { if ((firstByte & mask) == 0) { return value | ((firstByte & (mask - 1)) << (8 * i)); }// w w w . j a v a2 s . co m final long nextByte = in.readUnsignedByte(); value |= nextByte << (8 * i); mask >>>= 1; } return value; }
From source file:eu.stratosphere.types.StringValue.java
@Override public void read(final DataInput in) throws IOException { int len = in.readUnsignedByte(); if (len >= HIGH_BIT) { int shift = 7; int curr; len = len & 0x7f;/* w w w.j a v a2 s . c o m*/ while ((curr = in.readUnsignedByte()) >= HIGH_BIT) { len |= (curr & 0x7f) << shift; shift += 7; } len |= curr << shift; } this.len = len; this.hashCode = 0; ensureSize(len); final char[] data = this.value; for (int i = 0; i < len; i++) { int c = in.readUnsignedByte(); if (c < HIGH_BIT) { data[i] = (char) c; } else { int shift = 7; int curr; c = c & 0x7f; while ((curr = in.readUnsignedByte()) >= HIGH_BIT) { c |= (curr & 0x7f) << shift; shift += 7; } c |= curr << shift; data[i] = (char) c; } } }
From source file:bobs.is.compress.sevenzip.SevenZFile.java
private BitSet readAllOrBits(final DataInput header, final int size) throws IOException { final int areAllDefined = header.readUnsignedByte(); final BitSet bits; if (areAllDefined != 0) { bits = new BitSet(size); for (int i = 0; i < size; i++) { bits.set(i, true);//w w w . j a v a 2s . c o m } } else { bits = readBits(header, size); } return bits; }