Example usage for java.io InterruptedIOException InterruptedIOException

List of usage examples for java.io InterruptedIOException InterruptedIOException

Introduction

In this page you can find the example usage for java.io InterruptedIOException InterruptedIOException.

Prototype

public InterruptedIOException(String s) 

Source Link

Document

Constructs an InterruptedIOException with the specified detail message.

Usage

From source file:com.dongfang.net.http.client.entity.DecompressingEntity.java

/**
 * {@inheritDoc}/* w w w.  j a v a 2  s . co  m*/
 */
@Override
public void writeTo(OutputStream outStream) throws IOException {
    if (outStream == null) {
        throw new IllegalArgumentException("Output stream may not be null");
    }
    InputStream inStream = null;
    try {
        inStream = getContent();

        byte[] tmp = new byte[4096];
        int len;
        while ((len = inStream.read(tmp)) != -1) {
            outStream.write(tmp, 0, len);
            uploadedSize += len;
            if (callBackHandler != null) {
                if (!callBackHandler.updateProgress(uncompressedLength, uploadedSize, false)) {
                    throw new InterruptedIOException("stop");
                }
            }
        }
        outStream.flush();
        if (callBackHandler != null) {
            callBackHandler.updateProgress(uncompressedLength, uploadedSize, true);
        }
    } finally {
        IOUtils.closeQuietly(inStream);
    }
}

From source file:com.creditease.utilframe.http.client.entity.DecompressingEntity.java

/**
 * {@inheritDoc}/*  w w w. ja  v a 2 s  .  c o m*/
 */
@SuppressWarnings("resource")
@Override
public void writeTo(OutputStream outStream) throws IOException {
    if (outStream == null) {
        throw new IllegalArgumentException("Output stream may not be null");
    }
    InputStream inStream = null;
    try {
        inStream = getContent();

        byte[] tmp = new byte[4096];
        int len;
        while ((len = inStream.read(tmp)) != -1) {
            outStream.write(tmp, 0, len);
            uploadedSize += len;
            if (callBackHandler != null) {
                if (!callBackHandler.updateProgress(uncompressedLength, uploadedSize, false)) {
                    IOUtils.closeQuietly(inStream);
                    throw new InterruptedIOException("cancel");
                }
            }
        }
        outStream.flush();
        if (callBackHandler != null) {
            callBackHandler.updateProgress(uncompressedLength, uploadedSize, true);
        }
    } finally {
        IOUtils.closeQuietly(inStream);
    }
}

From source file:org.apache.hadoop.hbase.backup.util.BackupServerUtil.java

public static void waitForSnapshot(SnapshotDescription snapshot, long max, SnapshotManager snapshotMgr,
        Configuration conf) throws IOException {
    boolean done = false;
    long start = EnvironmentEdgeManager.currentTime();
    int numRetries = conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
            HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
    long maxPauseTime = max / numRetries;
    int tries = 0;
    LOG.debug(//from w w w . j  a  v a  2s. c om
            "Waiting a max of " + max + " ms for snapshot '" + ClientSnapshotDescriptionUtils.toString(snapshot)
                    + "'' to complete. (max " + maxPauseTime + " ms per retry)");
    while (tries == 0 || ((EnvironmentEdgeManager.currentTime() - start) < max && !done)) {
        try {
            // sleep a backoff <= pauseTime amount
            long pause = conf.getLong(HConstants.HBASE_CLIENT_PAUSE, HConstants.DEFAULT_HBASE_CLIENT_PAUSE);
            long sleep = HBaseAdmin.getPauseTime(tries++, pause);
            sleep = sleep > maxPauseTime ? maxPauseTime : sleep;
            LOG.debug("(#" + tries + ") Sleeping: " + sleep + "ms while waiting for snapshot completion.");
            Thread.sleep(sleep);
        } catch (InterruptedException e) {
            throw (InterruptedIOException) new InterruptedIOException("Interrupted").initCause(e);
        }
        LOG.debug("Getting current status of snapshot ...");
        done = snapshotMgr.isSnapshotDone(snapshot);
    }
    if (!done) {
        throw new SnapshotCreationException(
                "Snapshot '" + snapshot.getName() + "' wasn't completed in expectedTime:" + max + " ms",
                snapshot);
    }
}

