本文整理了Java中java.io.DataInputStream.readUTF()
方法的一些代码示例,展示了DataInputStream.readUTF()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataInputStream.readUTF()
方法的具体详情如下:
包路径:java.io.DataInputStream
类名称:DataInputStream
方法名:readUTF
[英]See the general contract of the readUTF
method of DataInput
.
Bytes for this operation are read from the contained input stream.
[中]参见readUTF
方法DataInput
的总合同。
此操作的字节从包含的输入流中读取。
代码示例来源:origin: stanfordnlp/CoreNLP
protected void read(DataInputStream inf) throws IOException {
num = inf.readInt();
// mg2008: slight speedup:
val = inf.readUTF();
// intern the tag strings as they are read, since there are few of them. This saves tons of memory.
tag = inf.readUTF();
hashCode = 0;
}
代码示例来源:origin: google/guava
@CanIgnoreReturnValue // to skip a field
@Override
public String readUTF() throws IOException {
return new DataInputStream(in).readUTF();
}
代码示例来源:origin: apache/nifi
private String readNullableString(final DataInputStream in) throws IOException {
final boolean valueExists = in.readBoolean();
if (valueExists) {
return in.readUTF();
} else {
return null;
}
}
代码示例来源:origin: apache/geode
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();
}
代码示例来源:origin: log4j/log4j
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);
}
}
代码示例来源:origin: stackoverflow.com
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();
代码示例来源:origin: google/ExoPlayer
/**
* 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);
}
代码示例来源:origin: stackoverflow.com
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());
}
}
}
}
代码示例来源:origin: apache/nifi
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);
}
代码示例来源:origin: google/ExoPlayer
@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);
}
};
代码示例来源:origin: apache/hive
IOException {
DataInputStream in = new DataInputStream(new ByteBufferBackedInputStream(payload));
try {
String columnName = in.readUTF();
boolean skip = in.readBoolean();
if (skip) {
info.skipPruning.set(true);
代码示例来源:origin: voldemort/voldemort
DataInputStream inputStream = new DataInputStream(new ByteBufferBackedInputStream(buffer));
byte opCode = inputStream.readByte();
inputStream.readUTF();
代码示例来源:origin: apache/nifi
public static void rejectCodecNegotiation(final DataInputStream dis, final DataOutputStream dos, final String explanation) throws IOException {
dis.readUTF(); // read codec name
dis.readInt(); // read codec version
dos.write(ABORT);
dos.writeUTF(explanation);
dos.flush();
}
代码示例来源:origin: robovm/robovm
/**
* 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;
}
代码示例来源:origin: apache/activemq
return this.dataIn.readInt();
return this.dataIn.readByte();
return Integer.valueOf(this.dataIn.readUTF()).intValue();
代码示例来源:origin: apache/nifi
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;
}
}
代码示例来源:origin: voldemort/voldemort
byte opCode = inputStream.readByte();
String storeName = inputStream.readUTF();
RequestRoutingType routingType = getRoutingType(inputStream);
代码示例来源:origin: apache/nifi
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);
}
}
代码示例来源:origin: jenkinsci/jenkins
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);
代码示例来源:origin: jenkinsci/jenkins
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();
内容来源于网络,如有侵权,请联系作者删除!