本文整理了Java中java.io.DataInputStream.read()
方法的一些代码示例,展示了DataInputStream.read()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataInputStream.read()
方法的具体详情如下:
包路径:java.io.DataInputStream
类名称:DataInputStream
方法名:read
暂无
代码示例来源:origin: apache/incubator-dubbo
@Override
public byte[] readBytes() throws IOException {
int length = dis.readInt();
byte[] bytes = new byte[length];
dis.read(bytes, 0, length);
return bytes;
}
}
代码示例来源:origin: skylot/jadx
private static String readString(DataInputStream in) throws IOException {
int len = in.readByte();
byte[] bytes = new byte[len];
int count = in.read(bytes);
while (count != len) {
int res = in.read(bytes, count, len - count);
if (res == -1) {
throw new IOException("String read error");
} else {
count += res;
}
}
return new String(bytes, STRING_CHARSET);
}
代码示例来源:origin: apache/nifi
@Override
public SetRecord deserializeEdit(final DataInputStream in, final Map<Object, SetRecord> currentRecordStates, final int version) throws IOException {
final int value = in.read();
if (value < 0) {
throw new EOFException();
}
final UpdateType updateType = (value == 0 ? UpdateType.DELETE : UpdateType.CREATE);
final int size = in.readInt();
final byte[] data = new byte[size];
in.readFully(data);
return new SetRecord(updateType, ByteBuffer.wrap(data));
}
代码示例来源:origin: aragozin/jvm-tools
loaded = false;
while(true) {
int tag = dis.read();
if (tag < 0) {
dis.close();
String str = dis.readUTF();
stringDic.add(str);
throw new IOException("Data format error");
代码示例来源:origin: apache/nifi
private boolean isMoreFlowFiles(final DataInputStream in, final int protocolVersion) throws IOException {
final int indicator = in.read();
if (indicator < 0) {
throw new EOFException();
}
if (indicator == MORE_FLOWFILES) {
logger.debug("Peer indicates that there is another FlowFile in transaction");
return true;
}
if (indicator == NO_MORE_FLOWFILES) {
logger.debug("Peer indicates that there are no more FlowFiles in transaction");
return false;
}
throw new IOException("Expected to receive 'More FlowFiles' indicator (" + MORE_FLOWFILES
+ ") or 'No More FlowFiles' indicator (" + NO_MORE_FLOWFILES + ") but received invalid value of " + indicator);
}
代码示例来源:origin: skylot/jadx
public void load(InputStream input) throws IOException, DecodeException {
try (DataInputStream in = new DataInputStream(input)) {
byte[] header = new byte[JADX_CLS_SET_HEADER.length()];
int readHeaderLength = in.read(header);
int version = in.readByte();
if (readHeaderLength != JADX_CLS_SET_HEADER.length()
|| !JADX_CLS_SET_HEADER.equals(new String(header, STRING_CHARSET))
|| version != VERSION) {
throw new DecodeException("Wrong jadx class set header");
}
int count = in.readInt();
classes = new NClass[count];
for (int i = 0; i < count; i++) {
String name = readString(in);
classes[i] = new NClass(name, i);
}
for (int i = 0; i < count; i++) {
int pCount = in.readByte();
NClass[] parents = new NClass[pCount];
for (int j = 0; j < pCount; j++) {
parents[j] = classes[in.readInt()];
}
classes[i].setParents(parents);
}
}
}
代码示例来源:origin: wildfly/wildfly
public void handleMessage(Channel channel, MessageInputStream messageInputStream) {
DataInputStream dis = new DataInputStream(messageInputStream);
try {
log.tracef("Bytes Available %d", dis.available());
byte[] firstThree = new byte[3];
dis.read(firstThree);
log.tracef("First Three %s", new String(firstThree));
if (Arrays.equals(firstThree, "JMX".getBytes()) == false) {
throw new IOException("Invalid leading bytes in header.");
}
future.setResult(null);
} catch (IOException e) {
future.setException(e);
} finally {
IoUtils.safeClose(dis);
}
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
DataInputStream dis = new DataInputStream(new BufferedInputStream(in));
dis.read(cMapData);
throw new IOException("Unsupported TGA true color depth: " + pixelDepth);
throw new IOException("Unsupported TGA true color depth: " + pixelDepth);
int index = dis.readUnsignedByte();
if (index >= cMapEntries.length || index < 0) {
throw new IOException("TGA: Invalid color map entry referenced: " + index);
代码示例来源:origin: wildfly/wildfly
public void handleMessage(Channel channel, MessageInputStream messageInputStream) {
DataInputStream dis = new DataInputStream(messageInputStream);
try {
log.tracef("Bytes Available %d", dis.available());
byte[] firstThree = new byte[3];
dis.read(firstThree);
log.tracef("First Three %s", new String(firstThree));
if (Arrays.equals(firstThree, "JMX".getBytes()) == false) {
throw new IOException("Invalid leading bytes in header.");
}
log.tracef("Bytes Available %d", dis.available());
String connectionId = dis.readUTF();
future.setResult(connectionId);
} catch (IOException e) {
future.setException(e);
} finally {
IoUtils.safeClose(dis);
}
}
代码示例来源:origin: apache/hbase
private void processResponseForConnectionHeader() throws IOException {
// if no response excepted, return
if (!waitingConnectionHeaderResponse) return;
try {
// read the ConnectionHeaderResponse from server
int len = this.in.readInt();
byte[] buff = new byte[len];
int readSize = this.in.read(buff);
if (LOG.isDebugEnabled()) {
LOG.debug("Length of response for connection header:" + readSize);
}
RPCProtos.ConnectionHeaderResponse connectionHeaderResponse =
RPCProtos.ConnectionHeaderResponse.parseFrom(buff);
// Get the CryptoCipherMeta, update the HBaseSaslRpcClient for Crypto Cipher
if (connectionHeaderResponse.hasCryptoCipherMeta()) {
negotiateCryptoAes(connectionHeaderResponse.getCryptoCipherMeta());
}
waitingConnectionHeaderResponse = false;
} catch (SocketTimeoutException ste) {
LOG.error(HBaseMarkers.FATAL, "Can't get the connection header response for rpc timeout, "
+ "please check if server has the correct configuration to support the additional "
+ "function.", ste);
// timeout when waiting the connection header response, ignore the additional function
throw new IOException("Timeout while waiting connection header response", ste);
}
}
代码示例来源:origin: aragozin/jvm-tools
loaded = false;
while(true) {
int tag = dis.read();
if (tag < 0) {
dis.close();
String str = dis.readUTF();
stringDic.add(str);
String str = dis.readUTF();
while(dynStringDic.size() <= id) {
dynStringDic.add(null);
String str = dis.readUTF();
int n = counterNames.length;
counterNames = Arrays.copyOf(counterNames, n + 1);
throw new IOException("Data format error");
代码示例来源:origin: apache/nifi
private void deserializeClaim(final DataInputStream in, final int serializationVersion, final StandardFlowFileRecord.Builder ffBuilder) throws IOException {
final int claimExists = in.read();
if (claimExists == 1) {
final String claimId;
throw new EOFException();
} else if (claimExists != 0) {
throw new IOException("Claim Existence Qualifier not found in stream; found value: "
+ claimExists + " after successfully restoring " + recordsRestored + " records");
代码示例来源:origin: apache/nifi
logger.debug("Consuming content from Peer {}", peerDescription);
int dataFrameIndicator = in.read();
if (dataFrameIndicator < 0) {
throw new EOFException("Encountered End-of-File when expecting to read Data Frame Indicator from Peer " + peerDescription);
throw new IOException("Expected a Data Frame Indicator from Peer " + peerDescription + " but received a value of " + dataFrameIndicator);
dataFrameIndicator = in.read();
if (dataFrameIndicator < 0) {
throw new EOFException("Encountered End-of-File when expecting to receive a Data Frame Indicator");
throw new IOException("Expected a Data Frame Indicator from Peer " + peerDescription + " but received a value of " + dataFrameIndicator);
代码示例来源:origin: libgdx/libgdx
static public Pixmap read (FileHandle file) {
DataInputStream in = null;
try {
// long start = System.nanoTime();
in = new DataInputStream(new InflaterInputStream(new BufferedInputStream(file.read())));
int width = in.readInt();
int height = in.readInt();
Format format = Format.fromGdx2DPixmapFormat(in.readInt());
Pixmap pixmap = new Pixmap(width, height, format);
ByteBuffer pixelBuf = pixmap.getPixels();
pixelBuf.position(0);
pixelBuf.limit(pixelBuf.capacity());
synchronized (readBuffer) {
int readBytes = 0;
while ((readBytes = in.read(readBuffer)) > 0) {
pixelBuf.put(readBuffer, 0, readBytes);
}
}
pixelBuf.position(0);
pixelBuf.limit(pixelBuf.capacity());
// Gdx.app.log("PixmapIO", "read:" + (System.nanoTime() - start) / 1000000000.0f);
return pixmap;
} catch (Exception e) {
throw new GdxRuntimeException("Couldn't read Pixmap from file '" + file + "'", e);
} finally {
StreamUtils.closeQuietly(in);
}
}
}
代码示例来源:origin: apache/activemq
int type = this.dataIn.read();
if (type == -1) {
throw new MessageEOFException("reached end of data");
return this.dataIn.readUTF();
return new Integer(this.dataIn.readInt()).toString();
代码示例来源:origin: cmusphinx/sphinx4
private void loadModelData(InputStream stream) throws IOException {
DataInputStream dataStream = new DataInputStream(new BufferedInputStream(stream));
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
while (true) {
if (dataStream.read(buffer) < 0)
break;
bytes.write(buffer);
}
inStream = new DataInputStream(new ByteArrayInputStream(bytes.toByteArray()));
}
代码示例来源:origin: Dreampie/Resty
public static Map<String, ParamAttribute> getParamNames(InputStream in)
throws IOException {
DataInputStream dis = new DataInputStream(new BufferedInputStream(in));
Map<String, List<LocalVariable>> names = new HashMap<String, List<LocalVariable>>();
Map<String, int[]> lines = new HashMap<String, int[]>();
int len = dis.readUnsignedShort();
byte[] data = new byte[len];
dis.read(data);
strs.put(i + 1, new String(data, "UTF-8"));// 必然是UTF8的
break;
for (int j = 0; j < attributes_count; j++) {
dis.skipBytes(2);// 跳过访问控制符
int attribute_length = dis.readInt();
dis.skipBytes(attribute_length);
for (int j = 0; j < attributes_count; j++) {
String attrName = strs.get(dis.readUnsignedShort());
int attribute_length = dis.readInt();
if ("Code".equals(attrName)) { // 形参只在Code属性中
dis.skipBytes(2);
dis.skipBytes(2);
int code_len = dis.readInt();
代码示例来源:origin: apache/geode
CompiledCode(byte[] code_block) throws IOException {
int idx;
ByteArrayInputStream bis = new ByteArrayInputStream(code_block);
DataInputStream source = new DataInputStream(bis);
max_stack = source.readUnsignedShort();
max_locals = source.readUnsignedShort();
code_length = source.readInt();
code = new byte[code_length];
source.read(code);
exception_table_length = source.readUnsignedShort();
exceptionTable = new ExceptionTableEntry[exception_table_length];
for (int i = 0; i < exception_table_length; i++) {
exceptionTable[i] = new ExceptionTableEntry(source);
}
attributes_count = source.readUnsignedShort();
attributes_info = new CompiledAttribute[attributes_count];
for (idx = 0; idx < attributes_count; idx++) {
attributes_info[idx] = new CompiledAttribute(source);
}
}
代码示例来源:origin: stackoverflow.com
byte[] messageByte = new byte[1000];
boolean end = false;
String dataString = "";
try
{
DataInputStream in = new DataInputStream(clientSocket.getInputStream());
int bytesRead = 0;
messageByte[0] = in.readByte();
messageByte[1] = in.readByte();
int bytesToRead = messageByte[1];
while(!end)
{
bytesRead = in.read(messageByte);
messageString += new String(messageByte, 0, bytesRead);
if (messageString.length == bytesToRead )
{
end = true;
}
}
System.out.println("MESSAGE: " + messageString);
}
catch (Exception e)
{
e.printStackTrace();
}
代码示例来源:origin: wildfly/wildfly
boolean handleRequest(DataInputStream in, DataOutputStream out) throws IOException {
while(true) {
byte type=(byte)in.read();
if(type == -1)
return false;
switch(type) {
case START:
int num=in.readInt();
startTest(num);
break;
case RECEIVE_ASYNC:
case RECEIVE_SYNC:
long val=in.readLong();
int len=in.readInt();
byte data[]=new byte[len];
in.readFully(data, 0, data.length);
receiveData(val, data);
if(type == RECEIVE_SYNC) {
out.writeLong(System.currentTimeMillis());
out.flush();
}
break;
default:
System.err.println("type " + type + " not known");
}
}
}
内容来源于网络,如有侵权,请联系作者删除!