List of usage examples for java.io DataInput readBoolean
boolean readBoolean() 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// ww w .jav a 2 s. c o m * @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.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 w w w.j a va 2 s.c om 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.oozie.coord.input.dependency.AbstractCoordInputDependency.java
@Override public void readFields(DataInput in) throws IOException { WritableUtils.readBytesAsString(in); this.isDependencyMet = in.readBoolean(); dependencyMap = WritableUtils.readMapWithList(in, CoordInputInstance.class); generateDependencies();//from ww w . j av a2 s . co m }
From source file:org.apache.oozie.coord.input.dependency.CoordUnResolvedInputDependency.java
@Override public void readFields(DataInput in) throws IOException { isResolved = in.readBoolean(); dependency = WritableUtils.readStringList(in); resolvedList = WritableUtils.readStringList(in); }
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);//www. j av a 2s. com return new DataByteArray(ba); } 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.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 ww. j av a 2 s . c o m*/ 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.accumulo.mr.RyaStatementWritable.java
/** * Loads a RyaStatementWritable by reading data from an input stream. * Creates a new RyaStatement and assigns it to this RyaStatementWritable. * @param dataInput An stream containing serialized statement data. *//*from www.j a v a2 s . co m*/ @Override public void readFields(DataInput dataInput) throws IOException { byte[] row = read(dataInput); byte[] columnFamily = read(dataInput); byte[] columnQualifier = read(dataInput); byte[] columnVisibility = read(dataInput); byte[] value = read(dataInput); boolean b = dataInput.readBoolean(); Long timestamp = null; if (b) { timestamp = dataInput.readLong(); } try { ryaStatement = ryaContext.deserializeTriple(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, new TripleRow(row, columnFamily, columnQualifier)); ryaStatement.setColumnVisibility(columnVisibility); ryaStatement.setValue(value); ryaStatement.setTimestamp(timestamp); } catch (TripleRowResolverException e) { throw new IOException(e); } }
From source file:org.apache.sysml.runtime.compress.CompressedMatrixBlock.java
@Override public void readFields(DataInput in) throws IOException { boolean compressed = in.readBoolean(); //deserialize uncompressed block if (!compressed) { super.readFields(in); return;/*from w w w. j a va2 s . c om*/ } //deserialize compressed block rlen = in.readInt(); clen = in.readInt(); nonZeros = in.readLong(); int ncolGroups = in.readInt(); _colGroups = new ArrayList<ColGroup>(ncolGroups); for (int i = 0; i < ncolGroups; i++) { CompressionType ctype = CompressionType.values()[in.readByte()]; ColGroup grp = null; //create instance of column group switch (ctype) { case UNCOMPRESSED: grp = new ColGroupUncompressed(); break; case OLE_BITMAP: grp = new ColGroupOLE(); break; case RLE_BITMAP: grp = new ColGroupRLE(); break; } //deserialize and add column group grp.readFields(in); _colGroups.add(grp); } }
From source file:org.apache.sysml.runtime.matrix.data.FrameBlock.java
@Override public void readFields(DataInput in) throws IOException { //read head (rows, cols) _numRows = in.readInt();// w w w. j a v a2 s .co m int numCols = in.readInt(); boolean isDefaultMeta = in.readBoolean(); //allocate schema/meta data arrays _schema = (_schema != null && _schema.length == numCols) ? _schema : new ValueType[numCols]; _colnames = (_colnames != null && _colnames.length == numCols) ? _colnames : new String[numCols]; _colmeta = (_colmeta != null && _colmeta.length == numCols) ? _colmeta : new ColumnMetadata[numCols]; _coldata = (_coldata != null && _coldata.length == numCols) ? _coldata : new Array[numCols]; //read columns (value type, meta, data) for (int j = 0; j < numCols; j++) { ValueType vt = ValueType.values()[in.readByte()]; String name = isDefaultMeta ? createColName(j) : in.readUTF(); long ndistinct = isDefaultMeta ? 0 : in.readLong(); String mvvalue = isDefaultMeta ? null : in.readUTF(); Array arr = null; switch (vt) { case STRING: arr = new StringArray(new String[_numRows]); break; case BOOLEAN: arr = new BooleanArray(new boolean[_numRows]); break; case INT: arr = new LongArray(new long[_numRows]); break; case DOUBLE: arr = new DoubleArray(new double[_numRows]); break; default: throw new IOException("Unsupported value type: " + vt); } arr.readFields(in); _schema[j] = vt; _colnames[j] = name; _colmeta[j] = new ColumnMetadata(ndistinct, (mvvalue == null || mvvalue.isEmpty()) ? null : mvvalue); _coldata[j] = arr; } }
From source file:org.cloudata.core.common.io.CObjectWritable.java
/** Read a {@link CWritable}, {@link String}, primitive type, or an array of * the preceding. */// ww w.j a v a 2s .c o m @SuppressWarnings("unchecked") public static Object readObject(DataInput in, CObjectWritable objectWritable, CloudataConf conf, boolean arrayComponent, Class componentClass) throws IOException { String className; if (arrayComponent) { className = componentClass.getName(); } else { className = CUTF8.readString(in); //SANGCHUL // System.out.println("SANGCHUL] className:" + className); } Class<?> declaredClass = PRIMITIVE_NAMES.get(className); if (declaredClass == null) { try { declaredClass = conf.getClassByName(className); } catch (ClassNotFoundException e) { //SANGCHUL e.printStackTrace(); throw new RuntimeException("readObject can't find class[className=" + className + "]", e); } } Object instance; if (declaredClass.isPrimitive()) { // primitive types if (declaredClass == Boolean.TYPE) { // boolean instance = Boolean.valueOf(in.readBoolean()); } else if (declaredClass == Character.TYPE) { // char instance = Character.valueOf(in.readChar()); } else if (declaredClass == Byte.TYPE) { // byte instance = Byte.valueOf(in.readByte()); } else if (declaredClass == Short.TYPE) { // short instance = Short.valueOf(in.readShort()); } else if (declaredClass == Integer.TYPE) { // int instance = Integer.valueOf(in.readInt()); } else if (declaredClass == Long.TYPE) { // long instance = Long.valueOf(in.readLong()); } else if (declaredClass == Float.TYPE) { // float instance = Float.valueOf(in.readFloat()); } else if (declaredClass == Double.TYPE) { // double instance = Double.valueOf(in.readDouble()); } else if (declaredClass == Void.TYPE) { // void instance = null; } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isArray()) { // array //System.out.println("SANGCHUL] is array"); int length = in.readInt(); //System.out.println("SANGCHUL] array length : " + length); //System.out.println("Read:in.readInt():" + length); if (declaredClass.getComponentType() == Byte.TYPE) { byte[] bytes = new byte[length]; in.readFully(bytes); instance = bytes; } else if (declaredClass.getComponentType() == ColumnValue.class) { instance = readColumnValue(in, conf, declaredClass, length); } else { Class componentType = declaredClass.getComponentType(); // SANGCHUL //System.out.println("SANGCHUL] componentType : " + componentType.getName()); instance = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Object arrayComponentInstance = readObject(in, null, conf, !componentType.isArray(), componentType); Array.set(instance, i, arrayComponentInstance); //Array.set(instance, i, readObject(in, conf)); } } } else if (declaredClass == String.class) { // String instance = CUTF8.readString(in); } else if (declaredClass.isEnum()) { // enum instance = Enum.valueOf((Class<? extends Enum>) declaredClass, CUTF8.readString(in)); } else if (declaredClass == ColumnValue.class) { //ColumnValue? ?? ?? ? ? ?. //? ? ? ? ? ? . Class instanceClass = null; try { short typeDiff = in.readShort(); if (typeDiff == TYPE_DIFF) { instanceClass = conf.getClassByName(CUTF8.readString(in)); } else { instanceClass = declaredClass; } } catch (ClassNotFoundException e) { throw new RuntimeException("readObject can't find class", e); } ColumnValue columnValue = new ColumnValue(); columnValue.readFields(in); instance = columnValue; } else { // Writable Class instanceClass = null; try { short typeDiff = in.readShort(); // SANGCHUL //System.out.println("SANGCHUL] typeDiff : " + typeDiff); //System.out.println("Read:in.readShort():" + typeDiff); if (typeDiff == TYPE_DIFF) { // SANGCHUL String classNameTemp = CUTF8.readString(in); //System.out.println("SANGCHUL] typeDiff : " + classNameTemp); instanceClass = conf.getClassByName(classNameTemp); //System.out.println("Read:UTF8.readString(in):" + instanceClass.getClass()); } else { instanceClass = declaredClass; } } catch (ClassNotFoundException e) { // SANGCHUL e.printStackTrace(); throw new RuntimeException("readObject can't find class", e); } CWritable writable = CWritableFactories.newInstance(instanceClass, conf); writable.readFields(in); //System.out.println("Read:writable.readFields(in)"); instance = writable; if (instanceClass == NullInstance.class) { // null declaredClass = ((NullInstance) instance).declaredClass; instance = null; } } if (objectWritable != null) { // store values objectWritable.declaredClass = declaredClass; objectWritable.instance = instance; } return instance; }