try{
if (len > 0) {
int received = 0;
boolean keepMoving = true;
while (keepMoving) {
int curByte;
try {
curByte = _in.read();
if (curByte >= 0) {
_heartBeatValidator.setTimeOut();
baos.write(curByte);
received++;
if (received >= len) {
keepMoving = false;
}
} else {
_logger.warn("Negative curByte = " + curByte);
keepMoving = false;
}
} catch (IOException e) {
checkConnectivity();
keepMoving = false;
}
}
if (baos.size() > 0) {
try {
final byte[] msg = baos.toByteArray();
final InputStream inputStream = new ByteArrayInputStream(msg);
data = XMLUTILS.toDOM(inputStream);
} catch (SAXException e) {
_logger.warn("Broken data received");
}
}
}
} catch (IOException ioex) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
_logger.error("", e);
}
}
public class WrappedInputStream extends FilterInputStream {
private static final int PACKET_CLOSED = -1;
private int remaining = PACKET_CLOSED;
private final DataInputStream fDataInputStream;
public WrappedInputStream(InputStream stream) throws IOException {
super(stream);
fDataInputStream = new DataInputStream(stream);
}
@Override
public int read() throws IOException {
final boolean wasClosed = readHeader();
if (!isEmpty()) {
final byte read = (byte) super.in.read();
if (isValid(read)) {
check(wasClosed, 1, read, read);
return read;
} else {
close();
return -1;
}
} else {
close();
Copyright©1996-2021,Tapuz Media Ltd. Forum software by XenForo® © 2010-2020 XenForo Ltd.