Skip to content

Commit

Permalink
Improvements | Use StandardCharsets.US_ASCII in favour of string (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
simon04 authored and cheenamalhotra committed Oct 27, 2018
1 parent cd3891c commit 7679dbe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.sql.Clob;
import java.sql.SQLException;
import java.text.MessageFormat;
Expand Down Expand Up @@ -776,7 +777,7 @@ public void write(byte[] b, int off, int len) throws IOException {
return;
try {
// Convert bytes to string using US-ASCII translation.
String s = new String(b, off, len, "US-ASCII");
String s = new String(b, off, len, StandardCharsets.US_ASCII);

// Call parent's setString and update position.
// setString can throw a SQLServerException, we translate
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/microsoft/sqlserver/jdbc/dtv.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.SQLException;
Expand Down Expand Up @@ -2193,11 +2194,7 @@ void execute(DTV dtv, InputStream inputStreamValue) throws SQLServerException {
// If the stream is to be sent as Unicode, then assume it's an ASCII stream
if (JDBCType.NCHAR == jdbcType || JDBCType.NVARCHAR == jdbcType || JDBCType.LONGNVARCHAR == jdbcType) {
Reader readerValue = null;
try {
readerValue = new InputStreamReader(inputStreamValue, "US-ASCII");
} catch (UnsupportedEncodingException ex) {
throw new SQLServerException(ex.getMessage(), null, 0, ex);
}
readerValue = new InputStreamReader(inputStreamValue, StandardCharsets.US_ASCII);

dtv.setValue(readerValue, JavaType.READER);

Expand Down

0 comments on commit 7679dbe

Please sign in to comment.