Java Doc for CircularByteBuffer.java in  » Template-Engine » ostermillerutils » com » Ostermiller » util » 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 » Template Engine » ostermillerutils » com.Ostermiller.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.Ostermiller.util.CircularByteBuffer

CircularByteBuffer
public class CircularByteBuffer (Code)
Implements the Circular Buffer producer/consumer model for bytes. More information about this class is available from ostermiller.org.

Using this class is a simpler alternative to using a PipedInputStream and a PipedOutputStream. PipedInputStreams and PipedOutputStreams don't support the mark operation, don't allow you to control buffer sizes that they use, and have a more complicated API that requires instantiating two classes and connecting them.

This class is thread safe.
See Also:   CircularCharBuffer
See Also:   CircularObjectBuffer
author:
   Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities
since:
   ostermillerutils 1.00.00


Inner Class :protected class CircularByteBufferInputStream extends InputStream
Inner Class :protected class CircularByteBufferOutputStream extends OutputStream

Field Summary
final public static  intINFINITE_SIZE
     A buffer that will grow as things are added.
protected  booleanblockingWrite
    
protected  byte[]buffer
     The circular buffer.

The actual capacity of the buffer is one less than the actual length of the buffer so that an empty and a full buffer can be distinguished.

protected  InputStreamin
     The InputStream that can empty this buffer.
protected volatile  booleaninfinite
    
protected  booleaninputStreamClosed
    
protected volatile  intmarkPosition
     Index of the first saved byte.
protected volatile  intmarkSize
     Number of bytes that have to be saved to support mark() and reset() on the InputStream.
protected  OutputStreamout
     The OutputStream that can fill this buffer.
protected  booleanoutputStreamClosed
    
protected volatile  intreadPosition
     Index of the first byte available to be read.
protected volatile  intwritePosition
     Index of the first byte available to be written.

Constructor Summary
public  CircularByteBuffer()
     Create a new buffer with a default capacity.
public  CircularByteBuffer(int size)
     Create a new buffer with given capacity.
public  CircularByteBuffer(boolean blockingWrite)
     Create a new buffer with a default capacity and given blocking behavior.
public  CircularByteBuffer(int size, boolean blockingWrite)
     Create a new buffer with the given capacity and blocking behavior.

Method Summary
public  voidclear()
     Make this buffer ready for reuse.
public  intgetAvailable()
     Get number of bytes that are available to be read.
public  InputStreamgetInputStream()
     Retrieve a InputStream that can be used to empty this buffer.
public  OutputStreamgetOutputStream()
     Retrieve a OutputStream that can be used to fill this buffer.

Write methods may throw a BufferOverflowException if the buffer is not large enough.

public  intgetSize()
     Get the capacity of this buffer.
public  intgetSpaceLeft()
     Get the number of bytes this buffer has free for writing.

Field Detail
INFINITE_SIZE
final public static int INFINITE_SIZE(Code)
A buffer that will grow as things are added.
since:
   ostermillerutils 1.00.00



blockingWrite
protected boolean blockingWrite(Code)
True if a write to a full buffer should block until the buffer has room, false if the write method should throw an IOException
since:
   ostermillerutils 1.00.00



buffer
protected byte[] buffer(Code)
The circular buffer.

The actual capacity of the buffer is one less than the actual length of the buffer so that an empty and a full buffer can be distinguished. An empty buffer will have the markPostion and the writePosition equal to each other. A full buffer will have the writePosition one less than the markPostion.

There are three important indexes into the buffer: The readPosition, the writePosition, and the markPosition. If the InputStream has never been marked, the readPosition and the markPosition should always be the same. The bytes available to be read go from the readPosition to the writePosition, wrapping around the end of the buffer. The space available for writing goes from the write position to one less than the markPosition, wrapping around the end of the buffer. The bytes that have been saved to support a reset() of the InputStream go from markPosition to readPosition, wrapping around the end of the buffer.
since:
   ostermillerutils 1.00.00




in
protected InputStream in(Code)
The InputStream that can empty this buffer.
since:
   ostermillerutils 1.00.00



infinite
protected volatile boolean infinite(Code)
If this buffer is infinite (should resize itself when full)
since:
   ostermillerutils 1.00.00



inputStreamClosed
protected boolean inputStreamClosed(Code)
true if the close() method has been called on the InputStream
since:
   ostermillerutils 1.00.00



