Permalink
Browse files

use Charset instead of String as parameter

  • Loading branch information...
1 parent 33d29a0 commit e0bf22fdde71110b47a6f44c4d16d3845f8fec75 @ropalka ropalka committed Oct 31, 2012
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
+import java.nio.charset.Charset;
import java.util.List;
import org.fossnova.json.stream.JsonException;
@@ -297,11 +298,11 @@
/**
* Serializes this JSON array to the writer using specified character set.
* @param output to write to
- * @param charsetName character set name
+ * @param charset character set
* @throws IOException if some I/O error occurs
* @throws JsonException if wrong JSON is detected
*/
- void writeTo( OutputStream output, String charsetName ) throws IOException, JsonException;
+ void writeTo( OutputStream output, Charset charset ) throws IOException, JsonException;
/**
* Clones this JSON array.
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
+import java.nio.charset.Charset;
import java.util.Map;
import org.fossnova.json.stream.JsonException;
@@ -146,11 +147,11 @@
/**
* Serializes this JSON object to the writer using specified character set.
* @param output to write to
- * @param charsetName character set name
+ * @param charset character set
* @throws IOException if some I/O error occurs
* @throws JsonException if wrong JSON is detected
*/
- void writeTo( OutputStream output, String charsetName ) throws IOException, JsonException;
+ void writeTo( OutputStream output, Charset charset ) throws IOException, JsonException;
/**
* Clones this JSON object.
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
+import java.nio.charset.Charset;
import org.fossnova.finder.FactoryFinder;
import org.fossnova.json.stream.JsonException;
@@ -130,10 +131,10 @@ public static JsonValueFactory newInstance() {
/**
* Creates either JSON array or object instance.
* @param data JSON available via input stream
- * @param charsetName character set name
+ * @param charset character set
* @return JSON array or object instance
* @throws IOException if some I/O error occurs
* @throws JsonException if wrong JSON is detected
*/
- public abstract JsonValue readFrom( InputStream data, String charsetName ) throws IOException, JsonException;
+ public abstract JsonValue readFrom( InputStream data, Charset charset ) throws IOException, JsonException;
}
@@ -22,8 +22,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
-import java.io.UnsupportedEncodingException;
import java.io.Writer;
+import java.nio.charset.Charset;
import org.fossnova.finder.FactoryFinder;
@@ -72,33 +72,29 @@ public static JsonStreamFactory newInstance() {
* Creates new JSON reader with default character set.
* @param stream input
* @return JSON reader instance
- * @throws UnsupportedEncodingException if default character set is not supported
*/
- public abstract JsonReader newJsonReader( InputStream stream ) throws UnsupportedEncodingException;
+ public abstract JsonReader newJsonReader( InputStream stream );
/**
* Creates new JSON writer with default character set.
* @param stream output
* @return JSON writer instance
- * @throws UnsupportedEncodingException if default character set is not supported
*/
- public abstract JsonWriter newJsonWriter( OutputStream stream ) throws UnsupportedEncodingException;
+ public abstract JsonWriter newJsonWriter( OutputStream stream );
/**
* Creates new JSON reader with specified character set.
* @param stream input
- * @param charsetName character set name
+ * @param charset character set
* @return JSON reader instance
- * @throws UnsupportedEncodingException if specified character set is not supported
*/
- public abstract JsonReader newJsonReader( InputStream stream, String charsetName ) throws UnsupportedEncodingException;
+ public abstract JsonReader newJsonReader( InputStream stream, Charset charset );
/**
* Creates new JSON writer with specified character set.
* @param stream output
- * @param charsetName character set name
+ * @param charset character set
* @return JSON writer instance
- * @throws UnsupportedEncodingException if specified character set is not supported
*/
- public abstract JsonWriter newJsonWriter( OutputStream stream, String charsetName ) throws UnsupportedEncodingException;
+ public abstract JsonWriter newJsonWriter( OutputStream stream, Charset charset );
}
@@ -24,6 +24,7 @@
import java.io.Writer;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.nio.charset.Charset;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
@@ -59,8 +60,8 @@ public final void writeTo( final OutputStream output ) throws IOException, JsonE
writeTo( writer );
}
- public final void writeTo( final OutputStream output, final String charsetName ) throws IOException, JsonException {
- final JsonWriter writer = JsonStreamFactory.newInstance().newJsonWriter( output, charsetName );
+ public final void writeTo( final OutputStream output, final Charset charset ) throws IOException, JsonException {
+ final JsonWriter writer = JsonStreamFactory.newInstance().newJsonWriter( output, charset );
writeTo( writer );
}
@@ -34,6 +34,7 @@
import java.io.StringReader;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.nio.charset.Charset;
import org.fossnova.json.JsonValue;
import org.fossnova.json.JsonValueFactory;
@@ -123,8 +124,8 @@ public JsonValue readFrom( final InputStream input ) throws IOException, JsonExc
}
@Override
- public JsonValue readFrom( final InputStream input, final String charsetName ) throws IOException, JsonException {
- final JsonReader reader = JsonStreamFactory.newInstance().newJsonReader( input, charsetName );
+ public JsonValue readFrom( final InputStream input, final Charset charset ) throws IOException, JsonException {
+ final JsonReader reader = JsonStreamFactory.newInstance().newJsonReader( input, charset );
return readFrom( reader );
}
@@ -24,7 +24,6 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
-import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.nio.charset.Charset;
@@ -35,7 +34,7 @@
*/
public final class JsonStreamFactoryImpl extends JsonStreamFactory {
- private static final String DEFAULT_CHARSET = Charset.defaultCharset().name();
+ private static final Charset DEFAULT_CHARSET = Charset.defaultCharset();
public JsonStreamFactoryImpl() {
}
@@ -47,15 +46,15 @@ public JsonReaderImpl newJsonReader( final Reader reader ) {
}
@Override
- public JsonReaderImpl newJsonReader( final InputStream stream ) throws UnsupportedEncodingException {
+ public JsonReaderImpl newJsonReader( final InputStream stream ) {
return newJsonReader( stream, DEFAULT_CHARSET );
}
@Override
- public JsonReaderImpl newJsonReader( final InputStream stream, final String charsetName ) throws UnsupportedEncodingException {
+ public JsonReaderImpl newJsonReader( final InputStream stream, final Charset charset ) {
assertNotNullParameter( stream );
- assertNotNullParameter( charsetName );
- return newJsonReader( new InputStreamReader( stream, charsetName ) );
+ assertNotNullParameter( charset );
+ return newJsonReader( new InputStreamReader( stream, charset ) );
}
@Override
@@ -65,15 +64,15 @@ public JsonWriterImpl newJsonWriter( final Writer writer ) {
}
@Override
- public JsonWriterImpl newJsonWriter( final OutputStream stream ) throws UnsupportedEncodingException {
+ public JsonWriterImpl newJsonWriter( final OutputStream stream ) {
return newJsonWriter( stream, DEFAULT_CHARSET );
}
@Override
- public JsonWriterImpl newJsonWriter( final OutputStream stream, final String charsetName ) throws UnsupportedEncodingException {
+ public JsonWriterImpl newJsonWriter( final OutputStream stream, final Charset charset ) {
assertNotNullParameter( stream );
- assertNotNullParameter( charsetName );
- return newJsonWriter( new OutputStreamWriter( stream, charsetName ) );
+ assertNotNullParameter( charset );
+ return newJsonWriter( new OutputStreamWriter( stream, charset ) );
}
private static void assertNotNullParameter( final Object o ) {
@@ -22,7 +22,6 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -44,7 +43,7 @@
private JsonWriter writer;
@Before
- public void init() throws UnsupportedEncodingException {
+ public void init() {
baos = new ByteArrayOutputStream();
writer = JsonStreamFactory.newInstance().newJsonWriter( new OutputStreamWriter( baos ) );
}
@@ -239,7 +238,7 @@ public void controlsEncoding() throws IOException, JsonException {
Assert.assertEquals( expected, getWriterOutput() );
}
- private String getWriterOutput() throws UnsupportedEncodingException {
- return baos.toString( "UTF-8" );
+ private String getWriterOutput() {
+ return baos.toString();
}
}

0 comments on commit e0bf22f

Please sign in to comment.