Example usage for org.apache.commons.net.io Util copyStream

List of usage examples for org.apache.commons.net.io Util copyStream

Introduction

In this page you can find the example usage for org.apache.commons.net.io Util copyStream.

Prototype

public static final long copyStream(InputStream source, OutputStream dest) throws CopyStreamException 

Source Link

Document

Same as copyStream(source, dest, DEFAULT_COPY_BUFFER_SIZE);

Usage

From source file:examples.IOUtil.java

public static final void readWrite(final InputStream remoteInput, final OutputStream remoteOutput,
        final InputStream localInput, final OutputStream localOutput) {
    Thread reader, writer;/*from   w w w. jav a  2  s  . c o m*/

    reader = new Thread() {
        public void run() {
            int ch;

            try {
                while (!interrupted() && (ch = localInput.read()) != -1) {
                    remoteOutput.write(ch);
                    remoteOutput.flush();
                }
            } catch (IOException e) {
                //e.printStackTrace();
            }
        }
    };

    writer = new Thread() {
        public void run() {
            try {
                Util.copyStream(remoteInput, localOutput);
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    };

    writer.setPriority(Thread.currentThread().getPriority() + 1);

    writer.start();
    reader.setDaemon(true);
    reader.start();

    try {
        writer.join();
        reader.interrupt();
    } catch (InterruptedException e) {
    }
}

From source file:com.hkd.socketclient.IOUtil.java

public static final void readWrite(final InputStream remoteInput, final OutputStream remoteOutput,
        final InputStream localInput, final OutputStream localOutput) {
    Thread reader, writer;/*from   w w w . j  a v a  2  s .  c om*/

    reader = new Thread() {
        @Override
        public void run() {
            int ch;

            try {
                while (!interrupted() && (ch = localInput.read()) != -1) {
                    remoteOutput.write(ch);
                    remoteOutput.flush();
                }
            } catch (IOException e) {
                //e.printStackTrace();
            }
        }
    };

    writer = new Thread() {
        @Override
        public void run() {
            try {
                Util.copyStream(remoteInput, localOutput);
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    };

    writer.setPriority(Thread.currentThread().getPriority() + 1);

    writer.start();
    reader.setDaemon(true);
    reader.start();

    try {
        writer.join();
        reader.interrupt();
    } catch (InterruptedException e) {
    }
}

From source file:org.apache.commons.net.examples.util.IOUtil.java

public static final void readWrite(final InputStream remoteInput, final OutputStream remoteOutput,
        final InputStream localInput, final OutputStream localOutput) {
    Thread reader, writer;// w ww  .  ja  v a  2 s  .co  m

    reader = new Thread() {
        @Override
        public void run() {
            int ch;

            try {
                while (!interrupted() && (ch = localInput.read()) != -1) {
                    remoteOutput.write(ch);
                    remoteOutput.flush();
                }
            } catch (IOException e) {
                //e.printStackTrace();
            }
        }
    };

    writer = new Thread() {
        @Override
        public void run() {
            try {
                Util.copyStream(remoteInput, localOutput);
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    };

    writer.setPriority(Thread.currentThread().getPriority() + 1);

    writer.start();
    reader.setDaemon(true);
    reader.start();

    try {
        writer.join();
        reader.interrupt();
    } catch (InterruptedException e) {
        // Ignored
    }
}

From source file:rnaedit.test.IOUtil.java

public static final void readWrite(final InputStream remoteInput,

        final OutputStream remoteOutput,

        final InputStream localInput,

        final OutputStream localOutput)

{

    Thread reader, writer;/*from  ww  w.  j a v  a 2 s . c o  m*/

    reader = new Thread()

    {

        public void run()

        {

            int ch;

            try

            {

                while (!interrupted() && (ch = localInput.read()) != -1)

                {

                    remoteOutput.write(ch);

                    remoteOutput.flush();

                }

            }

            catch (IOException e)

            {

                //e.printStackTrace();

            }

        }

    }

    ;

    writer = new Thread()

    {

        public void run()

        {

            try

            {

                Util.copyStream(remoteInput, localOutput);

            }

            catch (IOException e)

            {

                e.printStackTrace();

                System.exit(1);

            }

        }

    };

    writer.setPriority(Thread.currentThread().getPriority() + 1);

    writer.start();

    reader.setDaemon(true);

    reader.start();

    try

    {

        writer.join();

        reader.interrupt();

    }

    catch (InterruptedException e)

    {

    }

}