extra.inpro.training
Class SessionData

java.lang.Object
  extended by extra.inpro.training.SessionData

public class SessionData
extends java.lang.Object

Container for all data in the current session. SessionData contains files in the file system, and smaller information chunks (in SmallFile objects). An archive (in the form of a ZIP file) may be stored on disk or sent to a server via the network.

Author:
timo

Nested Class Summary
 class SessionData.SmallFile
          keeps data bits that are not worth to write into files.
 
Field Summary
(package private) static java.lang.String BOUNDARY
          the boundary between multipart message parts.
(package private) static int BUFFER_SIZE
          size of the buffer when piping from input buffer to output buffer
(package private)  java.util.List<SessionData.SmallFile> smallFiles
          additional list of small information chunks to be stored in the archive
(package private)  java.util.List<java.net.URL> urls
          the files contained in this archive
 
Constructor Summary
SessionData()
           
 
Method Summary
(package private)  void addFile(java.io.File file)
          add a file to the archive
(package private)  void addFile(java.lang.String filename)
          add a file given its filename
 void addFromURL(java.net.URL url)
          add data that comes from a URL
(package private)  void addSmallFile(java.lang.String filename, java.lang.CharSequence content)
          add a short bit of information that will be added to the archive under the given name.
(package private)  void clear()
          clear the archive of previous entries
static void main(java.lang.String[] args)
          for testing only.
private static void pipe(java.io.InputStream in, java.io.OutputStream out)
          pipe the content of an input stream into an output stream
(package private)  java.io.InputStream postToServer(java.lang.String url)
           
(package private)  java.io.InputStream postToServer(java.net.URL url)
          post the archive's content (packed as a zip file) to a server.
(package private)  void saveToFile(java.lang.String filename)
          write the archive's content to a local zip file
(package private)  void toOutputStream(java.io.OutputStream outStream)
          write the archive's content to an output stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

urls

final java.util.List<java.net.URL> urls
the files contained in this archive


smallFiles

final java.util.List<SessionData.SmallFile> smallFiles
additional list of small information chunks to be stored in the archive


BOUNDARY

static final java.lang.String BOUNDARY
the boundary between multipart message parts. As it is highly unlikely for this exact byte sequence to occur within the message, we ignore that we should actually check for the sequence within the message.

See Also:
Constant Field Values

BUFFER_SIZE

static final int BUFFER_SIZE
size of the buffer when piping from input buffer to output buffer

See Also:
Constant Field Values
Constructor Detail

SessionData

public SessionData()
Method Detail

addFile

void addFile(java.io.File file)
add a file to the archive

Parameters:
file - the file to add

addFile

void addFile(java.lang.String filename)
add a file given its filename


addSmallFile

void addSmallFile(java.lang.String filename,
                  java.lang.CharSequence content)
add a short bit of information that will be added to the archive under the given name.

Parameters:
filename - the filename in the zipfile
content - the data to be added

addFromURL

public void addFromURL(java.net.URL url)
add data that comes from a URL


clear

void clear()
clear the archive of previous entries


pipe

private static void pipe(java.io.InputStream in,
                         java.io.OutputStream out)
                  throws java.io.IOException
pipe the content of an input stream into an output stream

Parameters:
in - the stream being drained
out - destination of the data
Throws:
java.io.IOException - if reading or writing goes wrong

toOutputStream

void toOutputStream(java.io.OutputStream outStream)
              throws java.io.IOException
write the archive's content to an output stream

Parameters:
outStream - the stream that is written to
Throws:
java.io.IOException - when errors occur on reading the files contained in the archive

postToServer

java.io.InputStream postToServer(java.net.URL url)
                           throws java.io.IOException
post the archive's content (packed as a zip file) to a server. in Swing, this should be called from a SwingWorker thread and some progress state should be displayed, as posting large archives can take quite a while.

Parameters:
url - the server's URL
Throws:
java.io.IOException

postToServer

java.io.InputStream postToServer(java.lang.String url)
                           throws java.io.IOException
Throws:
java.io.IOException

saveToFile

void saveToFile(java.lang.String filename)
          throws java.io.IOException
write the archive's content to a local zip file

Parameters:
filename - name for the zip file
Throws:
java.io.IOException - when the file cannot be written to

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
for testing only.

Parameters:
args - arguments are ignored
Throws:
java.io.IOException - when something goes wrong