@CanIgnoreReturnValue // to skip a field @Override public String readUTF() throws IOException { return new DataInputStream(in).readUTF(); }
private String readNullableString(final DataInputStream in) throws IOException { final boolean valueExists = in.readBoolean(); if (valueExists) { return in.readUTF(); } else { return null; } }
private void readHeaderToken() throws IOException { byte archiveVersion = dataIn.readByte(); if (archiveVersion <= 1) { throw new GemFireIOException( String.format("Archive version: %s is no longer supported.", new Byte(archiveVersion)), null); } if (archiveVersion > ARCHIVE_VERSION) { throw new GemFireIOException( String.format("Unsupported archive version: %s . The supported version is: %s .", new Object[] {new Byte(archiveVersion), new Byte(ARCHIVE_VERSION)}), null); } this.archiveVersion = archiveVersion; this.startTimeStamp = dataIn.readLong(); this.systemId = dataIn.readLong(); this.systemStartTimeStamp = dataIn.readLong(); this.timeZoneOffset = dataIn.readInt(); this.timeZoneName = dataIn.readUTF(); this.systemDirectory = dataIn.readUTF(); this.productVersion = dataIn.readUTF(); this.os = dataIn.readUTF(); this.machine = dataIn.readUTF(); }
static void roll() { try { Socket socket = new Socket(host, port); DataOutputStream dos = new DataOutputStream(socket.getOutputStream()); DataInputStream dis = new DataInputStream(socket.getInputStream()); dos.writeUTF(ExternallyRolledFileAppender.ROLL_OVER); String rc = dis.readUTF(); if(ExternallyRolledFileAppender.OK.equals(rc)) { cat.info("Roll over signal acknowledged by remote appender."); } else { cat.warn("Unexpected return code "+rc+" from remote entity."); System.exit(2); } } catch(IOException e) { cat.error("Could not send roll signal on host "+host+" port "+port+" .", e); System.exit(2); } System.exit(0); } }
String msg_received; ServerSocket socket = new ServerSocket(1755); Socket clientSocket = socket.accept(); //This is blocking. It will wait. DataInputStream DIS = new DataInputStream(clientSocket.getInputStream()); msg_received = DIS.readUTF(); clientSocket.close(); socket.close();
/** * Deserializes one action that was serialized with {@link #serializeToStream(DownloadAction, * OutputStream)} from the {@code input}, using the {@link Deserializer}s that supports the * action's type. * * <p>The caller is responsible for closing the given {@link InputStream}. * * @param deserializers {@link Deserializer}s for supported actions. * @param input The stream from which to read the action. * @return The deserialized action. * @throws IOException If there is an IO error reading from {@code input}, or if the action type * isn't supported by any of the {@code deserializers}. */ public static DownloadAction deserializeFromStream( Deserializer[] deserializers, InputStream input) throws IOException { // Don't close the stream as it closes the underlying stream too. DataInputStream dataInputStream = new DataInputStream(input); String type = dataInputStream.readUTF(); int version = dataInputStream.readInt(); for (Deserializer deserializer : deserializers) { if (type.equals(deserializer.type) && deserializer.version >= version) { return deserializer.readFromStream(version, dataInputStream); } } throw new DownloadException("No deserializer found for:" + type + ", " + version); }
import java.io.*; public class Test { public static void main(String[] args) throws IOException { byte[] data; try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { try (DataOutputStream dos = new DataOutputStream(baos)) { dos.writeShort(10000); for (int i = 0; i < 500; i++) { dos.write(0); } } data = baos.toByteArray(); } try (ByteArrayInputStream bais = new ByteArrayInputStream(data)) { try (DataInputStream dis = new DataInputStream(bais)) { System.out.println(dis.readUTF()); } } } }
private SnapshotHeader validateHeader(final DataInputStream dataIn) throws IOException { final String snapshotClass = dataIn.readUTF(); logger.debug("Snapshot Class Name for {} is {}", storageDirectory, snapshotClass); if (!snapshotClass.equals(HashMapSnapshot.class.getName())) { throw new IOException("Write-Ahead Log Snapshot located at " + storageDirectory + " was written using the " + snapshotClass + " class; cannot restore using " + getClass().getName()); } final int snapshotVersion = dataIn.readInt(); logger.debug("Snapshot version for {} is {}", storageDirectory, snapshotVersion); if (snapshotVersion > getVersion()) { throw new IOException("Write-Ahead Log Snapshot located at " + storageDirectory + " was written using version " + snapshotVersion + " of the " + snapshotClass + " class; cannot restore using Version " + getVersion()); } final String serdeEncoding = dataIn.readUTF(); // ignore serde class name for now logger.debug("Serde encoding for Snapshot at {} is {}", storageDirectory, serdeEncoding); final int serdeVersion = dataIn.readInt(); logger.debug("Serde version for Snapshot at {} is {}", storageDirectory, serdeVersion); final long maxTransactionId = dataIn.readLong(); logger.debug("Max Transaction ID for Snapshot at {} is {}", storageDirectory, maxTransactionId); final int numRecords = dataIn.readInt(); logger.debug("Number of Records for Snapshot at {} is {}", storageDirectory, numRecords); final SerDe<T> serde = serdeFactory.createSerDe(serdeEncoding); serde.readHeader(dataIn); return new SnapshotHeader(serde, serdeVersion, maxTransactionId, numRecords); }
@Override public ProgressiveDownloadAction readFromStream(int version, DataInputStream input) throws IOException { Uri uri = Uri.parse(input.readUTF()); boolean isRemoveAction = input.readBoolean(); int dataLength = input.readInt(); byte[] data = new byte[dataLength]; input.readFully(data); String customCacheKey = input.readBoolean() ? input.readUTF() : null; return new ProgressiveDownloadAction(uri, isRemoveAction, data, customCacheKey); } };
IOException { DataInputStream in = new DataInputStream(new ByteBufferBackedInputStream(payload)); try { String columnName = in.readUTF(); boolean skip = in.readBoolean(); if (skip) { info.skipPruning.set(true);
DataInputStream inputStream = new DataInputStream(new ByteBufferBackedInputStream(buffer)); byte opCode = inputStream.readByte(); inputStream.readUTF();
/** * Reads a class descriptor from the source stream. * * @return the class descriptor read from the source stream. * @throws ClassNotFoundException * if a class for one of the objects cannot be found. * @throws IOException * if an error occurs while reading from the source stream. */ protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { ObjectStreamClass newClassDesc = new ObjectStreamClass(); String name = input.readUTF(); if (name.length() == 0) { throw new IOException("The stream is corrupted"); } newClassDesc.setName(name); newClassDesc.setSerialVersionUID(input.readLong()); newClassDesc.setFlags(input.readByte()); /* * We must register the class descriptor before reading field * descriptors. If called outside of readObject, the descriptorHandle * might be unset. */ if (descriptorHandle == -1) { descriptorHandle = nextHandle(); } registerObjectRead(newClassDesc, descriptorHandle, false); readFieldDescriptors(newClassDesc); return newClassDesc; }
private String readUUID(final DataInputStream in, final int serializationVersion) throws IOException { if (serializationVersion < 8) { final long msb = in.readLong(); final long lsb = in.readLong(); return new UUID(msb, lsb).toString(); } else { // before version 8, we serialized UUID's as two longs in order to // write less data. However, in version 8 we changed to just writing // out the string because it's extremely expensive to call UUID.fromString. // In the end, since we generally compress, the savings in minimal anyway. final String uuid = in.readUTF(); if (!UUID_PATTERN.matcher(uuid).matches()) { throw new IOException("Failed to parse Provenance Event Record: expected a UUID but got: " + uuid); } return uuid; } }
private StateMap deserialize(final byte[] data, final int recordVersion, final String componentId) throws IOException { try (final ByteArrayInputStream bais = new ByteArrayInputStream(data); final DataInputStream dis = new DataInputStream(bais)) { final byte encodingVersion = dis.readByte(); if (encodingVersion > ENCODING_VERSION) { throw new IOException("Retrieved a response from ZooKeeper when retrieving state for component with ID " + componentId + ", but the response was encoded using the ZooKeeperStateProvider Encoding Version of " + encodingVersion + " but this instance can only decode versions up to " + ENCODING_VERSION + "; it appears that the state was encoded using a newer version of NiFi than is currently running. This information cannot be decoded."); } final int numEntries = dis.readInt(); final Map<String, String> stateValues = new HashMap<>(numEntries); for (int i = 0; i < numEntries; i++) { final boolean hasKey = dis.readBoolean(); final String key = hasKey ? dis.readUTF() : null; final boolean hasValue = dis.readBoolean(); final String value = hasValue ? dis.readUTF() : null; stateValues.put(key, value); } return new StandardStateMap(stateValues, recordVersion); } }
int ch = s.getInputStream().read(); if (ch<0) throw new IOException("Failed to read the HTTP proxy response: "+rsp); rsp.write(ch); DataOutputStream dos = new DataOutputStream(s.getOutputStream()); dos.writeUTF("Protocol:CLI-connect"); DataInputStream dis = new DataInputStream(s.getInputStream()); dos = new DataOutputStream(s.getOutputStream()); dos.writeUTF("Protocol:CLI2-connect"); String greeting = dis.readUTF(); if (!greeting.equals("Welcome")) throw new IOException("Handshaking failed: "+greeting);
LOGGER.log(Level.FINE, "Accepted connection #{0} from {1}", new Object[] {id, s.getRemoteSocketAddress()}); DataInputStream in = new DataInputStream(s.getInputStream()); PrintWriter out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(s.getOutputStream(),"UTF-8")), String s = new DataInputStream(new SequenceInputStream(new ByteArrayInputStream(head),in)).readUTF();