Class CopyStream

java.lang.Object
com.pixelmed.utils.CopyStream

public class CopyStream extends Object

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

  • Method Summary

    Modifier and Type
    Method
    Description
    static final void
    copy(int readBufferSize, InputStream in, OutputStream out)
    Copy an entire input stream to an output stream.
    static final void
    copy(int readBufferSize, InputStream in, OutputStream out, long count)
    Copy the specified number of bytes from the current position of the input stream to an output stream.
    static final void
    copy(File inFile, File outFile)
    Copy an entire input file to an output file.
    static final void
    copy(File inFile, File outFile, int readBufferSize, int bufferedInputStreamSizeForFileCopy, int bufferedOutputStreamSizeForFileCopy)
    Copy an entire input file to an output file.
    static final void
    Copy an entire input stream to an output stream.
    static final void
    copy(InputStream in, OutputStream out, long count)
    Copy the specified number of bytes from the current position of the input stream to an output stream.
    static final void
    copy(String inFile, String outFile)
    Copy an entire input file to an output file.
    static final void
    copy(String inFile, String outFile, int readBufferSize, int bufferedInputStreamSizeForFileCopy, int bufferedOutputStreamSizeForFileCopy)
    Copy an entire input file to an output file.
    static final void
    copyByteSwapped(int readBufferSize, InputStream in, 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 final void
    copyByteSwapped(InputStream in, 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(String[] arg)
    Copy one file to another.
    static void
    skipInsistently(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 Details

    • skipInsistently

      public static void skipInsistently(InputStream in, long length) throws 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:
      IOException
    • copyByteSwapped

      public static final void copyByteSwapped(int readBufferSize, InputStream in, OutputStream out, long count) throws 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:
      IOException - thrown if the copying fails for any reason
    • copyByteSwapped

      public static final void copyByteSwapped(InputStream in, OutputStream out, long count) throws 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:
      IOException - thrown if the copying fails for any reason
    • copy

      public static final void copy(int readBufferSize, InputStream in, OutputStream out, long count) throws 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:
      readBufferSize - how much data to read in each request
      in - the source
      out - the destination
      count - the number of bytes to copy
      Throws:
      IOException - thrown if the copying fails for any reason
    • copy

      public static final void copy(InputStream in, OutputStream out, long count) throws 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:
      IOException - thrown if the copying fails for any reason
    • copy

      public static final void copy(int readBufferSize, InputStream in, OutputStream out) throws 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:
      IOException - thrown if the copying fails for any reason
    • copy

      public static final void copy(InputStream in, OutputStream out) throws 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:
      IOException - thrown if the copying fails for any reason
    • copy

      public static final void copy(File inFile, File outFile, int readBufferSize, int bufferedInputStreamSizeForFileCopy, int bufferedOutputStreamSizeForFileCopy) throws 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:
      IOException - thrown if the copying fails for any reason
    • copy

      public static final void copy(String inFile, String outFile, int readBufferSize, int bufferedInputStreamSizeForFileCopy, int bufferedOutputStreamSizeForFileCopy) throws 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:
      IOException - thrown if the copying fails for any reason
    • copy

      public static final void copy(File inFile, File outFile) throws IOException

      Copy an entire input file to an output file.

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

      public static final void copy(String inFile, String outFile) throws IOException

      Copy an entire input file to an output file.

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

      public static void main(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),