git://git.nikiroo.be
/
fanfix.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
code cleanup + fixes
[fanfix.git]
/
src
/
be
/
nikiroo
/
utils
/
serial
/
SerialUtils.java
diff --git
a/src/be/nikiroo/utils/serial/SerialUtils.java
b/src/be/nikiroo/utils/serial/SerialUtils.java
index a6a02a8e06205cb5996b0a94c1124056ce2cbf60..6f851731fd034541b912d71046b0375e8ee7422b 100644
(file)
--- a/
src/be/nikiroo/utils/serial/SerialUtils.java
+++ b/
src/be/nikiroo/utils/serial/SerialUtils.java
@@
-5,7
+5,6
@@
import java.io.IOException;
import java.io.InputStream;
import java.io.NotSerializableException;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.NotSerializableException;
import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@@
-20,6
+19,8
@@
import java.util.UnknownFormatConversionException;
import be.nikiroo.utils.IOUtils;
import be.nikiroo.utils.Image;
import be.nikiroo.utils.StringUtils;
import be.nikiroo.utils.IOUtils;
import be.nikiroo.utils.Image;
import be.nikiroo.utils.StringUtils;
+import be.nikiroo.utils.streams.Base64InputStream;
+import be.nikiroo.utils.streams.Base64OutputStream;
import be.nikiroo.utils.streams.NextableInputStream;
import be.nikiroo.utils.streams.NextableInputStreamStep;
import be.nikiroo.utils.streams.NextableInputStream;
import be.nikiroo.utils.streams.NextableInputStreamStep;
@@
-80,9
+81,9
@@
public class SerialUtils {
try {
// TODO: bad escaping?
write(out, "B64:");
try {
// TODO: bad escaping?
write(out, "B64:");
- OutputStream
bout = StringUtils.base64(out,
-
false, fals
e);
- new Exporter(
bout
).append(item);
+ OutputStream
out64 = new Base64OutputStream(
+
out, tru
e);
+ new Exporter(
out64
).append(item);
} catch (NotSerializableException e) {
throw new UnknownFormatConversionException(e
.getMessage());
} catch (NotSerializableException e) {
throw new UnknownFormatConversionException(e
.getMessage());
@@
-140,7
+141,7
@@
public class SerialUtils {
val = ((URL) value).toString();
}
val = ((URL) value).toString();
}
- out.write(
val.getBytes("UTF-8"
));
+ out.write(
StringUtils.getBytes(val
));
}
@Override
}
@Override
@@
-165,7
+166,7
@@
public class SerialUtils {
protected void toStream(OutputStream out, Object value)
throws IOException {
Image img = (Image) value;
protected void toStream(OutputStream out, Object value)
throws IOException {
Image img = (Image) value;
- OutputStream encoded =
StringUtils.base64(out, false, fals
e);
+ OutputStream encoded =
new Base64OutputStream(out, tru
e);
try {
InputStream in = img.newInputStream();
try {
try {
InputStream in = img.newInputStream();
try {
@@
-188,7
+189,7
@@
public class SerialUtils {
protected Object fromStream(InputStream in) throws IOException {
try {
// Cannot close it!
protected Object fromStream(InputStream in) throws IOException {
try {
// Cannot close it!
- InputStream decoded =
StringUtils.unbase64
(in, false);
+ InputStream decoded =
new Base64InputStream
(in, false);
return new Image(decoded);
} catch (IOException e) {
throw new UnknownFormatConversionException(e.getMessage());
return new Image(decoded);
} catch (IOException e) {
throw new UnknownFormatConversionException(e.getMessage());
@@
-479,7
+480,7
@@
public class SerialUtils {
if (customTypes.containsKey(type)) {
// TODO: we should start with a stream
InputStream streamEncodedValue = new ByteArrayInputStream(
if (customTypes.containsKey(type)) {
// TODO: we should start with a stream
InputStream streamEncodedValue = new ByteArrayInputStream(
-
encodedValue.getBytes("UTF-8"
));
+
StringUtils.getBytes(encodedValue
));
try {
return customTypes.get(type).decode(streamEncodedValue);
} finally {
try {
return customTypes.get(type).decode(streamEncodedValue);
} finally {
@@
-534,12
+535,7
@@
public class SerialUtils {
* in case of I/O error
*/
static void write(OutputStream out, Object data) throws IOException {
* in case of I/O error
*/
static void write(OutputStream out, Object data) throws IOException {
- try {
- out.write(data.toString().getBytes("UTF-8"));
- } catch (UnsupportedEncodingException e) {
- // A conforming JVM is required to support UTF-8
- e.printStackTrace();
- }
+ out.write(StringUtils.getBytes(data.toString()));
}
/**
}
/**