com.mindprod.filetransfer
Class FileTransfer

java.lang.Object
  extended by com.mindprod.filetransfer.MiniFileTransfer
      extended by com.mindprod.filetransfer.FileTransfer
Direct Known Subclasses:
MaxiFileTransfer

public class FileTransfer
extends MiniFileTransfer

classes to copy, and download files.

To read or write from the client's local hard disk, you will need a signed Applet and security clearance. see Signed Applet in the Java glossary. To read a files from the server, the file must be given public read access, usually the default. To write a file to the server, you server will have to support CGI-PUT with public access. This is unusual to find. Normally you upload files with FTP. See FTP in the Java glossary. See also the simpler hunkio package.

Since:
1999
Version:
2.5 2008-08-10 - add setReadTimeout and setConnectTimeout methods.
Author:
Roedy Green, Canadian Mind Products

Field Summary
static java.lang.String EMBEDDED_COPYRIGHT
          undisplayed copyright notice
static java.lang.String VERSION_STRING
          embedded version string.
 
Constructor Summary
FileTransfer()
          constructor
FileTransfer(int buffSize)
          constructor
 
Method Summary
 boolean append(java.io.File source, java.io.File target)
          append a file onto the end of another.
 boolean copy(java.io.File source, java.io.OutputStream target, boolean closeTarget)
          Copy a file to an OutputStream
 boolean copy(java.io.InputStream source, java.io.OutputStream target, long length, boolean closeTarget)
          Copy an InputStream to an OutputStream when you know the length in advance.
 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)
          dummy main
protected  void setStandardProperties(java.net.URLConnection urlc)
          set up the standard properties on the connection.
 
Methods inherited from class com.mindprod.filetransfer.MiniFileTransfer
copy, copy, copy, setConnectTimeout, setReadTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMBEDDED_COPYRIGHT

public static final java.lang.String EMBEDDED_COPYRIGHT
undisplayed copyright notice

See Also:
Constant Field Values

VERSION_STRING

public static final java.lang.String VERSION_STRING
embedded version string.

See Also:
Constant Field Values
Constructor Detail

FileTransfer

public FileTransfer()
constructor


FileTransfer

public FileTransfer(int buffSize)
constructor

Parameters:
buffSize - how big the I/O chunks are to copy files.
Method Detail

append

public boolean append(java.io.File source,
                      java.io.File target)
append a file onto the end of another. Works with pure bytes, so can handle binary and text files. Does not do anything special to remove ^Z when appending. You can concatenate files with multiple calls to append.

Parameters:
source - file to copy on local hard disk.
target - file that will become larger by having source appended to the end of it. It need not exist. Source and target must be using the same encoding.
Returns:
true if the copy was successful.

copy

public boolean copy(java.io.File source,
                    java.io.OutputStream target,
                    boolean closeTarget)
Copy a file to an OutputStream

Parameters:
source - file to copy on local hard disk.
target - OutputStream to copy the file to.
closeTarget - true if the target OutputStream should be closed when we are done. false if the target OutputStream should be left open for further output when done.
Returns:
true if the copy was successful.

copy

public boolean copy(java.io.InputStream source,
                    java.io.OutputStream target,
                    long length,
                    boolean closeTarget)
Copy an InputStream to an OutputStream when you know the length in advance.

Parameters:
source - InputStream, left closed.
target - OutputStream, left closed.
length - how many bytes to copy, -1 if you don't know.
closeTarget - true if you want the target stream closed when done. false if you want to the target stream left open for further output.
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. To use this method with a file that requires userid/password to access it, see http://mindprod.com/jgloss/authentication.html

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

setStandardProperties

protected void setStandardProperties(java.net.URLConnection urlc)
set up the standard properties on the connection. Like code in com.mindprod.http.Http.

Parameters:
urlc - Connection we are setting up.

main

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

Parameters:
args - not used source url, target file