List of usage examples for java.io DataInput readUnsignedShort
int readUnsignedShort() throws IOException;
From source file:org.apache.pig.data.BinInterSedes.java
private Tuple readSchemaTuple(DataInput in, byte type) throws IOException { int id;/* w ww .j a v a 2 s . com*/ switch (type) { case (SCHEMA_TUPLE_BYTE_INDEX): id = in.readUnsignedByte(); break; case (SCHEMA_TUPLE_SHORT_INDEX): id = in.readUnsignedShort(); break; case (SCHEMA_TUPLE): id = in.readInt(); break; default: throw new RuntimeException("Invalid type given to readSchemaTuple: " + type); } Tuple st = SchemaTupleFactory.getInstance(id).newTuple(); st.readFields(in); return st; }
From source file:org.apache.pig.data.BinInterSedes.java
public int getTupleSize(DataInput in, byte type) throws IOException { int sz;//ww w. j a v a 2 s .c o m switch (type) { case TUPLE_0: return 0; case TUPLE_1: return 1; case TUPLE_2: return 2; case TUPLE_3: return 3; case TUPLE_4: return 4; case TUPLE_5: return 5; case TUPLE_6: return 6; case TUPLE_7: return 7; case TUPLE_8: return 8; case TUPLE_9: return 9; case TINYTUPLE: sz = in.readUnsignedByte(); break; case SMALLTUPLE: sz = in.readUnsignedShort(); break; case TUPLE: sz = in.readInt(); break; default: { int errCode = 2112; String msg = "Unexpected datatype " + type + " while reading tuple" + "from binary file."; throw new ExecException(msg, errCode, PigException.BUG); } } // if sz == 0, we construct an "empty" tuple - presumably the writer wrote an empty tuple! if (sz < 0) { throw new IOException("Invalid size " + sz + " for a tuple"); } return sz; }
From source file:org.apache.pig.data.BinInterSedes.java
private DataBag readBag(DataInput in, byte type) throws IOException { DataBag bag = mBagFactory.newDefaultBag(); long size;// w w w .jav a 2 s. c o m // determine size of bag switch (type) { case TINYBAG: size = in.readUnsignedByte(); break; case SMALLBAG: size = in.readUnsignedShort(); break; case BAG: size = in.readLong(); break; default: int errCode = 2219; String msg = "Unexpected data while reading bag " + "from binary file."; throw new ExecException(msg, errCode, PigException.BUG); } for (long i = 0; i < size; i++) { try { Object o = readDatum(in); bag.add((Tuple) o); } catch (ExecException ee) { throw ee; } } return bag; }
From source file:org.apache.pig.data.BinInterSedes.java
private Map<String, Object> readMap(DataInput in, byte type) throws IOException { int size;/*w w w .j av a2s . c o m*/ switch (type) { case TINYMAP: size = in.readUnsignedByte(); break; case SMALLMAP: size = in.readUnsignedShort(); break; case MAP: size = in.readInt(); break; default: { int errCode = 2220; String msg = "Unexpected data while reading map" + "from binary file."; throw new ExecException(msg, errCode, PigException.BUG); } } Map<String, Object> m = new HashMap<String, Object>(size); for (int i = 0; i < size; i++) { String key = (String) readDatum(in); m.put(key, readDatum(in)); } return m; }
From source file:org.apache.pig.data.DataReaderWriter.java
public static String bytesToCharArray(DataInput in) throws IOException { int size = in.readUnsignedShort(); byte[] ba = new byte[size]; in.readFully(ba);/*w w w. j a va2 s .co m*/ return new String(ba, DataReaderWriter.UTF8); }
From source file:org.cloudata.core.common.io.CUTF8.java
/** Skips over one UTF8 in the input. */ public static void skip(DataInput in) throws IOException { int length = in.readUnsignedShort(); CWritableUtils.skipFully(in, length); }
From source file:org.netbeans.nbbuild.VerifyClassLinkageForIISI.java
public static Set<String> dependencies(byte[] data) throws IOException { Set<String> result = new TreeSet<String>(); DataInput input = new DataInputStream(new ByteArrayInputStream(data)); skip(input, 8); // magic, minor_version, major_version int size = input.readUnsignedShort() - 1; // constantPoolCount String[] utf8Strings = new String[size]; boolean[] isClassName = new boolean[size]; boolean[] isDescriptor = new boolean[size]; for (int i = 0; i < size; i++) { byte tag = input.readByte(); switch (tag) { case 1: // CONSTANT_Utf8 utf8Strings[i] = input.readUTF(); break; case 7: // CONSTANT_Class int index = input.readUnsignedShort() - 1; if (index >= size) { throw new IOException("@" + i + ": CONSTANT_Class_info.name_index " + index + " too big for size of pool " + size); }/*from w ww . j av a2s. c o m*/ //log("Class reference at " + index, Project.MSG_DEBUG); isClassName[index] = true; break; case 3: // CONSTANT_Integer case 4: // CONSTANT_Float case 9: // CONSTANT_Fieldref case 10: // CONSTANT_Methodref case 11: // CONSTANT_InterfaceMethodref skip(input, 4); break; case 12: // CONSTANT_NameAndType skip(input, 2); index = input.readUnsignedShort() - 1; if (index >= size || index < 0) { throw new IOException("@" + i + ": CONSTANT_NameAndType_info.descriptor_index " + index + " too big for size of pool " + size); } isDescriptor[index] = true; break; case 8: // CONSTANT_String skip(input, 2); break; case 5: // CONSTANT_Long case 6: // CONSTANT_Double skip(input, 8); i++; // weirdness in spec break; default: throw new IOException("Unrecognized constant pool tag " + tag + " at index " + i + "; running UTF-8 strings: " + Arrays.asList(utf8Strings)); } } //task.log("UTF-8 strings: " + Arrays.asList(utf8Strings), Project.MSG_DEBUG); for (int i = 0; i < size; i++) { String s = utf8Strings[i]; final Set<String> classNameSet = extractClassName(s); if (s != null) { if (CollectionUtils.isNotEmpty(classNameSet)) { result.addAll(classNameSet); } } } return result; }