// Length of zero may indicate an initialized text
// column that has been updated to null.
break;
}
ClobImpl clob = new ClobImpl(connection);
BlobBuffer blobBuffer = clob.getBlobBuffer();
if (dataLen <= connection.getLobBuffer()) {
//
// OK Small enough to load into memory
//
BufferedReader rdr =
new BufferedReader(
new InputStreamReader(in.getInputStream(dataLen),
charset),
1024);
byte[] data = new byte[dataLen * 2];
int p = 0;
int c;
while ((c = rdr.read()) >= 0) {
data[p++] = (byte)c;
data[p++] = (byte)(c >> 8);
}
rdr.close();
blobBuffer.setBuffer(data, false);
if (p == 2 && data[0] == 0x20 && data[1] == 0
&& in.getTdsVersion() < Driver.TDS70) {
// Single space with Sybase equates to empty string
p = 0;
}
// Explicitly set length as multi byte character sets
// may not fill array completely.
blobBuffer.setLength(p);
} else {
// Too big, need to write straight to disk
BufferedReader rdr =
new BufferedReader(
new InputStreamReader(in.getInputStream(dataLen),
charset),
1024);
try {
OutputStream out = blobBuffer.setBinaryStream(1, false);
int c;
while ((c = rdr.read()) >= 0) {
out.write(c);
out.write(c >> 8);
}
out.close();
rdr.close();
} catch (SQLException e) {
// Turn back into an IOException
throw new IOException(e.getMessage());
}
}
return clob;
}
break;
case SYBUNITEXT: // ASE 15+ unicode text type
case SYBNTEXT:
len = in.read();
if (len > 0) {
in.skip(24); // Skip textptr and timestamp
int dataLen = in.readInt();
if (dataLen == 0 && in.getTdsVersion() <= Driver.TDS50) {
// Length of zero may indicate an initialized unitext
// column that has been updated to null.
break;
}
ClobImpl clob = new ClobImpl(connection);
BlobBuffer blobBuffer = clob.getBlobBuffer();
if (dataLen <= connection.getLobBuffer()) {
//
// OK Small enough to load into memory
//
byte[] data = new byte[dataLen];
in.read(data);
blobBuffer.setBuffer(data, false);
if (dataLen == 2 && data[0] == 0x20 && data[1] == 0
&& in.getTdsVersion() == Driver.TDS50) {
// Single space with Sybase equates to empty string
dataLen = 0;
}
// Explicitly set length as multi byte character sets
// may not fill array completely.
blobBuffer.setLength(dataLen);
} else {
// Too big, need to write straight to disk
try {
OutputStream out = blobBuffer.setBinaryStream(1, false);
byte[] buffer = new byte[1024];
int result;
while ((result = in.read(buffer, 0,
Math.min(dataLen, buffer.length)))
!= -1 && dataLen != 0) {