From source file:org.apache.ambari.servicemonitor.utils.FindAndPingPid.java

/**
 * Signal the pid, block for completion//from w w w .j  a  v  a 2 s .c  om
 * @param pid process to signal
 * @param signal signal to raise
 * @return the return code
 * @throws IOException any IO problem.
 * @throws InterruptedIOException if the thread was interrupted during execution.
 */
int signalPid(String pid, int signal) throws IOException {
    String[] cmds = new String[3];
    int c = 0;
    cmds[c++] = "kill";
    cmds[c++] = "-" + signal;
    cmds[c] = pid;

    Process process = Runtime.getRuntime().exec(cmds);
    try {
        return process.waitFor();
    } catch (InterruptedException e) {
        throw new InterruptedIOException("While signalling " + pid);
    }

}

From source file:com.izforge.izpack.installer.unpacker.FileUnpacker.java

/**
 * Copies an input stream to a target, setting its timestamp to that of the pack file.
 * <p/>/*  w  ww.  ja  v  a 2 s .  co  m*/
 * If the target is a blockable file, then a temporary file will be created, and the file queued.
 *
 * @param file   the pack file
 * @param in     the pack file stream
 * @param target the file to write to
 * @return the number of bytes actually copied
 * @throws InterruptedIOException if the copy operation is cancelled
 * @throws IOException            for any I/O error
 */
protected long copy(PackFile file, InputStream in, File target) throws IOException {
    OutputStream out = getTarget(file, target);
    byte[] buffer = new byte[5120];
    long bytesCopied = 0;
    long bytesToCopy = (file.isBackReference() ? file.getLinkedPackFile().length() : file.length());
    logger.fine("|- Copying to file system (size: " + bytesToCopy + " bytes)");
    try {
        while (bytesCopied < bytesToCopy) {
            if (cancellable.isCancelled()) {
                // operation cancelled
                throw new InterruptedIOException("Copy operation cancelled");
            }
            bytesCopied = copy(file, buffer, in, out, bytesCopied);
        }
    } finally {
        IOUtils.closeQuietly(out);
    }

    postCopy(file);

    return bytesCopied;
}

From source file:com.izforge.izpack.installer.web.LoggedInputStream.java

/**
 * Updates the download progress.// www.j a  v  a  2 s. c  o m
 *
 * @throws InterruptedIOException if the download has been cancelled
 */
private void update() throws IOException {
    long bytesRead = is.getByteCount();

    if (lastTime > 0) {
        long currTime = System.currentTimeMillis();
        long diff = currTime - lastTime;
        if (diff > 800) {
            double bps = (double) (bytesRead - lastBytes) / ((double) (diff) / 1000.);
            downloader.setStatusLabel(Pack.toByteUnitsString(Math.round(bps)) + "/s");
            lastTime = currTime;
            lastBytes = bytesRead;
        }
    } else {
        lastTime = System.currentTimeMillis();
        lastBytes = bytesRead;
    }
    downloader.setProgressCurrent((int) bytesRead);
    if (cancelled) {
        throw new InterruptedIOException("Cancelled");
    }
}

From source file:cn.xdf.thinkutils.http.client.multipart.content.StringBody.java

public void writeTo(final OutputStream out) throws IOException {
    if (out == null) {
        throw new IllegalArgumentException("Output stream may not be null");
    }//ww w.  j a v  a  2  s .  c om
    InputStream in = new ByteArrayInputStream(this.content);
    byte[] tmp = new byte[4096];
    int l;
    while ((l = in.read(tmp)) != -1) {
        out.write(tmp, 0, l);
        callBackInfo.pos += l;
        if (!callBackInfo.doCallBack(false)) {
            throw new InterruptedIOException("cancel");
        }
    }
    out.flush();
}

From source file:org.apache.hadoop.hbase.index.client.IndexAdmin.java

