List of usage examples for java.io DataInput readFully
void readFully(byte b[]) throws IOException;
From source file:org.apache.nutch.protocol.Content.java
public final void readFields(DataInput in) throws IOException { metadata.clear();// ww w. ja va2s. c om int sizeOrVersion = in.readInt(); if (sizeOrVersion < 0) { // version version = sizeOrVersion; switch (version) { case VERSION: url = Text.readString(in); base = Text.readString(in); content = new byte[in.readInt()]; in.readFully(content); contentType = Text.readString(in); metadata.readFields(in); break; default: throw new VersionMismatchException((byte) VERSION, (byte) version); } } else { // size byte[] compressed = new byte[sizeOrVersion]; in.readFully(compressed, 0, compressed.length); ByteArrayInputStream deflated = new ByteArrayInputStream(compressed); DataInput inflater = new DataInputStream(new InflaterInputStream(deflated)); readFieldsCompressed(inflater); } }
From source file:org.apache.pig.data.BinInterSedes.java
private static Object readBytes(DataInput in, int size) throws IOException { byte[] ba = new byte[size]; in.readFully(ba); return new DataByteArray(ba); }
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); return new String(ba, DataReaderWriter.UTF8); }
From source file:org.apache.pig.data.DataReaderWriter.java
public static String bytesToBigCharArray(DataInput in) throws IOException { int size = in.readInt(); byte[] ba = new byte[size]; in.readFully(ba); return new String(ba, DataReaderWriter.UTF8); }
From source file:org.apache.pig.data.DataReaderWriter.java
public static Object readDatum(DataInput in, byte type) throws IOException, ExecException { switch (type) { case DataType.TUPLE: return bytesToTuple(in); case DataType.BAG: return bytesToBag(in); case DataType.MAP: return bytesToMap(in); case DataType.INTERNALMAP: return bytesToInternalMap(in); case DataType.INTEGER: return Integer.valueOf(in.readInt()); case DataType.LONG: return Long.valueOf(in.readLong()); case DataType.FLOAT: return Float.valueOf(in.readFloat()); case DataType.DOUBLE: return Double.valueOf(in.readDouble()); case DataType.BOOLEAN: return Boolean.valueOf(in.readBoolean()); case DataType.BYTE: return Byte.valueOf(in.readByte()); case DataType.BYTEARRAY: { int size = in.readInt(); byte[] ba = new byte[size]; in.readFully(ba); return new DataByteArray(ba); }/*from w w w . j a va2s .c o m*/ case DataType.BIGCHARARRAY: return bytesToBigCharArray(in); case DataType.CHARARRAY: return bytesToCharArray(in); case DataType.GENERIC_WRITABLECOMPARABLE: return bytesToWritable(in); case DataType.NULL: return null; default: throw new RuntimeException("Unexpected data type " + type + " found in stream."); } }
From source file:org.apache.pig.data.Tuple.java
public void readFields(DataInput in) throws IOException { byte[] b = new byte[1]; in.readFully(b); if (b[0] != TUPLE) throw new IOException("Unexpected data while reading tuple from binary file"); Tuple t = read(in);/*from w w w . j a va2 s . com*/ fields = t.fields; }
From source file:org.apache.pig.data.Tuple.java
public static Datum readDatum(DataInput in) throws IOException { byte[] b = new byte[1]; in.readFully(b); switch (b[0]) { case TUPLE:// w w w . j a va 2s .c o m return Tuple.read(in); case BAG: return DataBag.read(in); case MAP: return DataMap.read(in); case ATOM: return DataAtom.read(in); default: throw new IOException("Invalid data while reading Datum from binary file"); } }
From source file:org.apache.rya.accumulo.mr.RyaStatementWritable.java
/** * Read part of a statement from an input stream. * @param dataInput Stream for reading serialized statements. * @return The next individual field, as a byte array. * @throws IOException if reading from the stream fails. *//*from w w w .ja v a 2s. c om*/ protected byte[] read(DataInput dataInput) throws IOException { if (dataInput.readBoolean()) { int len = dataInput.readInt(); byte[] bytes = new byte[len]; dataInput.readFully(bytes); return bytes; } else { return null; } }
From source file:org.apache.rya.reasoning.mr.SchemaWritable.java
@Override public void readFields(DataInput in) throws IOException { int size = in.readInt(); if (size < 1) throw new Error("De-serializtion failed, count is less than one."); byte[] bytes = new byte[size]; in.readFully(bytes); // ObjectInputStream stream = new ObjectInputStream(new ByteArrayInputStream(bytes)); try (final ByteArrayInputStream bais = new ByteArrayInputStream(bytes); // final ValidatingObjectInputStream vois = new ValidatingObjectInputStream(bais) // this is how you find classes that you missed in the vois.accept() list, below. // { @Override protected void invalidClassNameFound(String className) throws java.io.InvalidClassException { // System.out.println("vois.accept(" + className + ".class, ");};}; ) {//from w w w . j a v a 2s.c om // this is a (hopefully) complete list of classes involved in a Schema to be serialized. // if a useful class is missing, throws an InvalidClassException. vois.accept(java.util.ArrayList.class, // org.apache.rya.reasoning.OwlProperty.class, // java.util.HashSet.class, // org.apache.rya.reasoning.OwlClass.class, // org.eclipse.rdf4j.model.impl.SimpleIRI.class, // org.eclipse.rdf4j.model.impl.SimpleBNode.class); try { Iterable<?> propList = (Iterable<?>) vois.readObject(); Iterable<?> classList = (Iterable<?>) vois.readObject(); for (Object p : propList) { OwlProperty prop = (OwlProperty) p; properties.put(prop.getURI(), prop); } for (Object c : classList) { OwlClass owlClass = (OwlClass) c; classes.put(owlClass.getURI(), owlClass); } } catch (ClassNotFoundException e) { throw new Error("While reading a schema object."); } } }
From source file:org.archive.io.hdfs.HDFSWriterDocument.java
/** * Reads the fields of this object from <code>in</code>. * * @param in input object to de-serialize from *//*www.ja v a 2s .c om*/ public void readFields(DataInput in) throws IOException { int length = in.readInt(); byte[] docBytes = new byte[length]; in.readFully(docBytes); load(docBytes, 0, length); }