edu.sdsc.sirius.io
Class FileTransfer

java.lang.Object
  extended byedu.sdsc.sirius.io.FileTransfer

public class FileTransfer
extends java.lang.Object

copy or download a file.

Author:
copyright (c) 1999 Roedy Green of Canadian Mind Products may be copied and used freely for any purpose but military. Roedy Green Canadian Mind Products 5317 Barker Avenue Burnaby, BC Canada V5H 2N6 tel: (604) 435-3052 mailto:roedy@mindprod.com http://mindprod.com version 1.0 1999 Sept 5 - implement upload and copy. - use of readBlocking to replace readFully and read. Futures: file upload??

Constructor Summary
FileTransfer()
          constructor
FileTransfer(int buffSize)
          constructor
 
Method Summary
 boolean copy(java.io.File source, java.io.File target)
          Copy a file.
 boolean copy(java.io.InputStream source, java.io.OutputStream target)
          Copy an InputStream to an OutputStream, until EOF.
 boolean copy(java.io.InputStream source, java.io.OutputStream target, long length)
          Copy an InputStream to an OutputStream.
 boolean download(java.net.URL source, java.io.File target)
          Copy a file from a remote URL to a local file on hard disk.
static void main(java.lang.String[] args)
          Test driver
 int readBlocking(java.io.InputStream in, byte[] b, int off, int len)
          Reads exactly len bytes from the input stream into the byte array.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileTransfer

public FileTransfer(int buffSize)
constructor

Parameters:
buffSize - how big the i/o chunks are to copy files.

FileTransfer

public FileTransfer()
constructor

Method Detail

copy

public boolean copy(java.io.File source,
                    java.io.File target)
Copy a file.

Parameters:
source - file to copy on local hard disk.
target - new file to be created on local hard disk.
Returns:
true if the copy was successful.

download

public boolean download(java.net.URL source,
                        java.io.File target)
Copy a file from a remote URL to a local file on hard disk.

Parameters:
source - remote URL to copy. e.g. new URL("http://www.billabong.com:80/songs/lyrics.txt")
target - new file to be created on local hard disk.
Returns:
true if the copy was successful.

copy

public boolean copy(java.io.InputStream source,
                    java.io.OutputStream target,
                    long length)
Copy an InputStream to an OutputStream.

Parameters:
source - InputStream, left open.
target - OutputStream, left open.
length - how many bytes to copy.
Returns:
true if the copy was successful.

copy

public boolean copy(java.io.InputStream source,
                    java.io.OutputStream target)
Copy an InputStream to an OutputStream, until EOF. Use only when you don't know the length.

Parameters:
source - InputStream, left open.
target - OutputStream, left open.
Returns:
true if the copy was successful.

readBlocking

public final int readBlocking(java.io.InputStream in,
                              byte[] b,
                              int off,
                              int len)
                       throws java.io.IOException
Reads exactly len bytes from the input stream into the byte array. This method reads repeatedly from the underlying stream until all the bytes are read. InputStream.read is often documented to block like this, but in actuality it does not always do so, and returns early with just a few bytes. readBlockiyng blocks until all the bytes are read, the end of the stream is detected, or an exception is thrown. You will always get as many bytes as you asked for unless you get an eof or other exception. Unlike readFully, you find out how many bytes you did get.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the number of bytes to read.
Returns:
number of bytes actually read.
Throws:
java.io.IOException - if an I/O error occurs.

main

public static void main(java.lang.String[] args)
Test driver