Consistent support for Charset/StandardCharsets in UriUtils etc

Issue: SPR-15613
This commit is contained in:
Juergen Hoeller
2017-06-12 15:51:45 +02:00
parent 14161d1dbf
commit 3ae84d6dd8
15 changed files with 244 additions and 171 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.PreparedStatement;
@@ -322,17 +322,12 @@ public class DefaultLobHandler extends AbstractLobHandler {
if (streamAsLob) {
if (asciiStream != null) {
try {
Reader reader = new InputStreamReader(asciiStream, "US-ASCII");
if (contentLength >= 0) {
ps.setClob(paramIndex, reader, contentLength);
}
else {
ps.setClob(paramIndex, reader);
}
Reader reader = new InputStreamReader(asciiStream, StandardCharsets.US_ASCII);
if (contentLength >= 0) {
ps.setClob(paramIndex, reader, contentLength);
}
catch (UnsupportedEncodingException ex) {
throw new SQLException("US-ASCII encoding not supported: " + ex);
else {
ps.setClob(paramIndex, reader);
}
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ 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.StandardCharsets;
import java.sql.Clob;
@@ -72,19 +71,14 @@ class PassThroughClob implements Clob {
@Override
public Reader getCharacterStream() throws SQLException {
try {
if (this.content != null) {
return new StringReader(this.content);
}
else if (this.characterStream != null) {
return this.characterStream;
}
else {
return new InputStreamReader(this.asciiStream, "US-ASCII");
}
if (this.content != null) {
return new StringReader(this.content);
}
catch (UnsupportedEncodingException ex) {
throw new SQLException("US-ASCII encoding not supported: " + ex);
else if (this.characterStream != null) {
return this.characterStream;
}
else {
return new InputStreamReader(this.asciiStream, StandardCharsets.US_ASCII);
}
}
@@ -102,9 +96,6 @@ class PassThroughClob implements Clob {
return this.asciiStream;
}
}
catch (UnsupportedEncodingException ex) {
throw new SQLException("US-ASCII encoding not supported: " + ex);
}
catch (IOException ex) {
throw new SQLException("Failed to read stream content: " + ex);
}