Class CopyStream


  • public class CopyStream
    extends java.lang.Object

    A class for copying an entire input stream to an output stream.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copy​(int readBufferSize, java.io.InputStream in, java.io.OutputStream out)
      Copy an entire input stream to an output stream.
      static void copy​(int readBufferSize, java.io.InputStream in, java.io.OutputStream out, long count)
      Copy the specified number of bytes from the current position of the input stream to an output stream.
      static void copy​(java.io.File inFile, java.io.File outFile)
      Copy an entire input file to an output file.
      static void copy​(java.io.File inFile, java.io.File outFile, int readBufferSize, int bufferedInputStreamSizeForFileCopy, int bufferedOutputStreamSizeForFileCopy)
      Copy an entire input file to an output file.
      static void copy​(java.io.File inFile, java.io.File outFile, int readBufferSize, int bufferedInputStreamSizeForFileCopy, int bufferedOutputStreamSizeForFileCopy, int debugLevel)
      Copy an entire input file to an output file.
      static void copy​(java.io.InputStream in, java.io.OutputStream out)
      Copy an entire input stream to an output stream.
      static void copy​(java.io.InputStream in, java.io.OutputStream out, long count)
      Copy the specified number of bytes from the current position of the input stream to an output stream.
      static void copy​(java.lang.String inFile, java.lang.String outFile)
      Copy an entire input file to an output file.
      static void copy​(java.lang.String inFile, java.lang.String outFile, int readBufferSize, int bufferedInputStreamSizeForFileCopy, int bufferedOutputStreamSizeForFileCopy)
      Copy an entire input file to an output file.
      static void copy​(java.lang.String inFile, java.lang.String outFile, int readBufferSize, int bufferedInputStreamSizeForFileCopy, int bufferedOutputStreamSizeForFileCopy, int debugLevel)
      Copy an entire input file to an output file.
      static void copyByteSwapped​(int readBufferSize, java.io.InputStream in, java.io.OutputStream out, long count)
      Copy the specified even number of bytes from the current position of the input stream to an output stream, swapping adjacent pairs of bytes.
      static void copyByteSwapped​(java.io.InputStream in, java.io.OutputStream out, long count)
      Copy the specified even number of bytes from the current position of the input stream to an output stream, swapping adjacent pairs of bytes.
      static void main​(java.lang.String[] arg)
      Copy one file to another.
      static void skipInsistently​(java.io.InputStream in, long length)
      Skip as many bytes as requested, unless an exception occurs.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • skipInsistently

        public static void skipInsistently​(java.io.InputStream in,
                                           long length)
                                    throws java.io.IOException

        Skip as many bytes as requested, unless an exception occurs.

        Parameters:
        in - the input stream in which to skip the bytes
        length - number of bytes to read (no more and no less)
        Throws:
        java.io.IOException
      • copyByteSwapped

        public static final void copyByteSwapped​(int readBufferSize,
                                                 java.io.InputStream in,
                                                 java.io.OutputStream out,
                                                 long count)
                                          throws java.io.IOException

        Copy the specified even number of bytes from the current position of the input stream to an output stream, swapping adjacent pairs of bytes.

        The data is copied in chunks rather than as individual bytes, but the input and output streams are used as is, and no BufferedInputStream or BufferedOutputStream is inserted; the caller is expected to do that if maximum performance is desired.

        Also, neither the input nor the output streams are explicitly closed after the copying has complete; the caller is expected to do that as well, since there may be occasions when there is more to be written to the output, or the input is to be rewound and reused, or whatever.

        Parameters:
        readBufferSize - how much data to read in each request
        in - the source
        out - the destination
        count - the number of bytes to copy
        Throws:
        java.io.IOException - thrown if the copying fails for any reason
      • copyByteSwapped

        public static final void copyByteSwapped​(java.io.InputStream in,
                                                 java.io.OutputStream out,
                                                 long count)
                                          throws java.io.IOException

        Copy the specified even number of bytes from the current position of the input stream to an output stream, swapping adjacent pairs of bytes.

        The data is copied in chunks rather than as individual bytes, but the input and output streams are used as is, and no BufferedInputStream or BufferedOutputStream is inserted; the caller is expected to do that if maximum performance is desired.

        Also, neither the input nor the output streams are explicitly closed after the copying has complete; the caller is expected to do that as well, since there may be occasions when there is more to be written to the output, or the input is to be rewound and reused, or whatever.

        Parameters:
        in - the source
        out - the destination
        count - the number of bytes to copy
        Throws:
        java.io.IOException - thrown if the copying fails for any reason
      • copy

        public static final void copy​(int readBufferSize,
                                      java.io.InputStream in,
                                      java.io.OutputStream out,
                                      long count)
                               throws java.io.IOException

        Copy the specified number of bytes from the current position of the input stream to an output stream.

        The data is copied in chunks rather than as individual bytes, but the input and output streams are used as is, and no BufferedInputStream or BufferedOutputStream is inserted; the caller is expected to do that if maximum performance is desired.

        Also, neither the input nor the output streams are explicitly closed after the copying has complete; the caller is expected to do that as well, since there may be occasions when there is more to be written to the output, or the input is to be rewound and reused, or whatever.

        Parameters:
        in - the source
        out - the destination
        count - the number of bytes to copy
        readBufferSize - how much data to read in each request
        Throws:
        java.io.IOException - thrown if the copying fails for any reason
      • copy

        public static final void copy​(java.io.InputStream in,
                                      java.io.OutputStream out,
                                      long count)
                               throws java.io.IOException

        Copy the specified number of bytes from the current position of the input stream to an output stream.

        The data is copied in chunks rather than as individual bytes, but the input and output streams are used as is, and no BufferedInputStream or BufferedOutputStream is inserted; the caller is expected to do that if maximum performance is desired.

        Also, neither the input nor the output streams are explicitly closed after the copying has complete; the caller is expected to do that as well, since there may be occasions when there is more to be written to the output, or the input is to be rewound and reused, or whatever.

        Parameters:
        in - the source
        out - the destination
        count - the number of bytes to copy
        Throws:
        java.io.IOException - thrown if the copying fails for any reason
      • copy

        public static final void copy​(int readBufferSize,
                                      java.io.InputStream in,
                                      java.io.OutputStream out)
                               throws java.io.IOException

        Copy an entire input stream to an output stream.

        The data is copied in chunks rather than as individual bytes, but the input and output streams are used as is, and no BufferedInputStream or BufferedOutputStream is inserted; the caller is expected to do that if maximum performance is desired.

        Also, neither the input nor the output streams are explicitly closed after the copying has complete; the caller is expected to do that as well, since there may be occasions when there is more to be written to the output, or the input is to be rewound and reused, or whatever.

        Parameters:
        readBufferSize - how much data to read in each request
        in - the source
        out - the destination
        Throws:
        java.io.IOException - thrown if the copying fails for any reason
      • copy

        public static final void copy​(java.io.InputStream in,
                                      java.io.OutputStream out)
                               throws java.io.IOException

        Copy an entire input stream to an output stream.

        The data is copied in chunks rather than as individual bytes, but the input and output streams are used as is, and no BufferedInputStream or BufferedOutputStream is inserted; the caller is expected to do that if maximum performance is desired.

        Also, neither the input nor the output streams are explicitly closed after the copying has complete; the caller is expected to do that as well, since there may be occasions when there is more to be written to the output, or the input is to be rewound and reused, or whatever.

        Parameters:
        in - the source
        out - the destination
        Throws:
        java.io.IOException - thrown if the copying fails for any reason
      • copy

        public static final void copy​(java.io.File inFile,
                                      java.io.File outFile,
                                      int readBufferSize,
                                      int bufferedInputStreamSizeForFileCopy,
                                      int bufferedOutputStreamSizeForFileCopy,
                                      int debugLevel)
                               throws java.io.IOException

        Copy an entire input file to an output file.

        Parameters:
        inFile - the source
        outFile - the destination
        readBufferSize - how much data to read in each request
        bufferedInputStreamSizeForFileCopy - the buffered input stream size (or zero if unbuffered)
        bufferedOutputStreamSizeForFileCopy - and the buffered output stream size (or zero if unbuffered)
        debugLevel - ignored
        Throws:
        java.io.IOException - thrown if the copying fails for any reason
      • copy

        public static final void copy​(java.io.File inFile,
                                      java.io.File outFile,
                                      int readBufferSize,
                                      int bufferedInputStreamSizeForFileCopy,
                                      int bufferedOutputStreamSizeForFileCopy)
                               throws java.io.IOException

        Copy an entire input file to an output file.

        Parameters:
        inFile - the source
        outFile - the destination
        readBufferSize - how much data to read in each request
        bufferedInputStreamSizeForFileCopy - the buffered input stream size (or zero if unbuffered)
        bufferedOutputStreamSizeForFileCopy - and the buffered output stream size (or zero if unbuffered)
        Throws:
        java.io.IOException - thrown if the copying fails for any reason
      • copy

        public static final void copy​(java.lang.String inFile,
                                      java.lang.String outFile,
                                      int readBufferSize,
                                      int bufferedInputStreamSizeForFileCopy,
                                      int bufferedOutputStreamSizeForFileCopy,
                                      int debugLevel)
                               throws java.io.IOException

        Copy an entire input file to an output file.

        Parameters:
        inFile - the source
        outFile - the destination
        readBufferSize - how much data to read in each request
        bufferedInputStreamSizeForFileCopy - the buffered input stream size (or zero if unbuffered)
        bufferedOutputStreamSizeForFileCopy - and the buffered output stream size (or zero if unbuffered)
        debugLevel - ignored
        Throws:
        java.io.IOException - thrown if the copying fails for any reason
      • copy

        public static final void copy​(java.lang.String inFile,
                                      java.lang.String outFile,
                                      int readBufferSize,
                                      int bufferedInputStreamSizeForFileCopy,
                                      int bufferedOutputStreamSizeForFileCopy)
                               throws java.io.IOException

        Copy an entire input file to an output file.

        Parameters:
        inFile - the source
        outFile - the destination
        readBufferSize - how much data to read in each request
        bufferedInputStreamSizeForFileCopy - the buffered input stream size (or zero if unbuffered)
        bufferedOutputStreamSizeForFileCopy - and the buffered output stream size (or zero if unbuffered)
        Throws:
        java.io.IOException - thrown if the copying fails for any reason
      • copy

        public static final void copy​(java.io.File inFile,
                                      java.io.File outFile)
                               throws java.io.IOException

        Copy an entire input file to an output file.

        Parameters:
        inFile - the source
        outFile - the destination
        Throws:
        java.io.IOException - thrown if the copying fails for any reason
      • copy

        public static final void copy​(java.lang.String inFile,
                                      java.lang.String outFile)
                               throws java.io.IOException

        Copy an entire input file to an output file.

        Parameters:
        inFile - the source
        outFile - the destination
        Throws:
        java.io.IOException - thrown if the copying fails for any reason
      • main

        public static void main​(java.lang.String[] arg)

        Copy one file to another.

        Parameters:
        arg - array of two or five strings - input file, output file, optionally the copy buffer size, the buffered input stream size (or zero if unbuffered), and the buffered output stream size (or zero if unbuffered),