This commit is contained in:
kamhung
2015-11-11 11:45:31 +08:00
parent 66117126c2
commit a1dc7e954d
3 changed files with 4 additions and 34 deletions

View File

@@ -49,6 +49,7 @@ public final class JsonByteBufferWriter extends JsonWriter {
return false; return false;
} }
@Override
public ByteBuffer[] toBuffers() { public ByteBuffer[] toBuffers() {
if (buffers == null) return new ByteBuffer[0]; if (buffers == null) return new ByteBuffer[0];
for (int i = index; i < this.buffers.length; i++) { for (int i = index; i < this.buffers.length; i++) {
@@ -58,16 +59,6 @@ public final class JsonByteBufferWriter extends JsonWriter {
return this.buffers; return this.buffers;
} }
@Override
public char[] toArray() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public byte[] toUTF8Bytes() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override @Override
public int count() { public int count() {
if (this.buffers == null) return 0; if (this.buffers == null) return 0;

View File

@@ -134,19 +134,4 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
} }
return out.toBuffers(); return out.toBuffers();
} }
public byte[] convertToUTF8Bytes(Object value) {
if (value == null) return new byte[]{110, 117, 108, 108};
return convertToUTF8Bytes(value.getClass(), value);
}
public byte[] convertToUTF8Bytes(final Type type, Object value) {
if (type == null) return null;
if (value == null) return new byte[]{110, 117, 108, 108};
final JsonWriter out = writerPool.get().setTiny(tiny);
factory.loadEncoder(type).convertTo(out, value);
byte[] result = out.toUTF8Bytes();
writerPool.offer(out);
return result;
}
} }

View File

@@ -7,6 +7,7 @@ package com.wentch.redkale.convert.json;
import com.wentch.redkale.convert.*; import com.wentch.redkale.convert.*;
import com.wentch.redkale.util.*; import com.wentch.redkale.util.*;
import java.nio.*;
/** /**
* *
@@ -101,15 +102,8 @@ public class JsonWriter implements Writer {
return true; return true;
} }
public char[] toArray() { public ByteBuffer[] toBuffers() {
if (count == content.length) return content; return new ByteBuffer[]{ByteBuffer.wrap(Utility.encodeUTF8(content, 0, count))};
char[] newdata = new char[count];
System.arraycopy(content, 0, newdata, 0, count);
return newdata;
}
public byte[] toUTF8Bytes() {
return Utility.encodeUTF8(content, 0, count);
} }
public int count() { public int count() {