Example usage for java.io PipedOutputStream close

List of usage examples for java.io PipedOutputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this piped output stream and releases any system resources associated with this stream.

Usage

From source file:org.waarp.openr66.context.task.ExecOutputTask.java

private void finalizeFromError(PipedOutputStream outputStream, PumpStreamHandler pumpStreamHandler,
        PipedInputStream inputStream, AllLineReader allLineReader, Thread thread, int status,
        CommandLine commandLine) {//from w  ww  . j av a  2s .  c  om
    try {
        Thread.sleep(Configuration.RETRYINMS);
    } catch (InterruptedException e) {
    }
    try {
        outputStream.flush();
    } catch (IOException e2) {
    }
    try {
        Thread.sleep(Configuration.RETRYINMS);
    } catch (InterruptedException e) {
    }
    try {
        outputStream.close();
    } catch (IOException e1) {
    }
    thread.interrupt();
    try {
        inputStream.close();
    } catch (IOException e1) {
    }
    try {
        Thread.sleep(Configuration.RETRYINMS);
    } catch (InterruptedException e) {
    }
    try {
        pumpStreamHandler.stop();
    } catch (IOException e2) {
    }
    try {
        Thread.sleep(Configuration.RETRYINMS);
    } catch (InterruptedException e) {
    }
    String result = allLineReader.getLastLine().toString();
    logger.error("Status: " + status + " Exec in error with " + commandLine + " returns " + result);
    OpenR66RunnerErrorException exc = new OpenR66RunnerErrorException(
            "<STATUS>" + status + "</STATUS><ERROR>" + result + "</ERROR>");
    futureCompletion.setFailure(exc);
}

From source file:org.whitesource.agent.utils.ZipUtils.java

private static void produceCompressDataFromStream(InputStream inputStream,
        PipedOutputStream pipedOutputStream) {
    try (BufferedInputStream in = new BufferedInputStream(inputStream)) {
        byte[] buffer = new byte[BYTES_BUFFER_SIZE];
        int len;/*from   w  w w.ja v  a2  s.  c om*/
        while ((len = in.read(buffer)) > 0) {
            pipedOutputStream.write(buffer, 0, len);
        }
        pipedOutputStream.close();
    } catch (IOException e) {
        // logger.error("Failed to produce data to compress : ", e);
    }
}

From source file:org.whitesource.agent.utils.ZipUtils.java

private static void produceCompressDataFromText(String text, PipedOutputStream pipedOutputStream) {
    int start_String = 0;
    int chunk = text.length();
    if (text.length() > STRING_MAX_SIZE) {
        chunk = text.length() / STRING_MAX_SIZE;
    }//from ww w . j  ava2s.c o m
    try {
        while (start_String < text.length()) {
            int end = start_String + chunk;
            if (end > text.length()) {
                end = text.length();
            }
            byte[] bytes = text.substring(start_String, end).getBytes(StandardCharsets.UTF_8);

            pipedOutputStream.write(bytes);
            start_String = end;
        }
        pipedOutputStream.close();
    } catch (IOException e) {
        // logger.error("Failed to produce data to compress : ", e);
    }
}

From source file:ubicrypt.core.Utils.java

public static InputStream readIs(final Path path) {
    final PipedInputStream pis = new PipedInputStream();
    final AtomicLong pos = new AtomicLong(0);
    try {//from  w  w  w . j a  va  2s.  c o  m
        final PipedOutputStream ostream = new PipedOutputStream(pis);
        final AsynchronousFileChannel channel = AsynchronousFileChannel.open(path, StandardOpenOption.READ);
        final ByteBuffer buffer = ByteBuffer.allocate(1 << 16);
        channel.read(buffer, pos.get(), buffer, new CompletionHandler<Integer, ByteBuffer>() {
            @Override
            public void completed(final Integer result, final ByteBuffer buf) {
                try {
                    if (result == -1) {
                        ostream.close();
                        return;
                    }
                    final byte[] bytes = new byte[result];
                    System.arraycopy(buf.array(), 0, bytes, 0, result);
                    ostream.write(bytes);
                    ostream.flush();
                    if (result < 1 << 16) {
                        ostream.close();
                        return;
                    }
                    pos.addAndGet(result);
                    final ByteBuffer buffer = ByteBuffer.allocate(1 << 16);
                    channel.read(buffer, pos.get(), buffer, this);
                } catch (final IOException e) {
                    Throwables.propagate(e);
                }
            }

            @Override
            public void failed(final Throwable exc, final ByteBuffer attachment) {
                log.error(exc.getMessage(), exc);
            }
        });
    } catch (final IOException e) {
        if (e instanceof NoSuchFileException) {
            throw new NotFoundException(path);
        }
        Throwables.propagate(e);
    }
    return pis;
}