Java Doc for BlobBuffer.java in  » Database-JDBC-Connection-Pool » jTDS » net » sourceforge » jtds » 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 » Database JDBC Connection Pool » jTDS » net.sourceforge.jtds.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   net.sourceforge.jtds.util.BlobBuffer

BlobBuffer
public class BlobBuffer (Code)
Manages a buffer (backed by optional disk storage) for use as a data store by the CLOB and BLOB objects.

The data can be purely memory based until the size exceeds the value dictated by the lobBuffer URL property after which it will be written to disk. The disk array is accessed randomly one page (1024 bytes) at a time.

This class is not synchronized and concurrent open input and output streams can conflict.

Tuning hints:

  1. The PAGE_SIZE governs how much data is buffered when reading or writing data a byte at a time. 1024 bytes seems to work well but if very large objects are being written a byte at a time 4096 may be better. NB. ensure that the PAGE_MASK and BYTE_MASK fields are also adjusted to match.
  2. Reading or writing byte arrays that are greater than or equal to the page size will go directly to or from the random access file cutting out an ArrayCopy operation.
  3. If BLOBs are being buffered exclusively in memory you may wish to adjust the MAX_BUF_INC value. Every time the buffer is expanded the existing contents are copied and this may get expensive with very large BLOBs.
  4. The BLOB file will be kept open for as long as there are open input or output streams. Therefore BLOB streams should be explicitly closed as soon as they are finished with.

author:
   Mike Hutchinson
version:
   $Id: BlobBuffer.java,v 1.4 2007/07/08 21:38:14 bheineman Exp $



Constructor Summary
public  BlobBuffer(File bufferDir, long maxMemSize)
     Creates a blob buffer.

Method Summary
public  voidclose()
     Logically closes the file or physically close it if the open count is now zero.
public  voidcreateBlobFile()
     Creates a random access disk file to use as backing storage for the LOB data.
protected  voidfinalize()
     Finalizes this object by deleting any work files.
public  InputStreamgetBinaryStream(boolean ascii)
     Retrieve the BLOB data as an InputStream.
public  byte[]getBytes(long pos, int len)
     Returns the BLOB data as a byte array.
public  longgetLength()
     Retrieves the length of this BLOB buffer in bytes.
public  InputStreamgetUnicodeStream()
     Retrieve the BLOB data as an Big Endian Unicode InputStream.
public  voidgrowBuffer(int minSize)
     Increases the size of the in memory buffer for situations where disk storage of BLOB is not possible.
public  voidopen()
     Opens the BLOB disk file.
public  intposition(byte[] pattern, long start)
     Provides support for pattern searching methods.
public  intread(int readPtr)
     Reads byte from the BLOB buffer at the specified location.

The read pointer is partitioned into a page number and an offset within the page.

public  intread(int readPtr, byte[] bytes, int offset, int len)
     Reads bytes from the BLOB buffer at the specified location.
public  voidreadPage(int page)
     Reads in the specified page from the disk buffer.
public  OutputStreamsetBinaryStream(long pos, boolean ascii)
     Creates an OutputStream that can be used to update the BLOB.
public  voidsetBuffer(byte[] bytes, boolean copy)
     Sets the initial buffer to an existing byte array.
public  intsetBytes(long pos, byte[] bytes, int offset, int len, boolean copy)
     Sets the content of the BLOB to the supplied byte array value.
public  voidsetLength(long length)
     Retrieves the length of the BLOB buffer (in memory version only).
public  voidtruncate(long len)
     Truncates the BLOB buffer to the specified size.
public  voidwrite(int writePtr, int b)
     Inserts a byte into the buffer at the specified location.

The write pointer is partitioned into a page number and an offset within the page.

 voidwrite(int writePtr, byte[] bytes, int offset, int len)
     Inserts bytes into the buffer at the specified location.
public  voidwritePage(int page)
     Writes the specified page to the disk buffer.


Constructor Detail
BlobBuffer
public BlobBuffer(File bufferDir, long maxMemSize)(Code)
Creates a blob buffer.
Parameters:
  bufferDir -
Parameters:
  maxMemSize - the maximum size of the in memory buffer




Method Detail
close
public void close() throws IOException(Code)
Logically closes the file or physically close it if the open count is now zero.

Any updated buffer in memory is flushed to disk before the file is closed.
throws:
  IOException - if an I/O error occurs




createBlobFile
public void createBlobFile()(Code)
Creates a random access disk file to use as backing storage for the LOB data.

This method may fail due to security exceptions or local disk problems, in which case the blob storage will remain entirely in memory.




finalize
protected void finalize() throws Throwable(Code)
Finalizes this object by deleting any work files.



getBinaryStream
public InputStream getBinaryStream(boolean ascii) throws SQLException(Code)
Retrieve the BLOB data as an InputStream.
Parameters:
  ascii - true if an ASCII input stream should be returned the InputStream built over the BLOB data
throws:
  SQLException - if an error occurs



getBytes
public byte[] getBytes(long pos, int len) throws SQLException(Code)
Returns the BLOB data as a byte array.
Parameters:
  pos - the start position in the BLOB buffer (from 1)
