List of usage examples for java.io DataInputStream readUTF
public final String readUTF() throws IOException
readUTF
method of DataInput
. From source file:org.apache.reef.io.data.loading.impl.DistributedDataSetPartitionSerializer.java
public static DistributedDataSetPartition deserialize(final String serializedPartition) { try (ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decodeBase64(serializedPartition))) { final DataInputStream dais = new DataInputStream(bais); return new DistributedDataSetPartition(dais.readUTF(), dais.readUTF(), dais.readInt()); } catch (final IOException e) { throw new RuntimeException("Unable to de-serialize distributed data partition", e); }/*w ww. j a v a2 s . c o m*/ }
From source file:com.koda.common.lcm.Tool.java
public static Object fromFile(String fileName) throws IOException { FileInputStream fis = new FileInputStream(fileName); DataInputStream dis = new DataInputStream(fis); String s = dis.readUTF(); dis.close();/* www . j ava 2 s .c om*/ return undoObject(s); }
From source file:com.microsoft.tfs.client.eclipse.resourcedata.ResourceData.java
/** * Deserializes a {@link ResourceData} object from a byte array. * * @param value/*from w ww. ja va2 s . c o m*/ * the byte array (not null) * @return the deserialized {@link ResourceData} or <code>null</code> if * there was a problem deserializing */ public static ResourceData fromByteArray(final byte[] value) { Check.notNull(value, "value"); //$NON-NLS-1$ try { final ByteArrayInputStream is = new ByteArrayInputStream(value); final DataInputStream dis = new DataInputStream(is); return new ResourceData(dis.readUTF(), dis.readInt()); } catch (final IOException e) { log.error("Error deserializing", e); //$NON-NLS-1$ return null; } }
From source file:io.hops.hopsworks.common.jobs.yarn.LogReader.java
/** * Keep calling this till you get a {@link EOFException} for getting logs of * all types for a single container./* w ww.j a va2s . c o m*/ * * @param valueStream * @param out * @throws IOException */ public static void readAContainerLogsForALogType(DataInputStream valueStream, PrintStream out) throws IOException { byte[] buf = new byte[65535]; String fileType = valueStream.readUTF(); String fileLengthStr = valueStream.readUTF(); long fileLength = Long.parseLong(fileLengthStr); out.print("LogType: "); out.println(fileType); out.print("LogLength: "); out.println(fileLengthStr); out.println("Log Contents:"); long curRead = 0; long pendingRead = fileLength - curRead; int toRead = pendingRead > buf.length ? buf.length : (int) pendingRead; int len = valueStream.read(buf, 0, toRead); while (len != -1 && curRead < fileLength) { out.write(buf, 0, len); curRead += len; pendingRead = fileLength - curRead; toRead = pendingRead > buf.length ? buf.length : (int) pendingRead; len = valueStream.read(buf, 0, toRead); } out.println(""); }
From source file:com.splout.db.benchmark.TCPTest.java
public static void tcpTest(String file, String table) throws UnknownHostException, IOException, InterruptedException, JSONSerDeException { final TCPServer server = new TCPServer(8888, file, table); Thread t = new Thread() { @Override/*from w w w.j a v a2 s. c o m*/ public void run() { server.serve(); } }; t.start(); while (!server.isServing()) { Thread.sleep(100); } Socket clientSocket = new Socket("localhost", 8888); DataInputStream inFromServer = new DataInputStream(new BufferedInputStream(clientSocket.getInputStream())); try { do { // Read a record inFromServer.readUTF(); inFromServer.readInt(); inFromServer.readDouble(); inFromServer.readUTF(); } while (true); } catch (Throwable th) { th.printStackTrace(); } clientSocket.close(); server.stop(); t.interrupt(); }
From source file:Main.java
public static Object[] readSettings(String file) throws IOException { DataInputStream in = new DataInputStream(new FileInputStream(file)); try {/*from w w w .j av a 2s. c om*/ Object[] res = new Object[in.readInt()]; for (int i = 0; i < res.length; i++) { char cl = in.readChar(); switch (cl) { case 'S': res[i] = in.readUTF(); break; case 'F': res[i] = in.readFloat(); break; case 'D': res[i] = in.readDouble(); break; case 'I': res[i] = in.readInt(); break; case 'L': res[i] = in.readLong(); break; case 'B': res[i] = in.readBoolean(); break; case 'Y': res[i] = in.readByte(); break; default: throw new IllegalStateException("cannot read type " + cl + " from " + file); } } return res; } finally { in.close(); } }
From source file:org.apache.jackrabbit.core.persistence.util.Serializer.java
/** * Deserializes a <code>NodeState</code> object from the given binary * <code>stream</code>.//from www .j a v a 2 s . c o m * * @param state <code>state</code> to deserialize * @param stream the stream where the <code>state</code> should be deserialized from * @throws Exception if an error occurs during the deserialization * @see #serialize(NodeState, OutputStream) */ public static void deserialize(NodeState state, InputStream stream) throws Exception { DataInputStream in = new DataInputStream(stream); // primaryType String s = in.readUTF(); state.setNodeTypeName(NameFactoryImpl.getInstance().create(s)); // parentUUID (may be null) byte[] uuidBytes = new byte[NodeId.UUID_BYTE_LENGTH]; in.readFully(uuidBytes); if (!Arrays.equals(uuidBytes, NULL_UUID_PLACEHOLDER_BYTES)) { state.setParentId(new NodeId(uuidBytes)); } // definitionId in.readUTF(); // mixin types int count = in.readInt(); // count Set<Name> set = new HashSet<Name>(count); for (int i = 0; i < count; i++) { set.add(NameFactoryImpl.getInstance().create(in.readUTF())); } if (set.size() > 0) { state.setMixinTypeNames(set); } // modCount short modCount = in.readShort(); state.setModCount(modCount); // properties (names) count = in.readInt(); // count for (int i = 0; i < count; i++) { state.addPropertyName(NameFactoryImpl.getInstance().create(in.readUTF())); // name } // child nodes (list of name/uuid pairs) count = in.readInt(); // count for (int i = 0; i < count; i++) { Name name = NameFactoryImpl.getInstance().create(in.readUTF()); // name // uuid in.readFully(uuidBytes); state.addChildNodeEntry(name, new NodeId(uuidBytes)); } }
From source file:io.hops.hopsworks.common.jobs.yarn.LogReader.java
/** * Writes all logs for a single container to the provided writer. * * @param valueStream/*from w w w .jav a 2 s. c o m*/ * @param writer * @throws IOException */ public static void readAcontainerLogs(DataInputStream valueStream, Writer writer) throws IOException { int bufferSize = 65536; char[] cbuf = new char[bufferSize]; String fileType; String fileLengthStr; long fileLength; while (true) { try { fileType = valueStream.readUTF(); } catch (EOFException e) { // EndOfFile return; } fileLengthStr = valueStream.readUTF(); fileLength = Long.parseLong(fileLengthStr); writer.write("\n\nLogType:"); writer.write(fileType); writer.write("\nLogLength:"); writer.write(fileLengthStr); writer.write("\nLog Contents:\n"); // ByteLevel BoundedInputStream bis = new BoundedInputStream(valueStream, fileLength); InputStreamReader reader = new InputStreamReader(bis); int currentRead = 0; int totalRead = 0; while ((currentRead = reader.read(cbuf, 0, bufferSize)) != -1) { writer.write(cbuf, 0, currentRead); totalRead += currentRead; } } }
From source file:ja.lingo.engine.mergedindex.ChannelMergedIndex.java
private static Map<Integer, IDictionaryIndex> _deserializeReaderIdToReaderMap(DataInputStream dis, Map<String, IDictionaryIndex> indexFileNameToReaderMap) throws IOException { Map<Integer, IDictionaryIndex> readerIdToReaderMap = new HashMap<Integer, IDictionaryIndex>(); int readerCount = dis.readInt(); for (int i = 0; i < readerCount; i++) { int readerId = dis.readInt(); String indexFileName = dis.readUTF(); IDictionaryIndex reader = indexFileNameToReaderMap.get(indexFileName); if (reader == null) { throw new IOException("Unable to retrieve reader with readerId=\"" + readerId + "\" and indexFileName=\"" + indexFileName + "\""); }//ww w .j a v a2 s.c o m readerIdToReaderMap.put(readerId, reader); } return readerIdToReaderMap; }
From source file:org.apache.jackrabbit.core.persistence.util.Serializer.java
/** * Deserializes a <code>NodeReferences</code> object from the given * binary <code>stream</code>. * * @param refs object to deserialize//from w ww . jav a2s.co m * @param stream the stream where the object should be deserialized from * @throws Exception if an error occurs during the deserialization * @see #serialize(NodeReferences, OutputStream) */ public static void deserialize(NodeReferences refs, InputStream stream) throws Exception { DataInputStream in = new DataInputStream(stream); refs.clearAllReferences(); // references int count = in.readInt(); // count for (int i = 0; i < count; i++) { refs.addReference(PropertyId.valueOf(in.readUTF())); // propertyId } }