List of usage examples for java.io DataInput readByte
byte readByte() throws IOException;
From source file:org.apache.marmotta.kiwi.io.KiWiIO.java
/** * Read a KiWiTriple serialized with writeTriple from a DataInput source * * @param input the source//from w w w .j a va 2 s . c om * @return the de-serialized KiWiTriple * @throws IOException */ public static KiWiTriple readTriple(DataInput input) throws IOException { KiWiTriple result = new KiWiTriple(); result.setId(input.readLong()); int mode = input.readByte(); if (mode == MODE_PREFIX) { String prefix = DataIO.readString(input); long sId = input.readLong(); String sUri = prefix + DataIO.readString(input); long sTime = input.readLong(); KiWiUriResource s = new KiWiUriResource(sUri); s.setId(sId); s.setCreated(new Date(sTime)); result.setSubject(s); result.setPredicate(readURI(input)); long oId = input.readLong(); String oUri = prefix + DataIO.readString(input); long oTime = input.readLong(); KiWiUriResource o = new KiWiUriResource(oUri); o.setId(oId); o.setCreated(new Date(oTime)); result.setObject(o); } else { result.setSubject((KiWiResource) readNode(input)); result.setPredicate(readURI(input)); result.setObject(readNode(input)); } result.setContext((KiWiResource) readNode(input)); result.setCreator((KiWiResource) readNode(input)); result.setDeleted(input.readBoolean()); result.setInferred(input.readBoolean()); result.setNewTriple(input.readBoolean()); result.setCreated(new Date(input.readLong())); long deletedAt = input.readLong(); if (deletedAt > 0) { result.setDeletedAt(new Date(deletedAt)); } return result; }
From source file:org.apache.marmotta.kiwi.io.KiWiIO.java
/** * Read a potentially compressed string from the data input. * * @param in/*from ww w . ja v a2 s .c om*/ * @return * @throws IOException */ private static String readContent(DataInput in) throws IOException { int mode = in.readByte(); if (mode == MODE_COMPRESSED) { try { int strlen = in.readInt(); int buflen = in.readInt(); byte[] buffer = new byte[buflen]; in.readFully(buffer); Inflater decompressor = new Inflater(true); decompressor.setInput(buffer); byte[] data = new byte[strlen]; decompressor.inflate(data); decompressor.end(); return new String(data, "UTF-8"); } catch (DataFormatException ex) { throw new IllegalStateException("input data is not valid", ex); } } else { return DataIO.readString(in); } }
From source file:org.apache.nutch.crawl.CrawlDatum.java
public void readFields(DataInput in) throws IOException { byte version = in.readByte(); // read version if (version > CUR_VERSION) // check version throw new VersionMismatchException(CUR_VERSION, version); status = in.readByte();//from www.j ava 2 s .c o m fetchTime = in.readLong(); retries = in.readByte(); if (version > 5) { fetchInterval = in.readInt(); } else fetchInterval = Math.round(in.readFloat()); score = in.readFloat(); if (version > 2) { modifiedTime = in.readLong(); int cnt = in.readByte(); if (cnt > 0) { signature = new byte[cnt]; in.readFully(signature); } else signature = null; } if (version > 3) { boolean hasMetadata = false; if (version < 7) { org.apache.hadoop.io.MapWritable oldMetaData = new org.apache.hadoop.io.MapWritable(); if (in.readBoolean()) { hasMetadata = true; metaData = new org.apache.hadoop.io.MapWritable(); oldMetaData.readFields(in); } for (Writable key : oldMetaData.keySet()) { metaData.put(key, oldMetaData.get(key)); } } else { if (in.readBoolean()) { hasMetadata = true; metaData = new org.apache.hadoop.io.MapWritable(); metaData.readFields(in); } } if (hasMetadata == false) metaData = null; } // translate status codes if (version < 5) { if (oldToNew.containsKey(status)) status = oldToNew.get(status); else status = STATUS_DB_UNFETCHED; } }
From source file:org.apache.nutch.crawl.MapWritable.java
public void readFields(DataInput in) throws IOException { clear();//from www . j a v a 2s . co m fSize = in.readInt(); if (fSize > 0) { // read class-id map fIdCount = in.readByte(); byte id; Class clazz; for (int i = 0; i < fIdCount; i++) { try { id = in.readByte(); clazz = Class.forName(Text.readString(in)); addIdEntry(id, clazz); } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn("Unable to load internal map entry" + e.toString()); } fIdCount--; } } KeyValueEntry entry; for (int i = 0; i < fSize; i++) { try { entry = getKeyValueEntry(in.readByte(), in.readByte()); entry.fKey.readFields(in); entry.fValue.readFields(in); if (fFirst == null) { fFirst = fLast = entry; } else { fLast = fLast.fNextEntry = entry; } } catch (IOException e) { if (LOG.isWarnEnabled()) { LOG.warn("Unable to load meta data entry, ignoring.. : " + e.toString()); } fSize--; } } } }
From source file:org.apache.nutch.parse.ParseData.java
public final void readFields(DataInput in) throws IOException { version = in.readByte(); // incompatible change from UTF8 (version < 5) to Text if (version != VERSION) throw new VersionMismatchException(VERSION, version); status = ParseStatus.read(in);/*from w ww . ja v a 2 s. c o m*/ title = Text.readString(in); // read title int numOutlinks = in.readInt(); outlinks = new Outlink[numOutlinks]; for (int i = 0; i < numOutlinks; i++) { outlinks[i] = Outlink.read(in); } if (version < 3) { int propertyCount = in.readInt(); // read metadata contentMeta.clear(); for (int i = 0; i < propertyCount; i++) { contentMeta.add(Text.readString(in), Text.readString(in)); } } else { contentMeta.clear(); contentMeta.readFields(in); } if (version > 3) { parseMeta.clear(); parseMeta.readFields(in); } }
From source file:org.apache.nutch.protocol.Content.java
private final void readFieldsCompressed(DataInput in) throws IOException { byte oldVersion = in.readByte(); switch (oldVersion) { case 0:/*from w w w . j av a2 s .co m*/ case 1: url = Text.readString(in); // read url base = Text.readString(in); // read base content = new byte[in.readInt()]; // read content in.readFully(content); contentType = Text.readString(in); // read contentType // reconstruct metadata int keySize = in.readInt(); String key; for (int i = 0; i < keySize; i++) { key = Text.readString(in); int valueSize = in.readInt(); for (int j = 0; j < valueSize; j++) { metadata.add(key, Text.readString(in)); } } break; case 2: url = Text.readString(in); // read url base = Text.readString(in); // read base content = new byte[in.readInt()]; // read content in.readFully(content); contentType = Text.readString(in); // read contentType metadata.readFields(in); // read meta data break; default: throw new VersionMismatchException((byte) 2, oldVersion); } }
From source file:org.apache.nutch.searcher.Query.java
public void readFields(DataInput in) throws IOException { clauses.clear();// ww w . j a v a 2 s . co m int length = in.readByte(); for (int i = 0; i < length; i++) clauses.add(Clause.read(in, this.conf)); params.readFields(in); }
From source file:org.apache.pig.data.BinInterSedes.java
@Override public Object readDatum(DataInput in) throws IOException, ExecException { // Read the data type byte b = in.readByte(); return readDatum(in, b); }
From source file:org.apache.pig.data.BinInterSedes.java
/** * Expects binInterSedes data types (NOT DataType types!) * <p>//from w w w . ja v a2 s .c o m * * @see org.apache.pig.data.InterSedes#readDatum(java.io.DataInput, byte) */ @Override public Object readDatum(DataInput in, byte type) throws IOException, ExecException { switch (type) { case TUPLE_0: case TUPLE_1: case TUPLE_2: case TUPLE_3: case TUPLE_4: case TUPLE_5: case TUPLE_6: case TUPLE_7: case TUPLE_8: case TUPLE_9: case TUPLE: case TINYTUPLE: case SMALLTUPLE: return SedesHelper.readGenericTuple(in, type); case BAG: case TINYBAG: case SMALLBAG: return readBag(in, type); case MAP: case TINYMAP: case SMALLMAP: return readMap(in, type); case INTERNALMAP: return readInternalMap(in); case INTEGER_0: return Integer.valueOf(0); case INTEGER_1: return Integer.valueOf(1); case INTEGER_INBYTE: return Integer.valueOf(in.readByte()); case INTEGER_INSHORT: return Integer.valueOf(in.readShort()); case INTEGER: return Integer.valueOf(in.readInt()); case LONG_0: return Long.valueOf(0); case LONG_1: return Long.valueOf(1); case LONG_INBYTE: return Long.valueOf(in.readByte()); case LONG_INSHORT: return Long.valueOf(in.readShort()); case LONG_ININT: return Long.valueOf(in.readInt()); case LONG: return Long.valueOf(in.readLong()); case DATETIME: return new DateTime(in.readLong(), DateTimeZone.forOffsetMillis(in.readShort() * ONE_MINUTE)); case FLOAT: return Float.valueOf(in.readFloat()); case DOUBLE: return Double.valueOf(in.readDouble()); case BIGINTEGER: return readBigInteger(in); case BIGDECIMAL: return readBigDecimal(in); case BOOLEAN_TRUE: return Boolean.valueOf(true); case BOOLEAN_FALSE: return Boolean.valueOf(false); case BYTE: return Byte.valueOf(in.readByte()); case TINYBYTEARRAY: case SMALLBYTEARRAY: case BYTEARRAY: return new DataByteArray(SedesHelper.readBytes(in, type)); case CHARARRAY: case SMALLCHARARRAY: return SedesHelper.readChararray(in, type); case GENERIC_WRITABLECOMPARABLE: return readWritable(in); case SCHEMA_TUPLE_BYTE_INDEX: case SCHEMA_TUPLE_SHORT_INDEX: case SCHEMA_TUPLE: return readSchemaTuple(in, type); case NULL: return null; default: throw new RuntimeException("Unexpected data type " + type + " found in stream."); } }
From source file:org.apache.pig.data.BinInterSedes.java
@Override public void addColsToTuple(DataInput in, Tuple t) throws IOException { byte type = in.readByte(); int sz = getTupleSize(in, type); for (int i = 0; i < sz; i++) { t.append(readDatum(in));/* w ww .j a va2s . c o m*/ } }