use of java.nio.channels.ClosedByInterruptException in project mapdb by jankotek.
the class FileChannelVol method writeFully.
protected void writeFully(long offset, ByteBuffer buf) {
int remaining = buf.limit() - buf.position();
if (CC.VOLUME_PRINT_STACK_AT_OFFSET != 0 && CC.VOLUME_PRINT_STACK_AT_OFFSET >= offset && CC.VOLUME_PRINT_STACK_AT_OFFSET <= offset + remaining) {
new IOException("VOL STACK:").printStackTrace();
}
try {
while (remaining > 0) {
int write = channel.write(buf, offset);
if (write < 0)
throw new EOFException();
remaining -= write;
}
} catch (ClosedByInterruptException e) {
throw new DBException.VolumeClosedByInterrupt(e);
} catch (ClosedChannelException e) {
throw new DBException.VolumeClosed(e);
} catch (IOException e) {
throw new DBException.VolumeIOException(e);
}
}
use of java.nio.channels.ClosedByInterruptException in project evosuite by EvoSuite.
the class EvoFileChannel method write.
private int write(ByteBuffer[] srcs, int offset, int length, AtomicInteger posToUpdate) throws IOException {
if (!isOpenForWrite) {
throw new NonWritableChannelException();
}
if ((offset < 0) || (offset > srcs.length) || (length < 0) || (length > srcs.length - offset)) {
throw new IndexOutOfBoundsException();
}
throwExceptionIfClosed();
int counter = 0;
byte[] buffer = new byte[1];
synchronized (readWriteMonitor) {
for (int j = offset; j < length; j++) {
ByteBuffer src = srcs[j];
int r = src.remaining();
for (int i = 0; i < r; i++) {
byte b = src.get();
buffer[0] = b;
NativeMockedIO.writeBytes(path, posToUpdate, buffer, 0, 1);
counter++;
if (closed) {
throw new AsynchronousCloseException();
}
if (Thread.currentThread().isInterrupted()) {
close();
throw new ClosedByInterruptException();
}
}
}
}
return counter;
}
use of java.nio.channels.ClosedByInterruptException in project storm by apache.
the class SystemOperation method exec.
public static String exec(String cmd) throws IOException {
LOG.debug("Shell cmd: {}", cmd);
Process process = new ProcessBuilder(new String[] { "/bin/bash", "-c", cmd }).start();
try {
process.waitFor();
String output = IOUtils.toString(process.getInputStream());
String errorOutput = IOUtils.toString(process.getErrorStream());
LOG.debug("Shell Output: {}", output);
if (errorOutput.length() != 0) {
LOG.error("Shell Error Output: {}", errorOutput);
throw new IOException(errorOutput);
}
return output;
} catch (InterruptedException | ClosedByInterruptException ie) {
throw new IOException(ie);
}
}
use of java.nio.channels.ClosedByInterruptException in project canal by alibaba.
the class BioSocketChannel method read.
public byte[] read(int readSize, int timeout) throws IOException {
InputStream input = this.input;
byte[] data = new byte[readSize];
int remain = readSize;
int accTimeout = 0;
if (input == null) {
throw new SocketException("Socket already closed.");
}
while (remain > 0 && accTimeout < timeout) {
try {
int read = input.read(data, readSize - remain, remain);
if (read > -1) {
remain -= read;
} else {
throw new IOException("EOF encountered.");
}
} catch (SocketTimeoutException te) {
if (Thread.interrupted()) {
throw new ClosedByInterruptException();
}
accTimeout += SO_TIMEOUT;
}
}
if (remain > 0 && accTimeout >= timeout) {
throw new SocketTimeoutException("Timeout occurred, failed to read total " + readSize + " bytes in " + timeout + " milliseconds, actual read only " + (readSize - remain) + " bytes");
}
return data;
}
use of java.nio.channels.ClosedByInterruptException in project canal by alibaba.
the class DirectLogFetcher method fetch.
/**
* {@inheritDoc}
*
* @see com.taobao.tddl.dbsync.binlog.LogFetcher#fetch()
*/
public boolean fetch() throws IOException {
try {
// Fetching packet header from input.
if (!fetch0(0, NET_HEADER_SIZE)) {
logger.warn("Reached end of input stream while fetching header");
return false;
}
// Fetching the first packet(may a multi-packet).
int netlen = getUint24(PACKET_LEN_OFFSET);
int netnum = getUint8(PACKET_SEQ_OFFSET);
if (!fetch0(NET_HEADER_SIZE, netlen)) {
logger.warn("Reached end of input stream: packet #" + netnum + ", len = " + netlen);
return false;
}
// Detecting error code.
final int mark = getUint8(NET_HEADER_SIZE);
if (mark != 0) {
if (// error from master
mark == 255) {
// Indicates an error, for example trying to fetch from
// wrong
// binlog position.
position = NET_HEADER_SIZE + 1;
final int errno = getInt16();
String sqlstate = forward(1).getFixString(SQLSTATE_LENGTH);
String errmsg = getFixString(limit - position);
throw new IOException("Received error packet:" + " errno = " + errno + ", sqlstate = " + sqlstate + " errmsg = " + errmsg);
} else if (mark == 254) {
// Indicates end of stream. It's not clear when this would
// be sent.
logger.warn("Received EOF packet from server, apparent" + " master disconnected. It's may be duplicate slaveId , check instance config");
return false;
} else {
// Should not happen.
throw new IOException("Unexpected response " + mark + " while fetching binlog: packet #" + netnum + ", len = " + netlen);
}
}
// if mysql is in semi mode
if (issemi) {
// parse semi mark
int semimark = getUint8(NET_HEADER_SIZE + 1);
int semival = getUint8(NET_HEADER_SIZE + 2);
this.semival = semival;
}
// The first packet is a multi-packet, concatenate the packets.
while (netlen == MAX_PACKET_LENGTH) {
if (!fetch0(0, NET_HEADER_SIZE)) {
logger.warn("Reached end of input stream while fetching header");
return false;
}
netlen = getUint24(PACKET_LEN_OFFSET);
netnum = getUint8(PACKET_SEQ_OFFSET);
if (!fetch0(limit, netlen)) {
logger.warn("Reached end of input stream: packet #" + netnum + ", len = " + netlen);
return false;
}
}
// Preparing buffer variables to decoding.
if (issemi) {
origin = NET_HEADER_SIZE + 3;
} else {
origin = NET_HEADER_SIZE + 1;
}
position = origin;
limit -= origin;
return true;
} catch (SocketTimeoutException e) {
close();
/* Do cleanup */
logger.error("Socket timeout expired, closing connection", e);
throw e;
} catch (InterruptedIOException | ClosedByInterruptException e) {
close();
/* Do cleanup */
logger.info("I/O interrupted while reading from client socket", e);
throw e;
} catch (IOException e) {
close();
/* Do cleanup */
logger.error("I/O error while reading from client socket", e);
throw e;
}
}
Aggregations