List of usage examples for java.io DataInput readByte
byte readByte() throws IOException;
From source file:org.godhuli.rhipe.RHBytesWritable.java
public static int readVInt(final DataInput stream) throws IOException { final byte firstByte = stream.readByte(); final int len = decodeVIntSize(firstByte); if (len == 1) { return firstByte; }/*from w ww.j a v a 2s. c o m*/ long i = 0; for (int idx = 0; idx < len - 1; idx++) { final byte b = stream.readByte(); i = i << 8; i = i | (b & 0xFF); } return ((int) ((isNegativeVInt(firstByte) ? (i ^ -1L) : i))); }
From source file:org.kalypso.shape.dbf.DBFField.java
public static IDBFField read(final DataInput input, final Charset charset) throws IOException, DBaseException { final byte[] columnNameBytes = new byte[MAX_COLUMN_NAME_LENGTH]; input.readFully(columnNameBytes);// w w w .j a v a 2 s . c o m final int columNameLength = findColumnNameLength(columnNameBytes); final String columnName = new String(columnNameBytes, 0, columNameLength, charset); final char columnType = (char) input.readByte(); input.skipBytes(4); // get field length and precision final short fieldLength = DataUtils.fixByte(input.readByte()); final short decimalCount = DataUtils.fixByte(input.readByte()); input.skipBytes(14); final FieldType fieldType = FieldType.valueOf("" + columnType); return new DBFField(columnName, fieldType, fieldLength, decimalCount); }
From source file:org.mitre.la.mapred.io.DenseVectorWritable.java
/** * Deserialize the fields of this object from <code>in</code>. * * @param in <code>DataInput</code> to deseriablize this object from. * @throws IOException/*from w w w .j a v a 2 s .c o m*/ */ @Override public void readFields(DataInput in) throws IOException { in.readByte(); String label = in.readUTF(); int length = in.readInt(); double[] v = new double[length]; for (int i = 0; i < length; i++) { v[i] = in.readDouble(); } this.dv = new DenseVector(label, v); }
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 www .j a v a 2 s . c om*/ //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; }
From source file:uk.ac.cam.eng.extraction.hadoop.datatypes.ProvenanceCountMap.java
@Override public void readFields(DataInput in) throws IOException { instance.clear();/*from w w w .j av a 2 s. c o m*/ byte length = in.readByte(); for (int i = 0; i < length; ++i) { byte key = in.readByte(); int value = in.readInt(); instance.put(getCached(key), getCached(value)); } }
From source file:w2v.WordToVec.java
private String readWord(DataInput dataInput) throws IOException { StringBuilder sb = new StringBuilder(); while (true) { byte ch;// w w w . java2s . c o m if (ungetc != null) { ch = ungetc; ungetc = null; } else { try { ch = dataInput.readByte(); } catch (EOFException eofe) { break; } } if (ch == '\r') { continue; } if ((ch == ' ') || (ch == '\t') || (ch == '\n')) { if (sb.length() > 0) { if (ch == '\n') { ungetc = ch; } break; } if (ch == '\n') { return "</s>"; } else { continue; } } sb.append((char) ch); // Truncate too long words if (sb.length() >= MAX_STRING - 1) { sb.deleteCharAt(sb.length() - 1); } } String word = sb.length() == 0 ? null : sb.toString(); return word; }