本文整理汇总了Java中java.io.InterruptedIOException类的典型用法代码示例。如果您正苦于以下问题:Java InterruptedIOException类的具体用法?Java InterruptedIOException怎么用?Java InterruptedIOException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InterruptedIOException类属于java.io包,在下文中一共展示了InterruptedIOException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitUntilWritable
import java.io.InterruptedIOException; //导入依赖的package包/类
/**
* Returns once the peer is ready to receive {@code count} bytes.
*
* @throws IOException if the stream was finished or closed, or the
* thread was interrupted.
*/
private void waitUntilWritable(int count, boolean last) throws IOException {
try {
while (unacknowledgedBytes + count >= writeWindowSize) {
SpdyStream.this.wait(); // Wait until we receive a WINDOW_UPDATE.
// The stream may have been closed or reset while we were waiting!
if (!last && closed) {
throw new IOException("stream closed");
} else if (finished) {
throw new IOException("stream finished");
} else if (errorCode != null) {
throw new IOException("stream was reset: " + errorCode);
}
}
} catch (InterruptedException e) {
throw new InterruptedIOException();
}
}
示例2: subAppend
import java.io.InterruptedIOException; //导入依赖的package包/类
/**
* This method differentiates OpenraspDailyRollingFileAppender from its
* super class.
*
* <p>Before actually logging, this method will check whether it is
* time to do a rollover. If it is, it will schedule the next
* rollover time and then rollover.
* */
protected void subAppend(LoggingEvent event) {
long n = System.currentTimeMillis();
if (n >= nextCheck) {
now.setTime(n);
nextCheck = rc.getNextCheckMillis(now);
try {
rollOver();
}
catch(IOException ioe) {
if (ioe instanceof InterruptedIOException) {
Thread.currentThread().interrupt();
}
LogLog.error("rollOver() failed.", ioe);
}
}
super.subAppend(event);
}
示例3: createDirOnFileSystem
import java.io.InterruptedIOException; //导入依赖的package包/类
/**
* Creates a directory for a filesystem and configuration object. Assumes the user has already
* checked for this directory existence.
*
* @param fs
* @param conf
* @param dir
* @return the result of fs.mkdirs(). In case underlying fs throws an IOException, it checks
* whether the directory exists or not, and returns true if it exists.
* @throws IOException
*/
private static boolean createDirOnFileSystem(FileSystem fs, Configuration conf, Path dir)
throws IOException {
int i = 0;
IOException lastIOE = null;
int hdfsClientRetriesNumber =
conf.getInt("hdfs.client.retries.number", DEFAULT_HDFS_CLIENT_RETRIES_NUMBER);
int baseSleepBeforeRetries =
conf.getInt("hdfs.client.sleep.before.retries", DEFAULT_BASE_SLEEP_BEFORE_RETRIES);
do {
try {
return fs.mkdirs(dir);
} catch (IOException ioe) {
lastIOE = ioe;
if (fs.exists(dir)) return true; // directory is present
try {
sleepBeforeRetry("Create Directory", i + 1, baseSleepBeforeRetries,
hdfsClientRetriesNumber);
} catch (InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
}
} while (++i <= hdfsClientRetriesNumber);
throw new IOException("Exception in createDir", lastIOE);
}
示例4: interruptReadingResponseBody
import java.io.InterruptedIOException; //导入依赖的package包/类
@Test public void interruptReadingResponseBody() throws Exception {
int responseBodySize = 2 * 1024 * 1024; // 2 MiB
server.enqueue(new MockResponse()
.setBody(new Buffer().write(new byte[responseBodySize]))
.throttleBody(64 * 1024, 125, TimeUnit.MILLISECONDS)); // 500 Kbps
server.start();
interruptLater(500);
HttpURLConnection connection = new OkUrlFactory(client).open(server.url("/").url());
InputStream responseBody = connection.getInputStream();
byte[] buffer = new byte[1024];
try {
while (responseBody.read(buffer) != -1) {
}
fail("Expected thread to be interrupted");
} catch (InterruptedIOException expected) {
}
responseBody.close();
}
示例5: connect
import java.io.InterruptedIOException; //导入依赖的package包/类
@Override public void connect() throws IOException {
if (executed) return;
Call call = buildCall();
executed = true;
call.enqueue(this);
synchronized (lock) {
try {
while (connectPending && response == null && callFailure == null) {
lock.wait(); // Wait 'til the network interceptor is reached or the call fails.
}
if (callFailure != null) {
throw propagate(callFailure);
}
} catch (InterruptedException e) {
throw new InterruptedIOException();
}
}
}
示例6: onError
import java.io.InterruptedIOException; //导入依赖的package包/类
@Override
public void onError(Throwable e) {
LogUtils.e("Retrofit", e.getMessage());
dismissProgress();
if (e instanceof HttpException) { // HTTP错误
onException(ExceptionReason.BAD_NETWORK);
} else if (e instanceof ConnectException
|| e instanceof UnknownHostException) { // 连接错误
onException(CONNECT_ERROR);
} else if (e instanceof InterruptedIOException) { // 连接超时
onException(CONNECT_TIMEOUT);
} else if (e instanceof JsonParseException
|| e instanceof JSONException
|| e instanceof ParseException) { // 解析错误
onException(PARSE_ERROR);
} else {
onException(UNKNOWN_ERROR);
}
}
示例7: awaitReadable
import java.io.InterruptedIOException; //导入依赖的package包/类
@Override
public void awaitReadable(long l, TimeUnit timeUnit) throws IOException {
if(Thread.currentThread() == getIoThread()) {
throw UndertowMessages.MESSAGES.awaitCalledFromIoThread();
}
if (data == null) {
synchronized (lock) {
if (data == null) {
try {
waiters++;
lock.wait(timeUnit.toMillis(l));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new InterruptedIOException();
} finally {
waiters--;
}
}
}
}
}
示例8: testInterruptedWaitForProxy
import java.io.InterruptedIOException; //导入依赖的package包/类
/**
* This test sets off a blocking thread and then interrupts it, before
* checking that the thread was interrupted
*
* @throws Throwable any exception other than that which was expected
*/
@Test(timeout = 10000)
public void testInterruptedWaitForProxy() throws Throwable {
RpcThread worker = new RpcThread(100);
worker.start();
Thread.sleep(1000);
assertTrue("worker hasn't started", worker.waitStarted);
worker.interrupt();
worker.join();
Throwable caught = worker.getCaught();
assertNotNull("No exception was raised", caught);
// looking for the root cause here, which can be wrapped
// as part of the NetUtils work. Having this test look
// a the type of exception there would be brittle to improvements
// in exception diagnostics.
Throwable cause = caught.getCause();
if (cause == null) {
// no inner cause, use outer exception as root cause.
cause = caught;
}
if (!(cause instanceof InterruptedIOException)
&& !(cause instanceof ClosedByInterruptException)) {
throw caught;
}
}
示例9: createDir
import java.io.InterruptedIOException; //导入依赖的package包/类
/**
* Creates a directory. Assumes the user has already checked for this directory existence.
*
* @param dir
* @return the result of fs.mkdirs(). In case underlying fs throws an IOException, it checks
* whether the directory exists or not, and returns true if it exists.
* @throws IOException
*/
boolean createDir(Path dir) throws IOException {
int i = 0;
IOException lastIOE = null;
do {
try {
return fs.mkdirs(dir);
} catch (IOException ioe) {
lastIOE = ioe;
if (fs.exists(dir)) return true; // directory is present
try {
sleepBeforeRetry("Create Directory", i + 1);
} catch (InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
}
} while (++i <= hdfsClientRetriesNumber);
throw new IOException("Exception in createDir", lastIOE);
}
示例10: getWriteEntry
import java.io.InterruptedIOException; //导入依赖的package包/类
/**
* Will block until a write entry has been assigned by they WAL subsystem.
* @return A WriteEntry gotten from local WAL subsystem. Must be completed by calling
* mvcc#complete or mvcc#completeAndWait.
* @throws InterruptedIOException
* @see
* #setWriteEntry(org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl.WriteEntry)
*/
@InterfaceAudience.Private // For internal use only.
public MultiVersionConcurrencyControl.WriteEntry getWriteEntry() throws InterruptedIOException {
try {
this.seqNumAssignedLatch.await();
} catch (InterruptedException ie) {
// If interrupted... clear out our entry else we can block up mvcc.
MultiVersionConcurrencyControl mvcc = getMvcc();
LOG.debug("mvcc=" + mvcc + ", writeEntry=" + this.writeEntry);
if (mvcc != null) {
if (this.writeEntry != null) {
mvcc.complete(this.writeEntry);
}
}
InterruptedIOException iie = new InterruptedIOException();
iie.initCause(ie);
throw iie;
}
return this.writeEntry;
}
示例11: event
import java.io.InterruptedIOException; //导入依赖的package包/类
/**
* Process pipelined HTTP requests using the specified input and output
* streams.
*
* @throws IOException error during an I/O operation
*/
@Override
public SocketState event(SocketStatus status)
throws IOException {
RequestInfo rp = request.getRequestProcessor();
try {
rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE);
if (!getAdapter().event(request, response, status)) {
setErrorState(ErrorState.CLOSE_NOW, null);
}
} catch (InterruptedIOException e) {
setErrorState(ErrorState.CLOSE_NOW, e);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
// 500 - Internal Server Error
response.setStatus(500);
setErrorState(ErrorState.CLOSE_NOW, t);
getAdapter().log(request, response, 0);
log.error(sm.getString("http11processor.request.process"), t);
}
rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);
if (getErrorState().isError() || status==SocketStatus.STOP) {
return SocketState.CLOSED;
} else if (!comet) {
inputBuffer.nextRequest();
outputBuffer.nextRequest();
return SocketState.OPEN;
} else {
return SocketState.LONG;
}
}
示例12: displayError
import java.io.InterruptedIOException; //导入依赖的package包/类
/**
* Display an exception prefaced with the command name. Also increments
* the error count for the command which will result in a non-zero exit
* code.
* @param e exception to display
*/
public void displayError(Exception e) {
// build up a list of exceptions that occurred
exceptions.add(e);
// use runtime so it rips up through the stack and exits out
if (e instanceof InterruptedIOException) {
throw new CommandInterruptException();
}
String errorMessage = e.getLocalizedMessage();
if (errorMessage == null) {
// this is an unexpected condition, so dump the whole exception since
// it's probably a nasty internal error where the backtrace would be
// useful
errorMessage = StringUtils.stringifyException(e);
LOG.debug(errorMessage);
} else {
errorMessage = errorMessage.split("\n", 2)[0];
}
displayError(errorMessage);
}
示例13: testInterruptedRename
import java.io.InterruptedIOException; //导入依赖的package包/类
@Test
public void testInterruptedRename() throws Exception {
FSDataOutputStream out = mock(FSDataOutputStream.class);
whenFsCreate().thenReturn(out);
when(mockFs.getFileStatus(eq(tmpPath))).thenReturn(fileStat);
when(mockFs.rename(eq(tmpPath), eq(path))).thenThrow(
new InterruptedIOException());
FSInputStream in = mock(FSInputStream.class);
when(in.read(any(byte[].class), anyInt(), anyInt())).thenReturn(-1);
tryCopyStream(in, false);
verify(mockFs).delete(eq(tmpPath), anyBoolean());
verify(mockFs).rename(eq(tmpPath), eq(path));
verify(mockFs, never()).delete(eq(path), anyBoolean());
verify(mockFs, never()).close();
}
示例14: waitTableDisabled
import java.io.InterruptedIOException; //导入依赖的package包/类
private void waitTableDisabled(final long deadlineTs)
throws IOException, TimeoutException {
waitForState(deadlineTs, new WaitForStateCallable() {
@Override
public boolean checkState(int tries) throws IOException {
return getAdmin().isTableDisabled(tableName);
}
@Override
public void throwInterruptedException() throws InterruptedIOException {
throw new InterruptedIOException("Interrupted when waiting for table to be disabled");
}
@Override
public void throwTimeoutException(long elapsedTime) throws TimeoutException {
throw new TimeoutException("Table " + tableName + " not yet disabled after " +
elapsedTime + "msec");
}
});
}
示例15: waitUntilReadable
import java.io.InterruptedIOException; //导入依赖的package包/类
/**
* Returns once the input stream is either readable or finished. Throws
* a {@link SocketTimeoutException} if the read timeout elapses before
* that happens.
*/
private void waitUntilReadable() throws IOException {
long start = 0;
long remaining = 0;
if (readTimeoutMillis != 0) {
start = (System.nanoTime() / 1000000);
remaining = readTimeoutMillis;
}
try {
while (pos == -1 && !finished && !closed && errorCode == null) {
if (readTimeoutMillis == 0) {
SpdyStream.this.wait();
} else if (remaining > 0) {
SpdyStream.this.wait(remaining);
remaining = start + readTimeoutMillis - (System.nanoTime() / 1000000);
} else {
throw new SocketTimeoutException();
}
}
} catch (InterruptedException e) {
throw new InterruptedIOException();
}
}