Parameters:
  len - the number of bytes to copy the requested data as a byte[]



getLength
public long getLength()(Code)
Retrieves the length of this BLOB buffer in bytes. the length of the BLOB data in bytes



getUnicodeStream
public InputStream getUnicodeStream() throws SQLException(Code)
Retrieve the BLOB data as an Big Endian Unicode InputStream. the InputStream built over the BLOB data
throws:
  SQLException - if an error occurs



growBuffer
public void growBuffer(int minSize)(Code)
Increases the size of the in memory buffer for situations where disk storage of BLOB is not possible.
Parameters:
  minSize - the minimum size of buffer required



open
public void open() throws IOException(Code)
Opens the BLOB disk file.

A count of open and close requests is kept so that the file may be closed when no longer required thus keeping the number of open files to a minimum.
throws:
  IOException - if an I/O error occurs




position
public int position(byte[] pattern, long start) throws SQLException(Code)
Provides support for pattern searching methods.
Parameters:
  pattern - the byte array containg the search pattern
Parameters:
  start - the start position in the BLOB (from 1) the int start index for the pattern (from 1) or -1if the pattern is not found.
throws:
  SQLException - if an error occurs



read
public int read(int readPtr) throws IOException(Code)
Reads byte from the BLOB buffer at the specified location.

The read pointer is partitioned into a page number and an offset within the page. This routine will read new pages as required. The page size must be a power of 2 and is currently set to 1024 bytes.
Parameters:
  readPtr - the offset in the buffer of the required byte the byte value as an int or -1 if at EOF
throws:
  IOException - if an I/O error occurs




read
public int read(int readPtr, byte[] bytes, int offset, int len) throws IOException(Code)
Reads bytes from the BLOB buffer at the specified location.
Parameters:
  readPtr - the offset in the buffer of the required byte
Parameters:
  bytes - the byte array to fill
Parameters:
  offset - the start position in the byte array
Parameters:
  len - the number of bytes to read the number of bytes read or -1 if at end of file
throws:
  IOException - if an I/O error occurs



readPage
public void readPage(int page) throws IOException(Code)
Reads in the specified page from the disk buffer.

Any existing dirty page is first saved to disk.
Parameters:
  page - the page number
throws:
  IOException - if an I/O error occurs




setBinaryStream
public OutputStream setBinaryStream(long pos, boolean ascii) throws SQLException(Code)
Creates an OutputStream that can be used to update the BLOB.

Given that we cannot know the final size of a BLOB created by the caller of this method, we assume the worst and create a disk BLOB by default.
Parameters:
  pos - the start position in the buffer (from 1)
Parameters:
  ascii - true if an ASCII output stream is required the OutputStream to be used to update the BLOB
throws:
  SQLException - if an error occurs




setBuffer
public void setBuffer(byte[] bytes, boolean copy)(Code)
Sets the initial buffer to an existing byte array.
Parameters:
  bytes - the byte array containing the BLOB data
Parameters:
  copy - true if a local copy of the data is required



setBytes
public int setBytes(long pos, byte[] bytes, int offset, int len, boolean copy) throws SQLException(Code)
Sets the content of the BLOB to the supplied byte array value.

If the following conditions are met:

  1. The start position is 1
  2. The existing BLOB length is smaller or the same as the length of the new data
  3. The new data length does not exceed the in memory limit
then the new data is buffered entirely in memory, otherwise a disk file is created.
Parameters:
  pos - the start position in the buffer (from 1)
Parameters:
  bytes - the byte array containing the data to copy
Parameters:
  offset - the start position in the byte array (from 0)
Parameters:
  len - the number of bytes to copy
Parameters:
  copy - true if a local copy of the byte array is required the number of bytes copied
throws:
  SQLException - if an error occurs



setLength
public void setLength(long length)(Code)
Retrieves the length of the BLOB buffer (in memory version only).
Parameters:
  length - the length of the valid data in the buffer



truncate
public void truncate(long len) throws SQLException(Code)
Truncates the BLOB buffer to the specified size.
Parameters:
  len - the required length
throws:
  SQLException - if an error occurs



write
public void write(int writePtr, int b) throws IOException(Code)
Inserts a byte into the buffer at the specified location.

The write pointer is partitioned into a page number and an offset within the page. This routine will write new pages as required. The page size must be a power of 2 and is currently set to 1024 bytes.
Parameters:
  writePtr - the offset in the buffer of the required byte
Parameters:
  b - the byte value to write
throws:
  IOException - if an I/O error occurs




write
void write(int writePtr, byte[] bytes, int offset, int len) throws IOException(Code)
Inserts bytes into the buffer at the specified location.
Parameters:
  writePtr - the offset in the buffer of the required byte
Parameters:
  bytes - the byte array value to write
Parameters:
  offset - the start position in the byte array
Parameters:
  len - the number of bytes to write
throws:
  IOException - if an I/O error occurs



writePage
public void writePage(int page) throws IOException(Code)
Writes the specified page to the disk buffer.
Parameters:
  page - the page number
throws:
  IOException - if an I/O error occurs



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.