Java Code Examples for java.io.InterruptedIOException#getMessage()

The following examples show how to use java.io.InterruptedIOException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalAudioTrackExecutor.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
private InterruptedException findInterrupt(Throwable throwable) {
  InterruptedException exception = findDeepException(throwable, InterruptedException.class);

  if (exception == null) {
    InterruptedIOException ioException = findDeepException(throwable, InterruptedIOException.class);

    if (ioException != null && (ioException.getMessage() == null || !ioException.getMessage().contains("timed out"))) {
      exception = new InterruptedException(ioException.getMessage());
    }
  }

  if (exception == null && Thread.interrupted()) {
    return new InterruptedException();
  }

  return exception;
}
 
Example 2
Source File: ObsoleteUrlFactory.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
void initOutputStream(final BufferedSink sink, final long expectedContentLength) {
    this.timeout = sink.timeout();
    this.expectedContentLength = expectedContentLength;

    // An output stream that writes to sink. If expectedContentLength is not -1, then this expects
    // exactly that many bytes to be written.
    this.outputStream = new OutputStream() {
        private long bytesReceived;

        @Override
        public void write(int b) throws IOException {
            write(new byte[]{(byte) b}, 0, 1);
        }

        @Override
        public void write(byte[] source, int offset, int byteCount) throws IOException {
            if (closed) throw new IOException("closed"); // Not IllegalStateException!

            if (expectedContentLength != -1L && bytesReceived + byteCount > expectedContentLength) {
                throw new ProtocolException("expected " + expectedContentLength
                        + " bytes but received " + bytesReceived + byteCount);
            }

            bytesReceived += byteCount;
            try {
                sink.write(source, offset, byteCount);
            } catch (InterruptedIOException e) {
                throw new SocketTimeoutException(e.getMessage());
            }
        }

        @Override
        public void flush() throws IOException {
            if (closed) return; // Weird, but consistent with historical behavior.
            sink.flush();
        }

        @Override
        public void close() throws IOException {
            closed = true;

            if (expectedContentLength != -1L && bytesReceived < expectedContentLength) {
                throw new ProtocolException("expected " + expectedContentLength
                        + " bytes but received " + bytesReceived);
            }

            sink.close();
        }
    };
}
 
Example 3
Source File: ObsoleteUrlFactory.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
void initOutputStream(final BufferedSink sink, final long expectedContentLength) {
    this.timeout = sink.timeout();
    this.expectedContentLength = expectedContentLength;

    // An output stream that writes to sink. If expectedContentLength is not -1, then this expects
    // exactly that many bytes to be written.
    this.outputStream = new OutputStream() {
        private long bytesReceived;

        @Override
        public void write(int b) throws IOException {
            write(new byte[]{(byte) b}, 0, 1);
        }

        @Override
        public void write(byte[] source, int offset, int byteCount) throws IOException {
            if (closed) throw new IOException("closed"); // Not IllegalStateException!

            if (expectedContentLength != -1L && bytesReceived + byteCount > expectedContentLength) {
                throw new ProtocolException("expected " + expectedContentLength
                        + " bytes but received " + bytesReceived + byteCount);
            }

            bytesReceived += byteCount;
            try {
                sink.write(source, offset, byteCount);
            } catch (InterruptedIOException e) {
                throw new SocketTimeoutException(e.getMessage());
            }
        }

        @Override
        public void flush() throws IOException {
            if (closed) return; // Weird, but consistent with historical behavior.
            sink.flush();
        }

        @Override
        public void close() throws IOException {
            closed = true;

            if (expectedContentLength != -1L && bytesReceived < expectedContentLength) {
                throw new ProtocolException("expected " + expectedContentLength
                        + " bytes but received " + bytesReceived);
            }

            sink.close();
        }
    };
}