You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by tm...@apache.org on 2006/05/27 04:20:30 UTC
svn commit: r409797 [4/4] - in
/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda: DDMWriter.java
DRDAConnThread.java EXTDTAInputStream.java
Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/EXTDTAInputStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/EXTDTAInputStream.java?rev=409797&r1=409796&r2=409797&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/EXTDTAInputStream.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/EXTDTAInputStream.java Fri May 26 19:20:29 2006
@@ -50,22 +50,21 @@
private InputStream binaryInputStream = null;
private boolean isEmptyStream;
-
+
private ResultSet dataResultSet = null;
private Blob blob = null;
private Clob clob = null;
-
+
private EXTDTAInputStream(ResultSet rs,
- int columnNumber,
- int ndrdaType)
- throws SQLException, IOException
- {
-
- this.dataResultSet = rs;
- this.isEmptyStream = ! initInputStream(rs,
- columnNumber,
- ndrdaType);
-
+ int columnNumber,
+ int ndrdaType)
+ throws SQLException, IOException {
+
+ this.dataResultSet = rs;
+ this.isEmptyStream = ! initInputStream(rs,
+ columnNumber,
+ ndrdaType);
+
}
@@ -84,32 +83,32 @@
* column number
* @param drdaType
* FD:OCA type of object one of
- * DRDAConstants.DRDA_TYPE_NLOBBYTES
- * DRDAConstants.DRDA_TYPE_LOBBYTES
- * DRDAConstants.DRDA_TYPE_NLOBCMIXED
- * DRDAConstants.DRDA_TYPE_LOBCMIXED
+ * DRDAConstants.DRDA_TYPE_NLOBBYTES
+ * DRDAConstants.DRDA_TYPE_LOBBYTES
+ * DRDAConstants.DRDA_TYPE_NLOBCMIXED
+ * DRDAConstants.DRDA_TYPE_LOBCMIXED
*
* @return null if the value is null or a new EXTDTAInputStream corresponding to
- * rs.getBinaryStream(column) value and associated length
+ * rs.getBinaryStream(column) value and associated length
*
* @throws SQLException
*/
public static EXTDTAInputStream getEXTDTAStream(ResultSet rs, int column, int drdaType)
- throws SQLException {
- try{
- int ndrdaType = drdaType | 1; //nullable drdaType
-
- return new EXTDTAInputStream(rs,
- column,
- ndrdaType);
-
- }catch(IOException e){
- throw new SQLException(e.getMessage());
- }
-
+ throws SQLException {
+ try{
+ int ndrdaType = drdaType | 1; //nullable drdaType
+
+ return new EXTDTAInputStream(rs,
+ column,
+ ndrdaType);
+
+ }catch(IOException e){
+ throw new SQLException(e.getMessage());
+ }
+
}
-
+
/**
* Get the length of the InputStream
* This method is currently not used because there seems to be no way to
@@ -120,37 +119,37 @@
* @return length of stream
*/
private static long getInputStreamLength(InputStream binaryInputStream)
- throws SQLException {
- long length = 0;
- if (binaryInputStream == null)
- return length;
-
- try {
- for (;;) {
- int avail = binaryInputStream.available();
- binaryInputStream.skip(avail);
- if (avail == 0)
- break;
- length += avail;
-
- }
- //binaryInputStream.close();
- } catch (IOException ioe) {
- throw Util.javaException(ioe);
- }
+ throws SQLException {
+ long length = 0;
+ if (binaryInputStream == null)
+ return length;
+
+ try {
+ for (;;) {
+ int avail = binaryInputStream.available();
+ binaryInputStream.skip(avail);
+ if (avail == 0)
+ break;
+ length += avail;
+
+ }
+ //binaryInputStream.close();
+ } catch (IOException ioe) {
+ throw Util.javaException(ioe);
+ }
- return length;
+ return length;
}
-
-
+
+
/**
*
*
* @see java.io.InputStream#read()
*/
public int read() throws IOException {
- return binaryInputStream.read();
+ return binaryInputStream.read();
}
/**
@@ -159,7 +158,7 @@
* @see java.io.InputStream#available()
*/
public int available() throws IOException {
- return binaryInputStream.available();
+ return binaryInputStream.available();
}
/**
@@ -168,19 +167,19 @@
* @see java.io.InputStream#close()
*/
public void close() throws IOException {
-
- try{
- if (binaryInputStream != null)
- binaryInputStream.close();
- binaryInputStream = null;
-
- }finally{
-
- blob = null;
- clob = null;
- dataResultSet = null;
- }
-
+
+ try{
+ if (binaryInputStream != null)
+ binaryInputStream.close();
+ binaryInputStream = null;
+
+ }finally{
+
+ blob = null;
+ clob = null;
+ dataResultSet = null;
+ }
+
}
/**
@@ -189,7 +188,7 @@
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object arg0) {
- return binaryInputStream.equals(arg0);
+ return binaryInputStream.equals(arg0);
}
/**
@@ -198,7 +197,7 @@
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
- return binaryInputStream.hashCode();
+ return binaryInputStream.hashCode();
}
/**
@@ -207,7 +206,7 @@
* @see java.io.InputStream#mark(int)
*/
public void mark(int arg0) {
- binaryInputStream.mark(arg0);
+ binaryInputStream.mark(arg0);
}
/**
@@ -216,7 +215,7 @@
* @see java.io.InputStream#markSupported()
*/
public boolean markSupported() {
- return binaryInputStream.markSupported();
+ return binaryInputStream.markSupported();
}
/**
@@ -225,7 +224,7 @@
* @see java.io.InputStream#read(byte[])
*/
public int read(byte[] arg0) throws IOException {
- return binaryInputStream.read(arg0);
+ return binaryInputStream.read(arg0);
}
/**
@@ -234,7 +233,7 @@
* @see java.io.InputStream#read(byte[], int, int)
*/
public int read(byte[] arg0, int arg1, int arg2) throws IOException {
- return binaryInputStream.read(arg0, arg1, arg2);
+ return binaryInputStream.read(arg0, arg1, arg2);
}
/**
@@ -243,7 +242,7 @@
* @see java.io.InputStream#reset()
*/
public void reset() throws IOException {
- binaryInputStream.reset();
+ binaryInputStream.reset();
}
/**
@@ -252,12 +251,12 @@
* @see java.io.InputStream#skip(long)
*/
public long skip(long arg0) throws IOException {
- return binaryInputStream.skip(arg0);
+ return binaryInputStream.skip(arg0);
}
protected boolean isEmptyStream(){
- return isEmptyStream;
+ return isEmptyStream;
}
@@ -274,75 +273,67 @@
*
*/
private boolean initInputStream(ResultSet rs,
- int column,
- int ndrdaType)
- throws SQLException,
- IOException
- {
-
- InputStream is = null;
- try{
- // BLOBS
- if (ndrdaType == DRDAConstants.DRDA_TYPE_NLOBBYTES)
- {
- blob = rs.getBlob(column);
- if(blob == null){
- return false;
- }
-
- is = blob.getBinaryStream();
-
- }
- // CLOBS
- else if (ndrdaType == DRDAConstants.DRDA_TYPE_NLOBCMIXED)
- {
- try {
- clob = rs.getClob(column);
-
- if(clob == null){
- return false;
- }
-
- is = new ReEncodedInputStream(clob.getCharacterStream());
-
- }catch (java.io.UnsupportedEncodingException e) {
- throw new SQLException (e.getMessage());
-
- }catch (IOException e){
- throw new SQLException (e.getMessage());
-
- }
-
- }
- else
- {
- if (SanityManager.DEBUG)
- {
- SanityManager.THROWASSERT("NDRDAType: " + ndrdaType +
- " not valid EXTDTA object type");
- }
- }
-
- boolean exist = is.read() > -1;
-
- is.close();
- is = null;
-
- if(exist){
- openInputStreamAgain();
- }
-
- return exist;
-
- }catch(IllegalStateException e){
- throw Util.javaException(e);
-
- }finally{
- if(is != null)
- is.close();
-
- }
-
+ int column,
+ int ndrdaType)
+ throws SQLException,
+ IOException {
+
+ InputStream is = null;
+ try{
+ // BLOBS
+ if (ndrdaType == DRDAConstants.DRDA_TYPE_NLOBBYTES) {
+ blob = rs.getBlob(column);
+ if(blob == null){
+ return false;
+ }
+
+ is = blob.getBinaryStream();
+
+ } else if (ndrdaType == DRDAConstants.DRDA_TYPE_NLOBCMIXED) {
+ try {
+ clob = rs.getClob(column);
+
+ if(clob == null){
+ return false;
+ }
+
+ is = new ReEncodedInputStream(clob.getCharacterStream());
+
+ }catch (java.io.UnsupportedEncodingException e) {
+ throw new SQLException (e.getMessage());
+
+ }catch (IOException e){
+ throw new SQLException (e.getMessage());
+
+ }
+
+ } else {
+ if (SanityManager.DEBUG) {
+ SanityManager.THROWASSERT("NDRDAType: " + ndrdaType +
+ " not valid EXTDTA object type");
+ }
+ }
+
+ boolean exist = is.read() > -1;
+
+ is.close();
+ is = null;
+
+ if(exist){
+ openInputStreamAgain();
+ }
+
+ return exist;
+
+ }catch(IllegalStateException e){
+ throw Util.javaException(e);
+
+ }finally{
+ if(is != null)
+ is.close();
+
+ }
+
}
@@ -353,42 +344,42 @@
*
*/
private void openInputStreamAgain() throws IllegalStateException,SQLException {
-
- if(this.binaryInputStream != null){
- return;
- }
-
- InputStream is = null;
- try{
-
- if(SanityManager.DEBUG){
- SanityManager.ASSERT( ( blob != null && clob == null ) ||
- ( clob != null && blob == null ),
- "One of blob or clob must be non-null.");
- }
-
- if(blob != null){
- is = blob.getBinaryStream();
-
- }else if(clob != null){
- is = new ReEncodedInputStream(clob.getCharacterStream());
- }
-
- }catch(IOException e){
- throw new IllegalStateException(e.getMessage());
- }
-
- if(! is.markSupported() ){
- is = new BufferedInputStream(is);
- }
+
+ if(this.binaryInputStream != null){
+ return;
+ }
+
+ InputStream is = null;
+ try{
+
+ if(SanityManager.DEBUG){
+ SanityManager.ASSERT( ( blob != null && clob == null ) ||
+ ( clob != null && blob == null ),
+ "One of blob or clob must be non-null.");
+ }
+
+ if(blob != null){
+ is = blob.getBinaryStream();
+
+ }else if(clob != null){
+ is = new ReEncodedInputStream(clob.getCharacterStream());
+ }
+
+ }catch(IOException e){
+ throw new IllegalStateException(e.getMessage());
+ }
+
+ if(! is.markSupported() ){
+ is = new BufferedInputStream(is);
+ }
- this.binaryInputStream = is;
+ this.binaryInputStream = is;
}
protected void finalize() throws Throwable{
- close();
+ close();
}