@Override
public void createTable(final HTableDescriptor desc, byte[][] splitKeys) throws IOException {
    try {// ww w  .ja v  a 2 s.co  m
        createTableAsync(desc, splitKeys);
    } catch (SocketTimeoutException ste) {
        LOG.warn("Creating " + desc.getNameAsString() + " took too long", ste);
    }
    int numRegs = splitKeys == null ? 1 : splitKeys.length + 1;
    int prevRegCount = 0;

    MetaScannerVisitorBaseWithTableName userTableVisitor = null;
    MetaScannerVisitorBaseWithTableName indexTableVisitor = null;
    boolean indexedHTD = desc.getValue(Constants.INDEX_SPEC_KEY) != null;

    for (int tries = 0; tries < this.numRetries * this.retryLongerMultiplier; ++tries) {

        AtomicInteger actualRegCount = null;
        // Wait for new table to come on-line
        if (userTableVisitor == null) {
            userTableVisitor = new MetaScannerVisitorBaseWithTableName(desc.getNameAsString());
        }
        actualRegCount = userTableVisitor.getActualRgnCnt();
        actualRegCount.set(0);
        MetaScanner.metaScan(getConfiguration(), getConnection(), userTableVisitor, desc.getTableName());
        if (actualRegCount.get() != numRegs) {
            if (tries == this.numRetries * this.retryLongerMultiplier - 1) {
                throw new RegionOfflineException("Only " + actualRegCount.get() + " of " + numRegs
                        + " regions are online; retries exhausted.");
            }
            try { // Sleep
                Thread.sleep(getPauseTime(tries));
            } catch (InterruptedException e) {
                throw new InterruptedIOException("Interrupted when opening" + " regions; "
                        + actualRegCount.get() + " of " + numRegs + " regions processed so far");
            }
            if (actualRegCount.get() > prevRegCount) { // Making progress
                prevRegCount = actualRegCount.get();
                tries = -1;
            }
        } else {
            if (indexedHTD) {
                TableName indexTableName = TableName.valueOf(IndexUtils.getIndexTableName(desc.getName()));
                if (indexTableVisitor == null) {
                    indexTableVisitor = new MetaScannerVisitorBaseWithTableName(
                            indexTableName.getNameAsString());
                }
                actualRegCount = indexTableVisitor.getActualRgnCnt();
                actualRegCount.set(0);
                MetaScanner.metaScan(getConfiguration(), getConnection(), indexTableVisitor, indexTableName);
                if (actualRegCount.get() != numRegs) {
                    if (tries == this.numRetries * this.retryLongerMultiplier - 1) {
                        throw new RegionOfflineException("Only " + actualRegCount.get() + " of " + numRegs
                                + " regions are online; retries exhausted.");
                    }
                    try { // Sleep
                        Thread.sleep(getPauseTime(tries));
                    } catch (InterruptedException e) {
                        throw new InterruptedIOException("Interrupted when opening" + " regions; "
                                + actualRegCount.get() + " of " + numRegs + " regions processed so far");
                    }
                    if (actualRegCount.get() > prevRegCount) { // Making progress
                        prevRegCount = actualRegCount.get();
                        tries = -1;
                    }
                } else if (isTableEnabled(indexTableName)) {
                    return;
                }
            } else if (isTableEnabled(desc.getName())) {
                return;
            }
        }
    }
    throw new TableNotEnabledException(
            "Retries exhausted while still waiting for table: " + desc.getNameAsString() + " to be enabled");
}

From source file:org.apache.http2.impl.conn.DefaultClientConnection.java

public void opening(Socket sock, HttpHost target) throws IOException {
    assertNotOpen();/*from w w  w.  j a  v  a  2  s  . c om*/
    this.socket = sock;
    this.targetHost = target;

    // Check for shutdown after assigning socket, so that
    if (this.shutdown) {
        sock.close(); // allow this to throw...
        // ...but if it doesn't, explicitly throw one ourselves.
        throw new InterruptedIOException("Connection already shutdown");
    }
}

From source file:org.apache.http.impl.conn.DefaultClientConnection.java

public void opening(final Socket sock, final HttpHost target) throws IOException {
    assertNotOpen();//from  www  .  j a  v  a2 s.com
    this.socket = sock;
    this.targetHost = target;

    // Check for shutdown after assigning socket, so that
    if (this.shutdown) {
        sock.close(); // allow this to throw...
        // ...but if it doesn't, explicitly throw one ourselves.
        throw new InterruptedIOException("Connection already shutdown");
    }
}