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 ka...@apache.org on 2013/05/30 09:19:54 UTC
svn commit: r1487774 - in
/db/derby/code/trunk/java/client/org/apache/derby/client: am/ net/
Author: kahatlen
Date: Thu May 30 07:19:54 2013
New Revision: 1487774
URL: http://svn.apache.org/r1487774
Log:
DERBY-6231: Remove unnecessary checks for UnsupportedEncodingException in the client
Refer to encodings with Charset constants instead of names.
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientClob.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientPreparedStatement.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/CrossConverters.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/Cursor.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/DateTime.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/Decimal.java
db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/EncodedInputStream.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPackageRequest.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetSqlca.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/Reply.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/Typdef.java
db/derby/code/trunk/java/client/org/apache/derby/client/net/Utf8CcsidManager.java
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientClob.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientClob.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientClob.java Thu May 30 07:19:54 2013
@@ -28,8 +28,8 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
import java.io.Writer;
+import java.nio.charset.Charset;
import java.sql.Clob;
import java.sql.SQLException;
@@ -69,64 +69,51 @@ public class ClientClob extends Lob impl
// CTOR for output, when a btc isn't available; the encoding is
public ClientClob(Agent agent,
byte[] unconvertedBytes,
- String charsetName,
+ Charset charset,
int dataOffset) throws SqlException {
this(agent,
false);
- try {
- // check for null encoding is needed because the net layer
- // will no longer throw an exception if the server didn't specify
- // a mixed or double byte ccsid (ccsid = 0). this check for null in the
- // cursor is only required for types which can have mixed or double
- // byte ccsids.
- if (charsetName == null) {
- throw new SqlException(agent.logWriter_,
- new ClientMessageId(SQLState.CHARACTER_CONVERTER_NOT_AVAILABLE));
- }
-
- string_ = new String(unconvertedBytes,
- dataOffset,
- unconvertedBytes.length - dataOffset,
- charsetName);
- setSqlLength(string_.length());
- dataType_ |= STRING;
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "byte[]", charsetName + " String", e);
-
+ // check for null encoding is needed because the net layer
+ // will no longer throw an exception if the server didn't specify
+ // a mixed or double byte ccsid (ccsid = 0). this check for null in the
+ // cursor is only required for types which can have mixed or double
+ // byte ccsids.
+ if (charset == null) {
+ throw new SqlException(agent.logWriter_,
+ new ClientMessageId(SQLState.CHARACTER_CONVERTER_NOT_AVAILABLE));
}
+
+ string_ = new String(unconvertedBytes,
+ dataOffset,
+ unconvertedBytes.length - dataOffset,
+ charset);
+ setSqlLength(string_.length());
+ dataType_ |= STRING;
}
// CTOR for ascii/unicode stream input
//"ISO-8859-1", "UTF-8", or "UnicodeBigUnmarked"
public ClientClob(Agent agent,
InputStream inputStream,
- String encoding,
- int length) throws SqlException {
+ Charset encoding,
+ int length) {
this(agent,
false);
setSqlLength(length);
- if (encoding.equals("ISO-8859-1")) {
+ if (encoding.equals(Cursor.ISO_8859_1)) {
asciiStream_ = inputStream;
dataType_ |= ASCII_STREAM;
- } else if (encoding.equals("UTF-8")) { // "UTF-8"
+ } else if (encoding.equals(Cursor.UTF_8)) {
unicodeStream_ = inputStream;
dataType_ |= UNICODE_STREAM;
- } else if (encoding.equals("UnicodeBigUnmarked")) { // "UnicodeBigUnmarked"
- try {
- characterStream_ =
- new InputStreamReader(inputStream, "UnicodeBigUnmarked");
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "UnicodeBigUnmarked", "InputStreamReader", e);
- }
+ } else if (encoding.equals(Cursor.UTF_16BE)) {
+ characterStream_ =
+ new InputStreamReader(inputStream, Cursor.UTF_16BE);
dataType_ |= CHARACTER_STREAM;
setSqlLength(length / 2);
}
@@ -145,13 +132,13 @@ public class ClientClob extends Lob impl
* @param encoding encoding to use for characters. Only "ISO-8859-1" is
* allowed.
*/
- ClientClob(Agent agent, InputStream inputStream, String encoding)
+ ClientClob(Agent agent, InputStream inputStream, Charset encoding)
throws SqlException {
this(agent,
isLayerBStreamingPossible( agent ));
- if (encoding.equals("ISO-8859-1")) {
+ if (encoding.equals(Cursor.ISO_8859_1)) {
asciiStream_ = inputStream;
dataType_ |= ASCII_STREAM;
} else {
@@ -975,19 +962,13 @@ public class ClientClob extends Lob impl
// Return the length of the equivalent UTF-8 string
// precondition: string_ is not null and dataType_ includes STRING
- public int getUTF8Length() throws SqlException {
+ public int getUTF8Length() {
if (utf8String_ != null) {
return utf8String_.length;
}
- try {
- utf8String_ = string_.getBytes("UTF-8");
- return utf8String_.length;
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "String", "UTF8 byte[]", e);
- }
+ utf8String_ = string_.getBytes(Cursor.UTF_8);
+ return utf8String_.length;
}
/**
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientPreparedStatement.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientPreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientPreparedStatement.java Thu May 30 07:19:54 2013
@@ -1051,7 +1051,7 @@ public class ClientPreparedStatement ext
}
checkStreamLength(length);
setInput(parameterIndex,
- new ClientClob(agent_, x, "ISO-8859-1", (int)length));
+ new ClientClob(agent_, x, Cursor.ISO_8859_1, (int) length));
}
}
catch ( SqlException se )
@@ -2511,7 +2511,7 @@ public class ClientPreparedStatement ext
return;
}
setInput(parameterIndex,
- new ClientClob(agent_, x, "ISO-8859-1"));
+ new ClientClob(agent_, x, Cursor.ISO_8859_1));
} catch (SqlException se) {
throw se.getSQLException();
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java Thu May 30 07:19:54 2013
@@ -28,6 +28,7 @@ import java.io.Reader;
import java.io.StringReader;
import java.math.BigDecimal;
import java.net.URL;
+import java.nio.charset.Charset;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
@@ -3116,7 +3117,8 @@ public abstract class ClientResultSet im
agent_.logWriter_.traceEntry(this, "updateAsciiStream", column, x, length);
}
checkUpdatePreconditions(column, "updateAsciiStream");
- updateColumn(column, agent_.crossConverters_.setObjectFromCharacterStream(resultSetMetaData_.types_[column - 1], x, "ISO-8859-1", length));
+ updateColumn(column, agent_.crossConverters_.setObjectFromCharacterStream(
+ resultSetMetaData_.types_[column - 1], x, Cursor.ISO_8859_1, length));
}
}
catch ( SqlException se )
@@ -5661,7 +5663,7 @@ public abstract class ClientResultSet im
agent_.crossConverters_.setObjectFromCharacterStream(
resultSetMetaData_.types_[columnIndex -1],
x,
- "ISO-8859-1",
+ Cursor.ISO_8859_1,
CrossConverters.UNKNOWN_LENGTH));
} catch (SqlException se) {
throw se.getSQLException();
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/CrossConverters.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/CrossConverters.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/CrossConverters.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/CrossConverters.java Thu May 30 07:19:54 2013
@@ -26,9 +26,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.nio.charset.Charset;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
@@ -807,7 +807,7 @@ final class CrossConverters {
final Object setObjectFromCharacterStream(
int targetType,
InputStream source,
- String encoding,
+ Charset encoding,
int length) throws SqlException {
switch (targetType) {
@@ -835,10 +835,9 @@ final class CrossConverters {
// create a String by reading all of the bytes from inputStream, applying encoding
private String setStringFromStream(
InputStream is,
- String encoding,
+ Charset encoding,
int length) throws SqlException {
- try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int totalRead = 0;
@@ -862,11 +861,6 @@ final class CrossConverters {
}
return new String(baos.toByteArray(), encoding);
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId (SQLState.UNSUPPORTED_ENCODING),
- "java.io.InputStream", "String", e);
- }
}
// Convert from Blob source to target type
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Cursor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Cursor.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Cursor.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Cursor.java Thu May 30 07:19:54 2013
@@ -32,8 +32,8 @@ import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.Reader;
import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
+import java.nio.charset.Charset;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
@@ -65,6 +65,11 @@ public abstract class Cursor {
// unused protocol element: VARIABLE_SHORT_BYTES = 6;
public final static int NULL_TERMINATED_BYTES = 7;
+ // Charsets
+ static final Charset UTF_16BE = Charset.forName("UTF-16BE");
+ static final Charset UTF_8 = Charset.forName("UTF-8");
+ static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
+
// unused protocol element: SBCS_CLOB = 8;
// unused protocol element: MBCS_CLOB = 9;
// unused protocol element: DBCS_CLOB = 10;
@@ -123,7 +128,7 @@ public abstract class Cursor {
public int[] jdbcTypes_;
public int columns_;
public boolean[] nullable_;
- public String[] charsetName_;
+ public Charset[] charset_;
public boolean[] isNull_;
public int[] fdocaLength_; // this is the max length for
@@ -146,7 +151,7 @@ public abstract class Cursor {
columns_ = numberOfColumns;
nullable_ = new boolean[numberOfColumns];
- charsetName_ = new String[numberOfColumns];
+ charset_ = new Charset[numberOfColumns];
ccsid_ = new int[numberOfColumns];
@@ -372,16 +377,10 @@ public abstract class Cursor {
// Build a java.math.BigDecimal from a fixed point decimal byte representation.
private final BigDecimal get_DECIMAL(int column) throws SqlException {
- try {
- return Decimal.getBigDecimal(dataBuffer_,
- columnDataPosition_[column - 1],
- getColumnPrecision(column - 1),
- getColumnScale(column - 1));
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId (SQLState.UNSUPPORTED_ENCODING),
- "DECIMAL", "java.math.BigDecimal", e);
- }
+ return Decimal.getBigDecimal(dataBuffer_,
+ columnDataPosition_[column - 1],
+ getColumnPrecision(column - 1),
+ getColumnScale(column - 1));
}
@@ -396,10 +395,6 @@ public abstract class Cursor {
throw new SqlException(agent_.logWriter_,
new ClientMessageId (SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE),
"double", e);
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId (SQLState.UNSUPPORTED_ENCODING),
- "DECIMAL", "double", e);
}
}
@@ -419,10 +414,6 @@ public abstract class Cursor {
throw new SqlException(agent_.logWriter_,
new ClientMessageId (SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE),
targetType, e);
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId (SQLState.UNSUPPORTED_ENCODING),
- "DECIMAL", targetType, e);
}
}
@@ -433,33 +424,28 @@ public abstract class Cursor {
// for all other cases length is the number of bytes.
// The length does not include the null terminator.
private String getVARCHAR(int column) throws SqlException {
- try {
- if (ccsid_[column - 1] == 1200) {
- return getStringWithoutConvert(columnDataPosition_[column - 1] + 2, columnDataComputedLength_[column - 1] - 2);
- }
-
- // check for null encoding is needed because the net layer
- // will no longer throw an exception if the server didn't specify
- // a mixed or double byte ccsid (ccsid = 0). this check for null in the
- // cursor is only required for types which can have mixed or double
- // byte ccsids.
- if (charsetName_[column - 1] == null) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId(SQLState.CHARACTER_CONVERTER_NOT_AVAILABLE));
- }
+ if (ccsid_[column - 1] == 1200) {
+ return getStringWithoutConvert(columnDataPosition_[column - 1] + 2,
+ columnDataComputedLength_[column - 1] - 2);
+ }
- String tempString = new String(dataBuffer_,
- columnDataPosition_[column - 1] + 2,
- columnDataComputedLength_[column - 1] - 2,
- charsetName_[column - 1]);
- return (maxFieldSize_ == 0) ? tempString :
- tempString.substring(0, Math.min(maxFieldSize_,
- tempString.length()));
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId (SQLState.UNSUPPORTED_ENCODING),
- "VARCHAR", "String", e);
+ // check for null encoding is needed because the net layer
+ // will no longer throw an exception if the server didn't specify
+ // a mixed or double byte ccsid (ccsid = 0). this check for null in the
+ // cursor is only required for types which can have mixed or double
+ // byte ccsids.
+ if (charset_[column - 1] == null) {
+ throw new SqlException(agent_.logWriter_,
+ new ClientMessageId(SQLState.CHARACTER_CONVERTER_NOT_AVAILABLE));
}
+
+ String tempString = new String(dataBuffer_,
+ columnDataPosition_[column - 1] + 2,
+ columnDataComputedLength_[column - 1] - 2,
+ charset_[column - 1]);
+ return (maxFieldSize_ == 0) ? tempString :
+ tempString.substring(0, Math.min(maxFieldSize_,
+ tempString.length()));
}
// Build a Java String from a database CHAR field.
@@ -468,137 +454,86 @@ public abstract class Cursor {
return getStringWithoutConvert(columnDataPosition_[column - 1], columnDataComputedLength_[column - 1]);
}
- try {
- // check for null encoding is needed because the net layer
- // will no longer throw an exception if the server didn't specify
- // a mixed or double byte ccsid (ccsid = 0). this check for null in the
- // cursor is only required for types which can have mixed or double
- // byte ccsids.
- if (charsetName_[column - 1] == null) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId(SQLState.CHARACTER_CONVERTER_NOT_AVAILABLE));
- }
-
- String tempString = new String(dataBuffer_,
- columnDataPosition_[column - 1],
- columnDataComputedLength_[column - 1],
- charsetName_[column - 1]);
- return (maxFieldSize_ == 0) ? tempString :
- tempString.substring(0, Math.min(maxFieldSize_,
- tempString.length()));
- } catch (UnsupportedEncodingException e) {
+ // check for null encoding is needed because the net layer
+ // will no longer throw an exception if the server didn't specify
+ // a mixed or double byte ccsid (ccsid = 0). this check for null in the
+ // cursor is only required for types which can have mixed or double
+ // byte ccsids.
+ if (charset_[column - 1] == null) {
throw new SqlException(agent_.logWriter_,
- new ClientMessageId (SQLState.UNSUPPORTED_ENCODING),
- "CHAR", "String", e);
+ new ClientMessageId(SQLState.CHARACTER_CONVERTER_NOT_AVAILABLE));
}
+
+ String tempString = new String(dataBuffer_,
+ columnDataPosition_[column - 1],
+ columnDataComputedLength_[column - 1],
+ charset_[column - 1]);
+ return (maxFieldSize_ == 0) ? tempString :
+ tempString.substring(0, Math.min(maxFieldSize_,
+ tempString.length()));
}
// Build a JDBC Date object from the DERBY ISO DATE field.
private Date getDATE(int column, Calendar cal) throws SqlException {
- try {
- return DateTime.dateBytesToDate(dataBuffer_,
- columnDataPosition_[column - 1],
- cal,
- charsetName_[column - 1]);
- }catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "DATE", "java.sql.Date", e);
- }
-
-
+ return DateTime.dateBytesToDate(dataBuffer_,
+ columnDataPosition_[column - 1],
+ cal,
+ charset_[column - 1]);
}
// Build a JDBC Time object from the DERBY ISO TIME field.
private Time getTIME(int column, Calendar cal) throws SqlException {
- try {
- return DateTime.timeBytesToTime(dataBuffer_,
- columnDataPosition_[column - 1],
- cal,
- charsetName_[column - 1]);
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "TIME", "java.sql.Time", e);
- }
+ return DateTime.timeBytesToTime(dataBuffer_,
+ columnDataPosition_[column - 1],
+ cal,
+ charset_[column - 1]);
}
// Build a JDBC Timestamp object from the DERBY ISO TIMESTAMP field.
private final Timestamp getTIMESTAMP(int column, Calendar cal)
throws SqlException {
-
- try {
- return DateTime.timestampBytesToTimestamp(
- dataBuffer_,
- columnDataPosition_[column - 1],
- cal,
- charsetName_[column - 1],
- agent_.connection_.serverSupportsTimestampNanoseconds());
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "TIMESTAMP", "java.sql.Timestamp", e);
- }
+ return DateTime.timestampBytesToTimestamp(
+ dataBuffer_,
+ columnDataPosition_[column - 1],
+ cal,
+ charset_[column - 1],
+ agent_.connection_.serverSupportsTimestampNanoseconds());
}
// Build a JDBC Timestamp object from the DERBY ISO DATE field.
private final Timestamp getTimestampFromDATE(
int column, Calendar cal) throws SqlException {
- try {
- return DateTime.dateBytesToTimestamp(dataBuffer_,
- columnDataPosition_[column - 1],
- cal,
- charsetName_[column -1]);
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "DATE", "java.sql.Timestamp", e);
- }
+ return DateTime.dateBytesToTimestamp(dataBuffer_,
+ columnDataPosition_[column - 1],
+ cal,
+ charset_[column -1]);
}
// Build a JDBC Timestamp object from the DERBY ISO TIME field.
private final Timestamp getTimestampFromTIME(
int column, Calendar cal) throws SqlException {
- try {
- return DateTime.timeBytesToTimestamp(dataBuffer_,
- columnDataPosition_[column - 1],
- cal,
- charsetName_[column -1]);
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "TIME", "java.sql.Timestamp", e);
- }
+ return DateTime.timeBytesToTimestamp(dataBuffer_,
+ columnDataPosition_[column - 1],
+ cal,
+ charset_[column -1]);
}
// Build a JDBC Date object from the DERBY ISO TIMESTAMP field.
private final Date getDateFromTIMESTAMP(int column, Calendar cal)
throws SqlException {
- try {
- return DateTime.timestampBytesToDate(dataBuffer_,
- columnDataPosition_[column - 1],
- cal,
- charsetName_[column -1]);
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "TIMESTAMP", "java.sql.Date", e);
- }
+ return DateTime.timestampBytesToDate(dataBuffer_,
+ columnDataPosition_[column - 1],
+ cal,
+ charset_[column -1]);
}
// Build a JDBC Time object from the DERBY ISO TIMESTAMP field.
private final Time getTimeFromTIMESTAMP(int column, Calendar cal)
throws SqlException {
- try {
- return DateTime.timestampBytesToTime(dataBuffer_,
- columnDataPosition_[column - 1],
- cal,
- charsetName_[column -1]);
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "TIMESTAMP", "java.sql.Time", e);
- }
+ return DateTime.timestampBytesToTime(dataBuffer_,
+ columnDataPosition_[column - 1],
+ cal,
+ charset_[column -1]);
}
private String getStringFromDATE(int column) throws SqlException {
@@ -1145,24 +1080,12 @@ public abstract class Cursor {
return c.getAsciiStreamX();
}
case Types.CHAR:
- try {
- return new ByteArrayInputStream(
- getCHAR(column).getBytes("ISO-8859-1"));
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId (SQLState.UNSUPPORTED_ENCODING),
- "CHAR", "java.io.InputStream", e);
- }
+ return new ByteArrayInputStream(
+ getCHAR(column).getBytes(ISO_8859_1));
case Types.VARCHAR:
case Types.LONGVARCHAR:
- try {
- return new ByteArrayInputStream(
- getVARCHAR(column).getBytes("ISO-8859-1"));
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId (SQLState.UNSUPPORTED_ENCODING),
- "VARCHAR/LONGVARCHAR", "java.io.InputStream", e);
- }
+ return new ByteArrayInputStream(
+ getVARCHAR(column).getBytes(ISO_8859_1));
case Types.BINARY:
return new ByteArrayInputStream(get_CHAR_FOR_BIT_DATA(column));
case Types.VARBINARY:
@@ -1195,35 +1118,16 @@ public abstract class Cursor {
case Types.LONGVARCHAR:
return new StringReader(getVARCHAR(column));
case Types.BINARY:
- try {
- return new InputStreamReader(
- new ByteArrayInputStream(
- get_CHAR_FOR_BIT_DATA(column)), "UTF-16BE");
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId (SQLState.UNSUPPORTED_ENCODING),
- "BINARY", "java.io.Reader", e);
- }
+ return new InputStreamReader(
+ new ByteArrayInputStream(
+ get_CHAR_FOR_BIT_DATA(column)), UTF_16BE);
case Types.VARBINARY:
case Types.LONGVARBINARY:
- try {
- return new InputStreamReader(
- new ByteArrayInputStream(
- get_VARCHAR_FOR_BIT_DATA(column)), "UTF-16BE");
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId (SQLState.UNSUPPORTED_ENCODING),
- "VARBINARY/LONGVARBINARY", "java.io.Reader", e);
- }
+ return new InputStreamReader(
+ new ByteArrayInputStream(
+ get_VARCHAR_FOR_BIT_DATA(column)), UTF_16BE);
case Types.BLOB:
- try {
- return new InputStreamReader(getBinaryStream(column),
- "UTF-16BE");
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(agent_.logWriter_,
- new ClientMessageId (SQLState.UNSUPPORTED_ENCODING),
- "BLOB", "java.io.Reader", e);
- }
+ return new InputStreamReader(getBinaryStream(column), UTF_16BE);
default:
throw coercionError( "java.io.Reader", column );
}
@@ -1352,7 +1256,7 @@ public abstract class Cursor {
columnDataIsNullCache_ = null;
jdbcTypes_ = null;
nullable_ = null;
- charsetName_ = null;
+ charset_ = null;
this.ccsid_ = null;
isUpdateDeleteHoleCache_ = null;
isNull_ = null;
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/DateTime.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/DateTime.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/DateTime.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/DateTime.java Thu May 30 07:19:54 2013
@@ -23,7 +23,7 @@ package org.apache.derby.client.am;
import org.apache.derby.shared.common.reference.SQLState;
import org.apache.derby.iapi.reference.DRDAConstants;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
@@ -64,12 +64,11 @@ public class DateTime {
* @param recyclableCal
* @param encoding encoding of buffer data
* @return Date translated from buffer with specified encoding
- * @throws UnsupportedEncodingException
*/
static final Date dateBytesToDate(byte[] buffer,
int offset,
Calendar recyclableCal,
- String encoding) throws UnsupportedEncodingException {
+ Charset encoding) {
int year, month, day;
@@ -118,13 +117,12 @@ public class DateTime {
* @param recyclableCal
* @param encoding encoding of buffer
* @return Time translated from buffer with specified encoding
- * @throws UnsupportedEncodingException
*/
static final Time timeBytesToTime(byte[] buffer,
- int offset,
- Calendar recyclableCal,
- String encoding)
- throws UnsupportedEncodingException {
+ int offset,
+ Calendar recyclableCal,
+ Charset encoding)
+ {
int hour, minute, second;
String time = new String(buffer, offset,
@@ -158,14 +156,10 @@ public class DateTime {
* @param encoding encoding of buffer
* @param supportsTimestampNanoseconds true if the server supports nanoseconds in timestamps
* @return TimeStamp translated from buffer with specified encoding
- * @throws UnsupportedEncodingException
*/
- static final Timestamp timestampBytesToTimestamp(byte[] buffer,
- int offset,
- Calendar recyclableCal,
- String encoding,
- boolean supportsTimestampNanoseconds)
- throws UnsupportedEncodingException
+ static final Timestamp timestampBytesToTimestamp(
+ byte[] buffer, int offset, Calendar recyclableCal,
+ Charset encoding, boolean supportsTimestampNanoseconds)
{
int year, month, day, hour, minute, second, fraction;
String timestamp = new String
@@ -263,12 +257,11 @@ public class DateTime {
* @return DateTime.dateRepresentationLength. This is the fixed length in
* bytes taken to represent the date value
* @throws SqlException
- * @throws UnsupportedEncodingException if UTF8 Encoding is not supported
*/
public static final int dateToDateBytes(byte[] buffer,
int offset,
DateTimeValue date)
- throws SqlException,UnsupportedEncodingException {
+ throws SqlException {
int year = date.getYear();
if (year > 9999) {
throw new SqlException(null,
@@ -310,12 +303,11 @@ public class DateTime {
* @param time java.sql.Time value
* @return DateTime.timeRepresentationLength. This is the fixed length in
* bytes taken to represent the time value
- * @throws UnsupportedEncodingException
*/
public static final int timeToTimeBytes(byte[] buffer,
int offset,
DateTimeValue time)
- throws UnsupportedEncodingException {
+ {
int hour = time.getHours();
int minute = time.getMinutes();
int second = time.getSeconds();
@@ -349,13 +341,12 @@ public class DateTime {
* @param supportsTimestampNanoseconds true if the server supports nanoseconds in timestamps
* @return DateTime.timestampRepresentationLength. This is the fixed length in bytes, taken to represent the timestamp value
* @throws SqlException
- * @throws UnsupportedEncodingException
*/
public static final int timestampToTimestampBytes(byte[] buffer,
int offset,
DateTimeValue timestamp,
boolean supportsTimestampNanoseconds)
- throws SqlException,UnsupportedEncodingException {
+ throws SqlException {
int year = timestamp.getYear();
if (year > 9999) {
throw new SqlException(null,
@@ -433,13 +424,12 @@ public class DateTime {
* @param recyclableCal
* @param encoding encoding of buffer
* @return Timestamp translated from buffer with specified encoding
- * @throws UnsupportedEncodingException
*/
static final Timestamp dateBytesToTimestamp(byte[] buffer,
int offset,
Calendar recyclableCal,
- String encoding)
- throws UnsupportedEncodingException {
+ Charset encoding)
+ {
int year, month, day;
String date = new String(buffer, offset, DateTime.dateRepresentationLength,
@@ -484,14 +474,13 @@ public class DateTime {
* @param recyclableCal
* @param encoding encoding of buffer
* @return Timestamp translated from buffer with specified encoding
- * @throws UnsupportedEncodingException
*
*/
static final Timestamp timeBytesToTimestamp(byte[] buffer,
- int offset,
- Calendar recyclableCal,
- String encoding)
- throws UnsupportedEncodingException {
+ int offset,
+ Calendar recyclableCal,
+ Charset encoding)
+{
int hour, minute, second;
String time = new String(buffer, offset,
@@ -536,13 +525,11 @@ public class DateTime {
* @param recyclableCal
* @param encoding encoding of buffer
* @return Date translated from buffer with specified encoding
- * @throws UnsupportedEncodingException
*/
static final Date timestampBytesToDate(byte[] buffer,
- int offset,
- Calendar recyclableCal,
- String encoding)
- throws UnsupportedEncodingException
+ int offset,
+ Calendar recyclableCal,
+ Charset encoding)
{
int year, month, day;
@@ -578,13 +565,11 @@ public class DateTime {
* @param recyclableCal
* @param encoding encoding of buffer
* @return Time translated from buffer with specified Encoding
- * @throws UnsupportedEncodingException
*/
static final Time timestampBytesToTime(byte[] buffer,
- int offset,
- Calendar recyclableCal,
- String encoding)
- throws UnsupportedEncodingException
+ int offset,
+ Calendar recyclableCal,
+ Charset encoding)
{
/* When getting a java.sql.Time object from a TIMESTAMP value we
* need to preserve the milliseconds from the timestamp.
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Decimal.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Decimal.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Decimal.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Decimal.java Thu May 30 07:19:54 2013
@@ -20,7 +20,6 @@
*/
package org.apache.derby.client.am;
-import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import org.apache.derby.shared.common.reference.SQLState;
@@ -151,7 +150,7 @@ public class Decimal {
byte[] buffer,
int offset,
int precision,
- int scale) throws UnsupportedEncodingException {
+ int scale) {
// The byte-length of a packed decimal with precision <code>p</code> is always <code>p/2 + 1</code>
int length = precision / 2 + 1;
@@ -247,7 +246,7 @@ public class Decimal {
byte[] buffer,
int offset,
int precision,
- int scale) throws UnsupportedEncodingException {
+ int scale) {
// The byte-length of a packed decimal with precision <code>p</code> is always <code>p/2 + 1</code>
int length = precision / 2 + 1;
@@ -312,7 +311,7 @@ public class Decimal {
byte[] buffer,
int offset,
int precision,
- int scale) throws UnsupportedEncodingException {
+ int scale) {
if (precision > 31) {
// throw an exception here if nibbles is greater than 31
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java Thu May 30 07:19:54 2013
@@ -21,7 +21,6 @@
package org.apache.derby.client.am;
-import java.io.UnsupportedEncodingException;
import java.sql.DataTruncation;
import java.sql.Types;
import java.util.Locale;
@@ -208,15 +207,8 @@ public abstract class Sqlca {
return null;
}
- try {
- sqlErrp_ = bytes2String(sqlErrpBytes_,
- 0,
- sqlErrpBytes_.length);
- return sqlErrp_;
- } catch (UnsupportedEncodingException e) {
- // leave sqlErrp as null.
- return null;
- }
+ sqlErrp_ = bytes2String(sqlErrpBytes_, 0, sqlErrpBytes_.length);
+ return sqlErrp_;
}
private int[] getSqlErrd() {
@@ -237,12 +229,7 @@ public abstract class Sqlca {
synchronized public String getSqlWarn() {
if (sqlWarn_ == null) {
if (sqlWarnBytes_ != null) {
- try {
- sqlWarn_ =
- bytes2String(sqlWarnBytes_, 0, sqlWarnBytes_.length);
- } catch (UnsupportedEncodingException e) {
- sqlWarn_ = elevenBlanks;
- }
+ sqlWarn_ = bytes2String(sqlWarnBytes_, 0, sqlWarnBytes_.length);
} else {
sqlWarn_ = elevenBlanks;
}
@@ -445,30 +432,25 @@ public abstract class Sqlca {
return;
}
- try {
- // tokenize and convert tokenBytes
- String fullString = bytes2String(tokenBytes, 0, length);
- String[] tokens = fullString.split("\\u0014{3}");
- String[] states = new String[tokens.length];
- states[0] = getSqlState();
- for (int i = 1; i < tokens.length; i++) {
- // All but the first message are preceded by the SQL state
- // (five characters) and a colon. Extract the SQL state and
- // clean up the token. See
- // DRDAConnThread.buildTokenizedSqlerrmc() for more details.
- int colonpos = tokens[i].indexOf(":");
- states[i] = tokens[i].substring(0, colonpos);
- tokens[i] = tokens[i].substring(colonpos + 1);
- }
- sqlStates_ = states;
- sqlErrmcMessages_ = tokens;
- } catch (UnsupportedEncodingException e) {
- /* do nothing, the arrays continue to be null */
+ // tokenize and convert tokenBytes
+ String fullString = bytes2String(tokenBytes, 0, length);
+ String[] tokens = fullString.split("\\u0014{3}");
+ String[] states = new String[tokens.length];
+ states[0] = getSqlState();
+ for (int i = 1; i < tokens.length; i++) {
+ // All but the first message are preceded by the SQL state
+ // (five characters) and a colon. Extract the SQL state and
+ // clean up the token. See
+ // DRDAConnThread.buildTokenizedSqlerrmc() for more details.
+ int colonpos = tokens[i].indexOf(":");
+ states[i] = tokens[i].substring(0, colonpos);
+ tokens[i] = tokens[i].substring(colonpos + 1);
}
+ sqlStates_ = states;
+ sqlErrmcMessages_ = tokens;
}
- protected String bytes2String(byte[] bytes, int offset, int length)
- throws UnsupportedEncodingException {
+ protected String bytes2String(byte[] bytes, int offset, int length) {
// Network server uses utf8 encoding
return new String(bytes, offset, length, Typdef.UTF8ENCODING);
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/EncodedInputStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/EncodedInputStream.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/EncodedInputStream.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/EncodedInputStream.java Thu May 30 07:19:54 2013
@@ -26,9 +26,7 @@ import java.io.OutputStreamWriter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-
-import org.apache.derby.shared.common.sanity.SanityManager;
+import java.nio.charset.Charset;
/**
* Create an encoded stream from a <code>Reader</code>.
@@ -45,6 +43,9 @@ import org.apache.derby.shared.common.sa
*/
public final class EncodedInputStream extends InputStream {
+ private static final Charset UTF_8 = Charset.forName("UTF-8");
+ private static final Charset UTF_16BE = Charset.forName("UTF-16BE");
+
/**
* Create a UTF-8 encoded stream from the given <code>Reader</code>.
*
@@ -53,7 +54,7 @@ public final class EncodedInputStream ex
*/
public static EncodedInputStream createUTF8Stream(Reader reader) {
return new EncodedInputStream(reader,
- "UTF8",
+ UTF_8,
BUFFERED_CHAR_LEN,
BUFFERED_CHAR_LEN*3);
}
@@ -66,7 +67,7 @@ public final class EncodedInputStream ex
*/
static EncodedInputStream createUTF16BEStream(Reader reader) {
return new EncodedInputStream(reader,
- "UTF-16BE",
+ UTF_16BE,
BUFFERED_CHAR_LEN,
BUFFERED_CHAR_LEN*2);
}
@@ -93,7 +94,7 @@ public final class EncodedInputStream ex
* holding the encoded bytes
*/
private EncodedInputStream(Reader reader,
- String encoding,
+ Charset encoding,
int charBufferSize,
int initialByteBufferSize) {
@@ -103,19 +104,9 @@ public final class EncodedInputStream ex
encodedOutputStream_ = new PublicBufferOutputStream(
initialByteBufferSize);
- try{
- encodedStreamWriter_ = new OutputStreamWriter(encodedOutputStream_,
- encoding);
-
- }catch(UnsupportedEncodingException e){
- // Should never happen. It is up to the caller to ensure the
- // specified encoding is available.
- if (SanityManager.DEBUG) {
- SanityManager.THROWASSERT("Unavailable encoding specified: " +
- encoding, e);
- }
- }
-
+ encodedStreamWriter_ =
+ new OutputStreamWriter(encodedOutputStream_, encoding);
+
encodedInputStream_ = suspendMarker;
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java Thu May 30 07:19:54 2013
@@ -3290,7 +3290,7 @@ class NetConnectionReply extends Reply
case CodePoint.PBSD_SCHEMA:
netAgent_.netConnection_.
completeInitialPiggyBackSchema
- (readString(getDdmLength(), "UTF-8"));
+ (readString(getDdmLength(), Typdef.UTF8ENCODING));
break;
default:
parseCommonError(peekCP);
@@ -3319,7 +3319,7 @@ class NetConnectionReply extends Reply
case CodePoint.PBSD_SCHEMA:
netAgent_.netConnection_.
completePiggyBackSchema
- (readString(getDdmLength(), "UTF-8"));
+ (readString(getDdmLength(), Typdef.UTF8ENCODING));
break;
default:
parseCommonError(peekCP);
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java Thu May 30 07:19:54 2013
@@ -21,7 +21,7 @@
package org.apache.derby.client.net;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
@@ -863,25 +863,15 @@ class NetCursor extends Cursor {
}
// This is not used for column data.
- private String readFdocaString(int length, String encoding) throws DisconnectException, SqlException {
+ private String readFdocaString(int length, Charset encoding)
+ throws SqlException {
if (length == 0) {
return null;
}
checkForSplitRowAndComplete(length);
- String s = null;
-
- try {
- s = new String(dataBuffer_, position_, length, encoding);
- } catch (UnsupportedEncodingException e) {
- netAgent_.accumulateChainBreakingReadExceptionAndThrow(
- new DisconnectException(
- netAgent_,
- new ClientMessageId(SQLState.NET_ENCODING_NOT_SUPPORTED),
- e));
- }
-
+ String s = new String(dataBuffer_, position_, length, encoding);
position_ += length;
return s;
}
@@ -1010,7 +1000,7 @@ class NetCursor extends Cursor {
} else {
dataOffset = 1;
}
- clob = new ClientClob(agent, data, charsetName_[index], dataOffset);
+ clob = new ClientClob(agent, data, charset_[index], dataOffset);
} else {
// the locator is not valid, it is a zero-length LOB
clob = new ClientClob(agent, "");
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPackageRequest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPackageRequest.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPackageRequest.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetPackageRequest.java Thu May 30 07:19:54 2013
@@ -166,30 +166,20 @@ class NetPackageRequest extends NetConne
return (length > lengthRequiringScldta);
}
- private byte[] getBytes(String string, String encoding) throws SqlException {
- try {
- return string.getBytes(encoding);
- } catch (Exception e) {
- throw new SqlException(netAgent_.logWriter_,
- new ClientMessageId(SQLState.JAVA_EXCEPTION),
- e.getClass().getName(), e.getMessage(), e);
- }
- }
-
private void buildNOCMorNOCS(String string) throws SqlException {
if (string == null) {
write2Bytes(0xffff);
} else {
- byte[] sqlBytes;
-
if (netAgent_.typdef_.isCcsidMbcSet()) {
- sqlBytes = getBytes(string, netAgent_.typdef_.getCcsidMbcEncoding());
+ byte[] sqlBytes =
+ string.getBytes(netAgent_.typdef_.getCcsidMbcEncoding());
write1Byte(0x00);
write4Bytes(sqlBytes.length);
writeBytes(sqlBytes, sqlBytes.length);
write1Byte(0xff);
} else {
- sqlBytes = getBytes(string, netAgent_.typdef_.getCcsidSbcEncoding());
+ byte[] sqlBytes =
+ string.getBytes(netAgent_.typdef_.getCcsidSbcEncoding());
write1Byte(0xff);
write1Byte(0x00);
write4Bytes(sqlBytes.length);
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetSqlca.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetSqlca.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetSqlca.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetSqlca.java Thu May 30 07:19:54 2013
@@ -22,10 +22,6 @@
package org.apache.derby.client.net;
import org.apache.derby.client.am.Sqlca;
-import org.apache.derby.shared.common.reference.SQLState;
-import org.apache.derby.client.am.ClientMessageId;
-import org.apache.derby.client.am.SqlException;
-import java.io.UnsupportedEncodingException;
import org.apache.derby.client.am.ClientConnection;
class NetSqlca extends Sqlca {
@@ -45,18 +41,10 @@ class NetSqlca extends Sqlca {
NetSqlca(ClientConnection connection,
int sqlCode,
byte[] sqlState,
- byte[] sqlErrpBytes) throws SqlException {
+ byte[] sqlErrpBytes) {
super(connection);
sqlCode_ = sqlCode;
- try
- {
- sqlState_ = bytes2String(sqlState,0,sqlState.length);
- }catch(UnsupportedEncodingException uee)
- {
- throw new SqlException(null,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "sqlstate bytes", "SQLSTATE",uee);
- }
+ sqlState_ = bytes2String(sqlState,0,sqlState.length);
sqlErrpBytes_ = sqlErrpBytes;
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetStatementRequest.java Thu May 30 07:19:54 2013
@@ -21,7 +21,6 @@
package org.apache.derby.client.net;
import java.io.ByteArrayInputStream;
-import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.sql.Blob;
import java.sql.Clob;
@@ -1221,34 +1220,25 @@ class NetStatementRequest extends NetPac
lidAndLengths[i][1] = 32767;
} else {
// Flow the data as CLOB data if the data too large to for LONGVARCHAR
- ByteArrayInputStream bais = null;
- byte[] ba = null;
- try {
- ba = s.getBytes("UTF-8");
- bais = new ByteArrayInputStream(ba);
- ClientClob c = new ClientClob(
- netAgent_, bais, "UTF-8", ba.length);
- // inputRow[i] = c;
- // Place the new Lob in the promototedParameter_ collection for
- // NetStatementRequest use
- promototedParameters_.put(i, c);
-
- lidAndLengths[i][0] = DRDAConstants.DRDA_TYPE_NLOBCMIXED;
+ byte[] ba = s.getBytes(Typdef.UTF8ENCODING);
+ ByteArrayInputStream bais = new ByteArrayInputStream(ba);
+ ClientClob c = new ClientClob(
+ netAgent_, bais, Typdef.UTF8ENCODING, ba.length);
+ // inputRow[i] = c;
+ // Place the new Lob in the promototedParameter_ collection for
+ // NetStatementRequest use
+ promototedParameters_.put(i, c);
+
+ lidAndLengths[i][0] = DRDAConstants.DRDA_TYPE_NLOBCMIXED;
+
+ if( c.willBeLayerBStreamed() ){
+
+ //Correspond to totalLength 0 as default length for unknown
+ lidAndLengths[i][1] = 0x8002;
+
+ }else {
+ lidAndLengths[i][1] = buildPlaceholderLength(c.length());
- if( c.willBeLayerBStreamed() ){
-
- //Correspond to totalLength 0 as default length for unknown
- lidAndLengths[i][1] = 0x8002;
-
- }else {
- lidAndLengths[i][1] = buildPlaceholderLength(c.length());
-
- }
-
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(netAgent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "byte array", "Clob", e);
}
}
break;
@@ -1369,26 +1359,18 @@ class NetStatementRequest extends NetPac
lidAndLengths[i][1] = 32767;
} else {
// Flow the data as CLOB data if the data too large to for LONGVARCHAR
- ByteArrayInputStream bais = null;
- byte[] ba = null;
- try {
- ba = s.getBytes("UTF-8");
- bais = new ByteArrayInputStream(ba);
- ClientClob c = new ClientClob(
- netAgent_, bais, "UTF-8", ba.length);
-
- // inputRow[i] = c;
- // Place the new Lob in the promototedParameter_ collection for
- // NetStatementRequest use
- promototedParameters_.put(i, c);
+ byte[] ba = s.getBytes(Typdef.UTF8ENCODING);
+ ByteArrayInputStream bais = new ByteArrayInputStream(ba);
+ ClientClob c = new ClientClob(
+ netAgent_, bais, Typdef.UTF8ENCODING, ba.length);
- lidAndLengths[i][0] = DRDAConstants.DRDA_TYPE_NLOBCMIXED;
- lidAndLengths[i][1] = buildPlaceholderLength(c.length());
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(netAgent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "byte array", "Clob");
- }
+ // inputRow[i] = c;
+ // Place the new Lob in the promototedParameter_ collection for
+ // NetStatementRequest use
+ promototedParameters_.put(i, c);
+
+ lidAndLengths[i][0] = DRDAConstants.DRDA_TYPE_NLOBCMIXED;
+ lidAndLengths[i][1] = buildPlaceholderLength(c.length());
}
break;
case Types.BINARY:
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/Reply.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/Reply.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/Reply.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/Reply.java Thu May 30 07:19:54 2013
@@ -24,7 +24,7 @@ package org.apache.derby.client.net;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.util.Arrays;
import org.apache.derby.client.am.Agent;
@@ -632,20 +632,11 @@ class Reply {
return (byte) (buffer_[pos_++] & 0xff);
}
- final String readString(int length, String encoding) throws DisconnectException {
+ final String readString(int length, Charset encoding)
+ throws DisconnectException {
ensureBLayerDataInBuffer(length);
adjustLengths(length);
- String s = null;
-
- try {
- s = new String(buffer_, pos_, length, encoding);
- } catch (UnsupportedEncodingException e) {
- agent_.accumulateChainBreakingReadExceptionAndThrow(
- new DisconnectException(agent_,
- new ClientMessageId(SQLState.NET_ENCODING_NOT_SUPPORTED),
- e));
- }
-
+ String s = new String(buffer_, pos_, length, encoding);
pos_ += length;
return s;
}
@@ -1216,17 +1207,8 @@ class Reply {
}
}
- final String readFastString(int length, String encoding) throws DisconnectException {
- String s = null;
-
- try {
- s = new String(buffer_, pos_, length, encoding);
- } catch (UnsupportedEncodingException e) {
- agent_.accumulateChainBreakingReadExceptionAndThrow(
- new DisconnectException(agent_,
- new ClientMessageId(SQLState.NET_ENCODING_NOT_SUPPORTED),
- e));
- }
+ final String readFastString(int length, Charset encoding) {
+ String s = new String(buffer_, pos_, length, encoding);
pos_ += length;
return s;
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/Request.java Thu May 30 07:19:54 2013
@@ -36,10 +36,10 @@ import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Reader;
-import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
+import java.nio.charset.Charset;
import java.util.Hashtable;
@@ -1297,44 +1297,25 @@ class Request {
}
final void writeDate(DateTimeValue date) throws SqlException {
- try
- {
- ensureLength(10);
- DateTime.dateToDateBytes(buffer.array(), buffer.position(), date);
- buffer.position(buffer.position() + 10);
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(netAgent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "java.sql.Date", "DATE", e);
- }
+ ensureLength(10);
+ DateTime.dateToDateBytes(buffer.array(), buffer.position(), date);
+ buffer.position(buffer.position() + 10);
}
- final void writeTime(DateTimeValue time) throws SqlException {
- try{
- ensureLength(8);
- DateTime.timeToTimeBytes(buffer.array(), buffer.position(), time);
- buffer.position(buffer.position() + 8);
- } catch(UnsupportedEncodingException e) {
- throw new SqlException(netAgent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "java.sql.Time", "TIME", e);
- }
+ final void writeTime(DateTimeValue time) {
+ ensureLength(8);
+ DateTime.timeToTimeBytes(buffer.array(), buffer.position(), time);
+ buffer.position(buffer.position() + 8);
}
final void writeTimestamp(DateTimeValue timestamp) throws SqlException {
- try{
- boolean supportsTimestampNanoseconds = netAgent_.netConnection_.serverSupportsTimestampNanoseconds();
- int length = DateTime.getTimestampLength( supportsTimestampNanoseconds );
- ensureLength(length);
- DateTime.timestampToTimestampBytes(
- buffer.array(), buffer.position(),
- timestamp, supportsTimestampNanoseconds);
- buffer.position(buffer.position() + length);
- }catch(UnsupportedEncodingException e) {
- throw new SqlException(netAgent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "java.sql.Timestamp", "TIMESTAMP", e);
- }
+ boolean supportsTimestampNanoseconds = netAgent_.netConnection_.serverSupportsTimestampNanoseconds();
+ int length = DateTime.getTimestampLength( supportsTimestampNanoseconds );
+ ensureLength(length);
+ DateTime.timestampToTimestampBytes(
+ buffer.array(), buffer.position(),
+ timestamp, supportsTimestampNanoseconds);
+ buffer.position(buffer.position() + length);
}
// insert a java boolean into the buffer. the boolean is written
@@ -1348,15 +1329,8 @@ class Request {
// should this throw SqlException
// Will write a varchar mixed or single
// this was writeLDString
- final void writeSingleorMixedCcsidLDString(String s, String encoding) throws SqlException {
- byte[] b;
- try {
- b = s.getBytes(encoding);
- } catch (UnsupportedEncodingException e) {
- throw new SqlException(netAgent_.logWriter_,
- new ClientMessageId(SQLState.UNSUPPORTED_ENCODING),
- "String", "byte", e);
- }
+ final void writeSingleorMixedCcsidLDString(String s, Charset encoding) throws SqlException {
+ byte[] b = s.getBytes(encoding);
if (b.length > 0x7FFF) {
throw new SqlException(netAgent_.logWriter_,
new ClientMessageId(SQLState.LANG_STRING_TOO_LONG),
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/Typdef.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/Typdef.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/Typdef.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/Typdef.java Thu May 30 07:19:54 2013
@@ -21,6 +21,7 @@
package org.apache.derby.client.net;
+import java.nio.charset.Charset;
import java.sql.Types;
import org.apache.derby.client.am.Cursor;
import org.apache.derby.client.am.DisconnectException;
@@ -157,7 +158,7 @@ public class Typdef implements Cloneable
// lob length
static final short LOBLENGTH = 4;
- public static final String UTF8ENCODING = "UTF8";
+ public static final Charset UTF8ENCODING = Charset.forName("UTF-8");
private static final int OVERRIDE_TABLE_SIZE = 0xff;
@@ -902,16 +903,16 @@ public class Typdef implements Cloneable
private int ccsidSbc_;
private boolean ccsidSbcSet_;
- private String ccsidSbcEncoding_;
+ private Charset ccsidSbcEncoding_;
private int ccsidDbc_;
private boolean ccsidDbcSet_;
- private String ccsidDbcEncoding_;
+ private Charset ccsidDbcEncoding_;
private int ccsidMbc_;
private boolean ccsidMbcSet_;
- private String ccsidMbcEncoding_;
+ private Charset ccsidMbcEncoding_;
private boolean mddOverride_ = false;
@@ -983,7 +984,7 @@ public class Typdef implements Cloneable
}
// analyze exception handling some more here
- String getCcsidSbcEncoding() throws DisconnectException {
+ Charset getCcsidSbcEncoding() throws DisconnectException {
if (ccsidSbcEncoding_ == null) {
ccsidSbcEncoding_ = UTF8ENCODING;
}
@@ -1005,7 +1006,7 @@ public class Typdef implements Cloneable
}
// analyze exception handling some more here
- private String getCcsidDbcEncoding() throws DisconnectException {
+ private Charset getCcsidDbcEncoding() throws DisconnectException {
if (ccsidDbcEncoding_ == null) {
ccsidDbcEncoding_ = UTF8ENCODING;
}
@@ -1027,7 +1028,7 @@ public class Typdef implements Cloneable
}
// analyze exception handling some more here
- String getCcsidMbcEncoding() throws DisconnectException {
+ Charset getCcsidMbcEncoding() throws DisconnectException {
if (ccsidMbcEncoding_ == null) {
ccsidMbcEncoding_ = UTF8ENCODING;
}
@@ -1068,30 +1069,30 @@ public class Typdef implements Cloneable
// The typdef object should store the java encoding,
switch (sda.ccsid_) {
case CCSIDSBC:
- netCursor.charsetName_[columnIndex] = getCcsidSbcEncoding();
+ netCursor.charset_[columnIndex] = getCcsidSbcEncoding();
netCursor.ccsid_[columnIndex] = this.ccsidSbc_;
break;
case CCSIDMBC:
if (isCcsidMbcSet() && (ccsidMbc_ != 0)) {
- netCursor.charsetName_[columnIndex] = getCcsidMbcEncoding();
+ netCursor.charset_[columnIndex] = getCcsidMbcEncoding();
netCursor.ccsid_[columnIndex] = ccsidMbc_;
} else {
// if the server didn't return a mixed byte ccsid, set both the
// encoding and the btc reference to null. see CCSIDDBC comment below.
- netCursor.charsetName_[columnIndex] = null;
+ netCursor.charset_[columnIndex] = null;
netCursor.ccsid_[columnIndex] = 0;
}
break;
case CCSIDDBC:
if (isCcsidDbcSet() && (ccsidDbc_ != 0)) {
- netCursor.charsetName_[columnIndex] = getCcsidDbcEncoding();
+ netCursor.charset_[columnIndex] = getCcsidDbcEncoding();
netCursor.ccsid_[columnIndex] = this.ccsidDbc_;
} else {
// if the server didn't return a double byte ccsid, set both the
// encoding and the btc reference to null. later an exception will
// be thrown on the getXXX method. calling the getCcsidDbcEncoding method
// will throw the exception here and this is not desirable.
- netCursor.charsetName_[columnIndex] = null;
+ netCursor.charset_[columnIndex] = null;
netCursor.ccsid_[columnIndex] = 0;
}
break;
@@ -1101,7 +1102,7 @@ public class Typdef implements Cloneable
// otherwise the sda.ccsid_ is a placeholder:
// CCSIDMBC, CCSIDDDBC, CCSIDSBC to indicate that
// the actual ccsid is the connection's ccsid (in protocol lingo the connection's typdef ccsid).
- netCursor.charsetName_[columnIndex] = UTF8ENCODING;
+ netCursor.charset_[columnIndex] = UTF8ENCODING;
netCursor.ccsid_[columnIndex] = sda.ccsid_;
break;
}
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/Utf8CcsidManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/Utf8CcsidManager.java?rev=1487774&r1=1487773&r2=1487774&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/Utf8CcsidManager.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/Utf8CcsidManager.java Thu May 30 07:19:54 2013
@@ -21,7 +21,6 @@
package org.apache.derby.client.net;
-import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
@@ -32,7 +31,6 @@ import java.nio.charset.CoderResult;
import org.apache.derby.client.am.Agent;
import org.apache.derby.client.am.ClientMessageId;
import org.apache.derby.client.am.SqlException;
-import org.apache.derby.shared.common.sanity.SanityManager;
import org.apache.derby.shared.common.reference.SQLState;
public class Utf8CcsidManager extends CcsidManager {
@@ -93,18 +91,7 @@ public class Utf8CcsidManager extends Cc
* Offset and numToConvert are given in terms of bytes! Not characters!
*/
public String convertToJavaString(byte[] sourceBytes, int offset, int numToConvert) {
- try {
- // Here we'd rather specify the encoding using a Charset object to
- // avoid the need to handle UnsupportedEncodingException, but that
- // constructor wasn't introduced until Java 6.
- return new String(sourceBytes, offset, numToConvert, UTF8);
- } catch (UnsupportedEncodingException e) {
- // We don't have an agent in this method
- if (SanityManager.DEBUG) {
- SanityManager.THROWASSERT("Could not convert byte[] to Java String using UTF-8 encoding with offset",e);
- }
- }
- return null;
+ return new String(sourceBytes, offset, numToConvert, UTF8_CHARSET);
}
public void startEncoding() {