com.mindprod.filetransfer
Class MiniFileTransfer

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

public class MiniFileTransfer
extends java.lang.Object

copy a file, typically from a resource in a jar to the hard disk.

To read or write from the client's local hard disk in an Applet, 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.

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

Constructor Summary
MiniFileTransfer()
          constructor
MiniFileTransfer(int buffSize)
          constructor
 
Method Summary
 boolean copy(java.io.InputStream source, java.io.File target)
          copy a file from a stream, typically a resource in the archive jar file to a local file on hard disk.
 boolean copy(java.io.InputStream source, java.io.OutputStream target, boolean closeTarget)
          Copy an InputStream to an OutputStream, until EOF.
 boolean copy(java.util.zip.ZipFile sourceJar, java.lang.String zipEntryString, java.io.File target)
          Copy a file from a resource in some a local jar file, not the archive, to a local file on hard disk.
static void main(java.lang.String[] args)
          dummy main
 void setConnectTimeout(int connectTimeout)
          override the default connect timeout of 50 seconds
 void setReadTimeout(int readTimeout)
          override the default read timeout of 40 seconds
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MiniFileTransfer

public MiniFileTransfer()
constructor


MiniFileTransfer

public MiniFileTransfer(int buffSize)
constructor

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

copy

public boolean copy(java.io.InputStream source,
                    java.io.File target)
copy a file from a stream, typically a resource in the archive jar file to a local file on hard disk.

Parameters:
source - resource as stream e.g. this.class.getResourceAsStream("lyrics.ram"); Netscape interferes with extensions *.exe, *.dll etc. So use *.ram for your resources.
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,
                    boolean closeTarget)
Copy an InputStream to an OutputStream, until EOF. Use only when you don't know the length of the transfer ahead of time. Otherwise use FileTransfer.copy.

Parameters:
source - InputStream, always left closed
target - OutputStream
closeTarget - true if you want target stream closed when done. false, leave the target open for more I/O.
Returns:
true if the copy was successful.

copy

public boolean copy(java.util.zip.ZipFile sourceJar,
                    java.lang.String zipEntryString,
                    java.io.File target)
Copy a file from a resource in some a local jar file, not the archive, to a local file on hard disk. To deal with remote jars in JDK 1.1 download the entire jar, then copy the various contents to their resting places, then delete the jar. To deal with remote jars in JDK 1.2 use the new jar URL syntax, that lets you treat a member as if it were an separate file, jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class

Parameters:
sourceJar - ZipFile e.g. new ZipFile("stuff.jar"), left open.
zipEntryString - fully qualified name of ZipEntry e.g. "com/mindprod/mypack/Stuff.html". Note this is a String, not a ZipEntry.
target - new file to be created on local hard disk.
Returns:
true if the copy was successful.

setConnectTimeout

public void setConnectTimeout(int connectTimeout)
override the default connect timeout of 50 seconds

Parameters:
connectTimeout - timeout to connect in ms. Note int not long.

setReadTimeout

public void setReadTimeout(int readTimeout)
override the default read timeout of 40 seconds

Parameters:
readTimeout - timeout to connect int ms. Note int not long.

main

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

Parameters:
args - not used source url, target file