List of usage examples for java.io DataInput readBoolean
boolean readBoolean() throws IOException;
From source file:com.chinamobile.bcbsp.util.StaffStatus.java
/** * deserialize//w w w.j a v a 2 s. c o m * * @param in Reads some bytes from an input. */ @Override public void readFields(DataInput in) throws IOException { this.jobId.readFields(in); this.staffId.readFields(in); this.progress = in.readInt(); this.runState = WritableUtils.readEnum(in, State.class); this.stateString = Text.readString(in); this.phase = WritableUtils.readEnum(in, Phase.class); this.startTime = in.readLong(); this.finishTime = in.readLong(); this.superstepCount = in.readLong(); this.faultFlag = in.readInt(); if (this.faultFlag == 1) { this.fault.readFields(in); } this.recovery = in.readBoolean(); this.currentSSTime = in.readLong(); this.workerManager = Text.readString(in); }
From source file:com.fiorano.openesb.application.aps.OutPortInst.java
/** * This is called to read this object <code>OutPortInst</code> from the * specified object of input stream.//from www .j a va 2 s.c om * * @param is DataInput object * @param versionNo Description of the Parameter * @exception IOException if an error occurs while reading bytes or while * converting them into specified Java primitive type. * @since Tifosi2.0 */ public void fromStream(DataInput is, int versionNo) throws IOException { super.fromStream(is, versionNo); m_strPortName = readUTF(is); m_strDscription = readUTF(is); m_strXSD = readUTF(is); m_strContextXSL = readUTF(is); m_strContextInfo = readUTF(is); m_transformerType = readUTF(is); m_strJavaClass = readUTF(is); m_bIsSyncRequestType = is.readBoolean(); m_bisDisabled = is.readBoolean(); int size = is.readInt(); for (int i = 0; i < size; ++i) { Param param = new Param(); param.fromStream(is, versionNo); m_params.addElement(param); } }
From source file:com.mongodb.hadoop.io.MongoUpdateWritable.java
/** * {@inheritDoc}/* w w w .ja v a2 s .co m*/ * * @see Writable#readFields(DataInput) */ public void readFields(DataInput in) throws IOException { BSONDecoder dec = new BasicBSONDecoder(); BSONCallback cb = new BasicBSONCallback(); // Read the BSON length from the start of the record byte[] l = new byte[4]; try { in.readFully(l); int dataLen = Bits.readInt(l); byte[] data = new byte[dataLen + 4]; System.arraycopy(l, 0, data, 0, 4); in.readFully(data, 4, dataLen - 4); dec.decode(data, cb); this.query = (BasicBSONObject) cb.get(); in.readFully(l); dataLen = Bits.readInt(l); data = new byte[dataLen + 4]; System.arraycopy(l, 0, data, 0, 4); in.readFully(data, 4, dataLen - 4); dec.decode(data, cb); this.modifiers = (BasicBSONObject) cb.get(); this.upsert = in.readBoolean(); this.multiUpdate = in.readBoolean(); } catch (Exception e) { /* If we can't read another length it's not an error, just return quietly. */ // TODO - Figure out how to gracefully mark this as an empty log.info("No Length Header available." + e); this.query = new BasicDBObject(); this.modifiers = new BasicDBObject(); } }
From source file:com.zjy.mongo.io.MongoUpdateWritable.java
/** * {@inheritDoc}/* w ww . j a v a 2 s.c om*/ * * @see Writable#readFields(DataInput) */ public void readFields(final DataInput in) throws IOException { BSONDecoder dec = new BasicBSONDecoder(); BSONCallback cb = new BasicBSONCallback(); // Read the BSON length from the start of the record byte[] l = new byte[4]; try { in.readFully(l); int dataLen = Bits.readInt(l); byte[] data = new byte[dataLen + 4]; System.arraycopy(l, 0, data, 0, 4); in.readFully(data, 4, dataLen - 4); dec.decode(data, cb); query = (BasicBSONObject) cb.get(); in.readFully(l); dataLen = Bits.readInt(l); data = new byte[dataLen + 4]; System.arraycopy(l, 0, data, 0, 4); in.readFully(data, 4, dataLen - 4); dec.decode(data, cb); modifiers = (BasicBSONObject) cb.get(); upsert = in.readBoolean(); multiUpdate = in.readBoolean(); } catch (Exception e) { /* If we can't read another length it's not an error, just return quietly. */ // TODO - Figure out how to gracefully mark this as an empty LOG.info("No Length Header available." + e); query = new BasicDBObject(); modifiers = new BasicDBObject(); } }
From source file:eu.stratosphere.nephele.jobgraph.AbstractJobVertex.java
@SuppressWarnings("unchecked") @Override/*from w w w . j av a 2s .c o m*/ public void read(final DataInput in) throws IOException { if (jobGraph == null) { throw new IOException("jobGraph is null, cannot deserialize"); } // Read number of subtasks this.numberOfSubtasks = in.readInt(); // Number of execution retries this.numberOfExecutionRetries = in.readInt(); // Read vertex to share instances with if (in.readBoolean()) { final JobVertexID id = new JobVertexID(); id.read(in); final AbstractJobVertex vertexToShareInstancesWith = this.jobGraph.findVertexByID(id); if (vertexToShareInstancesWith == null) { throw new IOException("Cannot find vertex with id " + id + " share instances with"); } this.vertexToShareInstancesWith = vertexToShareInstancesWith; } // Find the class loader for the job final ClassLoader cl = LibraryCacheManager.getClassLoader(this.getJobGraph().getJobID()); if (cl == null) { throw new IOException("Cannot find class loader for vertex " + getID()); } // Re-instantiate the configuration object with the correct class loader and read the configuration this.configuration = new Configuration(cl); this.configuration.read(in); // Read number of forward edges final int numForwardEdges = in.readInt(); // Now reconnect to other vertices via the reconstruction map final JobVertexID tmpID = new JobVertexID(); for (int i = 0; i < numForwardEdges; i++) { if (in.readBoolean()) { tmpID.read(in); final AbstractJobVertex jv = jobGraph.findVertexByID(tmpID); if (jv == null) { throw new IOException("Cannot find vertex with id " + tmpID); } final ChannelType channelType = EnumUtils.readEnum(in, ChannelType.class); final DistributionPattern distributionPattern = EnumUtils.readEnum(in, DistributionPattern.class); final int indexOfInputGate = in.readInt(); try { this.connectTo(jv, channelType, i, indexOfInputGate, distributionPattern); } catch (JobGraphDefinitionException e) { throw new IOException(StringUtils.stringifyException(e)); } } else { this.forwardEdges.add(null); } } // Read the invokable class final boolean isNotNull = in.readBoolean(); if (!isNotNull) { return; } // Read the name of the expected class final String className = StringRecord.readString(in); try { this.invokableClass = (Class<? extends AbstractInvokable>) Class.forName(className, true, cl); } catch (ClassNotFoundException cnfe) { throw new IOException("Class " + className + " not found in one of the supplied jar files: " + StringUtils.stringifyException(cnfe)); } }
From source file:ml.shifu.shifu.core.dtrain.dataset.PersistBasicFloatNetwork.java
public BasicFloatNetwork readNetwork(final DataInput in) throws IOException { final BasicFloatNetwork result = new BasicFloatNetwork(); final FlatNetwork flat = new FlatNetwork(); // read properties Map<String, String> properties = new HashMap<String, String>(); int size = in.readInt(); for (int i = 0; i < size; i++) { properties.put(ml.shifu.shifu.core.dtrain.StringUtils.readString(in), ml.shifu.shifu.core.dtrain.StringUtils.readString(in)); }//from w w w. j a v a2 s.c o m result.getProperties().putAll(properties); // read fields flat.setBeginTraining(in.readInt()); flat.setConnectionLimit(in.readDouble()); flat.setContextTargetOffset(readIntArray(in)); flat.setContextTargetSize(readIntArray(in)); flat.setEndTraining(in.readInt()); flat.setHasContext(in.readBoolean()); flat.setInputCount(in.readInt()); flat.setLayerCounts(readIntArray(in)); flat.setLayerFeedCounts(readIntArray(in)); flat.setLayerContextCount(readIntArray(in)); flat.setLayerIndex(readIntArray(in)); flat.setLayerOutput(readDoubleArray(in)); flat.setOutputCount(in.readInt()); flat.setLayerSums(new double[flat.getLayerOutput().length]); flat.setWeightIndex(readIntArray(in)); flat.setWeights(readDoubleArray(in)); flat.setBiasActivation(readDoubleArray(in)); // read activations flat.setActivationFunctions(new ActivationFunction[flat.getLayerCounts().length]); int acSize = in.readInt(); for (int i = 0; i < acSize; i++) { String name = ml.shifu.shifu.core.dtrain.StringUtils.readString(in); if (name.equals("ActivationReLU")) { name = ActivationReLU.class.getName(); } else if (name.equals("ActivationLeakyReLU")) { name = ActivationLeakyReLU.class.getName(); } else if (name.equals("ActivationSwish")) { name = ActivationSwish.class.getName(); } else if (name.equals("ActivationPTANH")) { name = ActivationPTANH.class.getName(); } else { name = "org.encog.engine.network.activation." + name; } ActivationFunction af = null; try { final Class<?> clazz = Class.forName(name); af = (ActivationFunction) clazz.newInstance(); } catch (final ClassNotFoundException e) { throw new PersistError(e); } catch (final InstantiationException e) { throw new PersistError(e); } catch (final IllegalAccessException e) { throw new PersistError(e); } double[] params = readDoubleArray(in); for (int j = 0; j < params.length; j++) { af.setParam(j, params[j]); } flat.getActivationFunctions()[i] = af; } // read subset int subsetSize = in.readInt(); Set<Integer> featureList = new HashSet<Integer>(); for (int i = 0; i < subsetSize; i++) { featureList.add(in.readInt()); } result.setFeatureSet(featureList); result.getStructure().setFlat(flat); return result; }
From source file:com.mapr.hbase.support.objects.MHRegionInfo.java
@Override public void readFields(DataInput in) throws IOException { // Read the single version byte. We don't ask the super class do it // because freaks out if its not the current classes' version. This method // can deserialize version 0 and version 1 of HRI. byte version = in.readByte(); if (version == 0) { // This is the old HRI that carried an HTD. Migrate it. The below // was copied from the old 0.90 HRI readFields. this.endKey = Bytes.readByteArray(in); this.offLine = in.readBoolean(); this.regionId = in.readLong(); this.regionName = Bytes.readByteArray(in); this.regionNameStr = Bytes.toStringBinary(this.regionName); this.split = in.readBoolean(); this.startKey = Bytes.readByteArray(in); try {/*from w ww. j a va 2 s.co m*/ tableDesc = new HTableDescriptor(); tableDesc.readFields(in); this.tableName = tableDesc.getName(); } catch (EOFException eofe) { throw new IOException("HTD not found in input buffer", eofe); } this.hashCode = in.readInt(); } else if (getVersion() == version) { this.endKey = Bytes.readByteArray(in); this.offLine = in.readBoolean(); this.regionId = in.readLong(); this.regionName = Bytes.readByteArray(in); this.regionNameStr = Bytes.toStringBinary(this.regionName); this.split = in.readBoolean(); this.startKey = Bytes.readByteArray(in); this.tableName = Bytes.readByteArray(in); this.hashCode = in.readInt(); } else { throw new IOException("Non-migratable/unknown version=" + getVersion()); } }
From source file:dk.statsbiblioteket.util.LineReaderTest.java
public void testSample(String type, DataInput in) throws Exception { assertEquals("Int 1 should work for " + type, 12345, in.readInt()); assertEquals("Int 2 should work for " + type, -87, in.readInt()); assertEquals("Long should work for " + type, 123456789L, in.readLong()); assertEquals("String 1 should work for " + type, "Hello World!", in.readLine()); assertEquals("String 2 should work for " + type, "Another world", in.readLine()); assertEquals("Float should work for " + type, 0.5f, in.readFloat()); assertEquals("Boolean 1 should work for " + type, true, in.readBoolean()); assertEquals("Boolean 2 should work for " + type, false, in.readBoolean()); assertEquals("Byte 1 should work for " + type, (byte) 12, in.readByte()); assertEquals("Byte 2 should work for " + type, (byte) -12, in.readByte()); assertEquals("Unsigned byte should work for " + type, 129, in.readUnsignedByte()); assertEquals("Short should work for " + type, -4567, in.readShort()); byte[] loaded = new byte[5]; byte[] expected = new byte[] { (byte) 'A', (byte) 'S', (byte) 'C', (byte) 'I', (byte) 'I' }; in.readFully(loaded);//from w w w. ja v a2 s .c om for (int i = 0; i < loaded.length; i++) { assertEquals("Byte-stored string should be equal at byte " + i + " for " + type, expected[i], loaded[i]); } }
From source file:com.fiorano.openesb.application.aps.ApplicationHeader.java
/** * This method reads this <code>ApplicationHeaders</code> object from the * specified input stream object.//from w ww .j ava 2 s .co m * * @param is DataInput object * @param versionNo * @exception IOException if an error occurs while reading bytes or while * converting them into specified Java primitive type. * @since Tifosi2.0 */ public void fromStream(DataInput is, int versionNo) throws IOException { super.fromStream(is, versionNo); m_canBeSubGraphed = is.readBoolean(); String temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) m_scope = null; else m_scope = temp; temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) m_appName = null; else m_appName = temp; temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) m_appGUID = null; else setApplicationGUID(temp); temp = UTFReaderWriter.readUTF(is); if (temp == null || temp.trim().equals("")) formatStringAsDate(""); else formatStringAsDate(temp); temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) m_category = null; else m_category = temp; int tempInt; if ((tempInt = is.readInt()) != 0) for (int i = 0; i < tempInt; i++) { String name = UTFReaderWriter.readUTF(is); m_authorNames.add(name); } temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) m_iconName = null; else m_iconName = temp; temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) m_shortDescription = null; else m_shortDescription = temp; temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) m_longDescription = null; else m_longDescription = temp; if ((tempInt = is.readInt()) != 0) for (int i = 0; i < tempInt; i++) { String name = UTFReaderWriter.readUTF(is); m_compatibleWith.add(name); } m_maxInstLimit = is.readInt(); if ((tempInt = is.readInt()) != 0) for (int i = 0; i < tempInt; i++) { Param param = new Param(); param.fromStream(is, versionNo); m_params.add(param); } temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) m_version = null; else m_version = temp; m_isVersionLocked = is.readBoolean(); m_strProfile = UTFReaderWriter.readUTF(is); int result = is.readInt(); if (result == 1) { m_appContext = new ApplicationContext(); m_appContext.fromStream(is, versionNo); } }
From source file:com.fiorano.openesb.application.aps.Route.java
/** * This method reads this object <code>Routes</code> from the specified * input stream object./*from w w w . j a v a2 s .c om*/ * * @param is DataInput object * @param versionNo * @exception IOException if an error occurs while reading bytes or while * converting them into specified Java primitive type. * @see #toStream(DataOutput, int) * @since Tifosi2.0 */ public void fromStream(DataInput is, int versionNo) throws IOException { super.fromStream(is, versionNo); m_isP2PRoute = is.readBoolean(); m_isPersitant = is.readBoolean(); m_isDurable = is.readBoolean(); m_applyTransformationAtSrc = is.readBoolean(); String temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) { m_routeName = null; } else { m_routeName = temp; } temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) { m_routeGUID = null; } else { m_routeGUID = temp; } m_iTimeToLive = is.readLong(); temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) { m_srcServInst = null; } else { m_srcServInst = temp; } temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) { m_trgtServInst = null; } else { m_trgtServInst = temp; } temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) { m_srcPortName = null; } else { m_srcPortName = temp; } temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) { m_trgtPortName = null; } else { m_trgtPortName = temp; } temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) { m_transformationXSL = null; } else { m_transformationXSL = temp; } int size = is.readInt(); if (size > 0) { _readSelectorFromOldDmi(is, versionNo, size); } else if (size < 0) { _readSelector(is, versionNo); } int tempInt = 0; if ((tempInt = is.readInt()) != 0) { for (int i = 0; i < tempInt; i++) { Param param = new Param(); param.fromStream(is, versionNo); m_params.add(param); } } temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) { m_shortDescription = null; } else { m_shortDescription = temp; } temp = UTFReaderWriter.readUTF(is); if (temp.equals("")) { m_longDescription = null; } else { m_longDescription = temp; } if (is.readInt() == 1) { m_altDestination = new AlternateDestination(); m_altDestination.fromStream(is, versionNo); } }