markPosition
protected volatile int markPosition(Code)
Index of the first saved byte. (To support stream marking.)
since:
   ostermillerutils 1.00.00



markSize
protected volatile int markSize(Code)
Number of bytes that have to be saved to support mark() and reset() on the InputStream.
since:
   ostermillerutils 1.00.00



out
protected OutputStream out(Code)
The OutputStream that can fill this buffer.
since:
   ostermillerutils 1.00.00



outputStreamClosed
protected boolean outputStreamClosed(Code)
true if the close() method has been called on the OutputStream
since:
   ostermillerutils 1.00.00



readPosition
protected volatile int readPosition(Code)
Index of the first byte available to be read.
since:
   ostermillerutils 1.00.00



writePosition
protected volatile int writePosition(Code)
Index of the first byte available to be written.
since:
   ostermillerutils 1.00.00




Constructor Detail
CircularByteBuffer
public CircularByteBuffer()(Code)
Create a new buffer with a default capacity. Writing to a full buffer will block until space is available rather than throw an exception.
since:
   ostermillerutils 1.00.00



CircularByteBuffer
public CircularByteBuffer(int size)(Code)
Create a new buffer with given capacity. Writing to a full buffer will block until space is available rather than throw an exception.

Note that the buffer may reserve some bytes for special purposes and capacity number of bytes may not be able to be written to the buffer.

Note that if the buffer is of INFINITE_SIZE it will neither block or throw exceptions, but rather grow without bound.
Parameters:
  size - desired capacity of the buffer in bytes or CircularByteBuffer.INFINITE_SIZE.
since:
   ostermillerutils 1.00.00




CircularByteBuffer
public CircularByteBuffer(boolean blockingWrite)(Code)
Create a new buffer with a default capacity and given blocking behavior.
Parameters:
  blockingWrite - true writing to a full buffer should blockuntil space is available, false if an exception shouldbe thrown instead.
since:
   ostermillerutils 1.00.00



CircularByteBuffer
public CircularByteBuffer(int size, boolean blockingWrite)(Code)
Create a new buffer with the given capacity and blocking behavior.

Note that the buffer may reserve some bytes for special purposes and capacity number of bytes may not be able to be written to the buffer.

Note that if the buffer is of INFINITE_SIZE it will neither block or throw exceptions, but rather grow without bound.
Parameters:
  size - desired capacity of the buffer in bytes or CircularByteBuffer.INFINITE_SIZE.
Parameters:
  blockingWrite - true writing to a full buffer should blockuntil space is available, false if an exception shouldbe thrown instead.
since:
   ostermillerutils 1.00.00





Method Detail
clear
public void clear()(Code)
Make this buffer ready for reuse. The contents of the buffer will be cleared and the streams associated with this buffer will be reopened if they had been closed.
since:
   ostermillerutils 1.00.00



getAvailable
public int getAvailable()(Code)
Get number of bytes that are available to be read.

Note that the number of bytes available plus the number of bytes free may not add up to the capacity of this buffer, as the buffer may reserve some space for other purposes. the size in bytes of this buffer
since:
   ostermillerutils 1.00.00




getInputStream
public InputStream getInputStream()(Code)
Retrieve a InputStream that can be used to empty this buffer.

This InputStream supports marks at the expense of the buffer size. the consumer for this buffer.
since:
   ostermillerutils 1.00.00




getOutputStream
public OutputStream getOutputStream()(Code)
Retrieve a OutputStream that can be used to fill this buffer.

Write methods may throw a BufferOverflowException if the buffer is not large enough. A large enough buffer size must be chosen so that this does not happen or the caller must be prepared to catch the exception and try again once part of the buffer has been consumed. the producer for this buffer.
since:
   ostermillerutils 1.00.00




getSize
public int getSize()(Code)
Get the capacity of this buffer.

Note that the number of bytes available plus the number of bytes free may not add up to the capacity of this buffer, as the buffer may reserve some space for other purposes. the size in bytes of this buffer
since:
   ostermillerutils 1.00.00




getSpaceLeft
public int getSpaceLeft()(Code)
Get the number of bytes this buffer has free for writing.

Note that the number of bytes available plus the number of bytes free may not add up to the capacity of this buffer, as the buffer may reserve some space for other purposes. the available space in bytes of this buffer
since:
   ostermillerutils 1.00.00




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.