Java Doc for FileMessageFactory.java in  » Sevlet-Container » apache-tomcat-6.0.14 » org » apache » catalina » ha » deploy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Sevlet Container » apache tomcat 6.0.14 » org.apache.catalina.ha.deploy 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.catalina.ha.deploy.FileMessageFactory

FileMessageFactory
public class FileMessageFactory (Code)
This factory is used to read files and write files by splitting them up into smaller messages. So that entire files don't have to be read into memory.
The factory can be used as a reader or writer but not both at the same time. When done reading or writing the factory will close the input or output streams and mark the factory as closed. It is not possible to use it after that.
To force a cleanup, call cleanup() from the calling object.
This class is not thread safe.
author:
   Filip Hanik
version:
   1.0


Field Summary
final public static  intREAD_SIZE
    
protected  booleanclosed
     Once the factory is used, it can not be reused.
protected  byte[]data
     The bytes that we hold the data in, not thread safe.
protected  Filefile
    
protected  FileInputStreamin
    
public static  org.apache.juli.logging.Loglog
    
protected  intnrOfMessagesProcessed
    
protected  booleanopenForWrite
     True means that we are writing with this factory.
protected  FileOutputStreamout
    
protected  longsize
    
protected  longtotalNrOfMessages
    


Method Summary
protected  voidcheckState(boolean openForWrite)
     Check to make sure the factory is able to perform the function it is asked to do.
public  voidcleanup()
    
public  FilegetFile()
    
public static  FileMessageFactorygetInstance(File f, boolean openForWrite)
     Creates a factory to read or write from a file.
public static  voidmain(String[] args)
     Example usage.
public  FileMessagereadMessage(FileMessage f)
     Reads file data into the file message and sets the size, totalLength, totalNrOfMsgs and the message number
If EOF is reached, the factory returns null, and closes itself, otherwise the same message is returned as was passed in.
public  booleanwriteMessage(FileMessage msg)
     Writes a message to file.

Field Detail
READ_SIZE
final public static int READ_SIZE(Code)
The number of bytes that we read from file



closed
protected boolean closed(Code)
Once the factory is used, it can not be reused.



data
protected byte[] data(Code)
The bytes that we hold the data in, not thread safe.



file
protected File file(Code)
The file that we are reading/writing



in
protected FileInputStream in(Code)
When openForWrite=false, the input stream is held by this variable



log
public static org.apache.juli.logging.Log log(Code)



nrOfMessagesProcessed
protected int nrOfMessagesProcessed(Code)
The number of messages we have read or written



openForWrite
protected boolean openForWrite(Code)
True means that we are writing with this factory. False means that we are reading with this factory



out
protected FileOutputStream out(Code)
When openForWrite=true, the output stream is held by this variable



size
protected long size(Code)
The total size of the file



totalNrOfMessages
protected long totalNrOfMessages(Code)
The total number of packets that we split this file into





Method Detail
checkState
protected void checkState(boolean openForWrite) throws IllegalArgumentException(Code)
Check to make sure the factory is able to perform the function it is asked to do. Invoked by readMessage/writeMessage before those methods proceed.
Parameters:
  openForWrite - boolean
throws:
  IllegalArgumentException -



cleanup
public void cleanup()(Code)
Closes the factory, its streams and sets all its references to null



getFile
public File getFile()(Code)



getInstance
public static FileMessageFactory getInstance(File f, boolean openForWrite) throws FileNotFoundException, IOException(Code)
Creates a factory to read or write from a file. When opening for read, the readMessage can be invoked, and when opening for write the writeMessage can be invoked.
Parameters:
  f - File - the file to be read or written
Parameters:
  openForWrite - boolean - true, means we are writing to the file, false meanswe are reading from it
throws:
  FileNotFoundException - -if the file to be read doesn't exist
throws:
  IOException - -if it fails to create the file that is to be written FileMessageFactory



main
public static void main(String[] args) throws Exception(Code)
Example usage.
Parameters:
  args - String[], args[0] - read from filename, args[1] write tofilename
throws:
  Exception -



readMessage
public FileMessage readMessage(FileMessage f) throws IllegalArgumentException, IOException(Code)
Reads file data into the file message and sets the size, totalLength, totalNrOfMsgs and the message number
If EOF is reached, the factory returns null, and closes itself, otherwise the same message is returned as was passed in. This makes sure that not more memory is ever used. To remember, neither the file message or the factory are thread safe. dont hand off the message to one thread and read the same with another.
Parameters:
  f - FileMessage - the message to be populated with file data
throws:
  IllegalArgumentException - -if the factory is for writing or is closed
throws:
  IOException - -if a file read exception occurs FileMessage - returns the same message passed in as a parameter,or null if EOF



writeMessage
public boolean writeMessage(FileMessage msg) throws IllegalArgumentException, IOException(Code)
Writes a message to file. If (msg.getMessageNumber() == msg.getTotalNrOfMsgs()) the output stream will be closed after writing.
Parameters:
  msg - FileMessage - message containing data to be written
throws:
  IllegalArgumentException - -if the factory is opened for read or closed
throws:
  IOException - -if a file write error occurs returns true if the file is complete and outputstream is closed,false otherwise.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.