From 979ff809827ab25005364dad41d2fd043b8eaa4d Mon Sep 17 00:00:00 2001 From: frsyuki Date: Thu, 20 May 2010 03:49:26 +0900 Subject: java: redesign --- .../java/org/msgpack/BufferedUnpackerImpl.java | 384 ++++++++++++++++ .../main/java/org/msgpack/MessageConvertable.java | 23 + .../main/java/org/msgpack/MessageMergeable.java | 23 - .../java/org/msgpack/MessageTypeException.java | 4 +- .../main/java/org/msgpack/MessageUnpackable.java | 25 + java/src/main/java/org/msgpack/Packer.java | 2 +- .../main/java/org/msgpack/UnbufferedUnpacker.java | 82 ---- java/src/main/java/org/msgpack/UnpackCursor.java | 96 ++++ java/src/main/java/org/msgpack/UnpackIterator.java | 24 +- java/src/main/java/org/msgpack/UnpackResult.java | 42 ++ java/src/main/java/org/msgpack/Unpacker.java | 269 ++++++----- java/src/main/java/org/msgpack/UnpackerImpl.java | 504 +++++++++++++++++++++ .../main/java/org/msgpack/impl/UnpackerImpl.java | 500 -------------------- .../java/org/msgpack/TestDirectConversion.java | 154 +++++++ java/src/test/java/org/msgpack/TestPackUnpack.java | 2 +- 15 files changed, 1366 insertions(+), 768 deletions(-) create mode 100644 java/src/main/java/org/msgpack/BufferedUnpackerImpl.java create mode 100644 java/src/main/java/org/msgpack/MessageConvertable.java delete mode 100644 java/src/main/java/org/msgpack/MessageMergeable.java create mode 100644 java/src/main/java/org/msgpack/MessageUnpackable.java delete mode 100644 java/src/main/java/org/msgpack/UnbufferedUnpacker.java create mode 100644 java/src/main/java/org/msgpack/UnpackCursor.java create mode 100644 java/src/main/java/org/msgpack/UnpackResult.java create mode 100644 java/src/main/java/org/msgpack/UnpackerImpl.java delete mode 100644 java/src/main/java/org/msgpack/impl/UnpackerImpl.java create mode 100644 java/src/test/java/org/msgpack/TestDirectConversion.java (limited to 'java') diff --git a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java new file mode 100644 index 0000000..0ef9c12 --- /dev/null +++ b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java @@ -0,0 +1,384 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009-2010 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack; + +import java.io.IOException; +import java.nio.ByteBuffer; +//import java.math.BigInteger; + +abstract class BufferedUnpackerImpl extends UnpackerImpl { + int filled = 0; + byte[] buffer = null; + private ByteBuffer castBuffer = ByteBuffer.allocate(8); + + abstract boolean fill() throws IOException; + + final int next(int offset, UnpackResult result) throws IOException, UnpackException { + if(filled == 0) { + if(!fill()) { + return offset; + } + } + + do { + int noffset = super.execute(buffer, offset, filled); + if(noffset <= offset) { + if(!fill()) { + return offset; + } + } + offset = noffset; + } while(!super.isFinished()); + + Object obj = super.getData(); + super.reset(); + result.done(obj); + + return offset; + } + + private final void more(int offset, int require) throws IOException, UnpackException { + while(filled - offset < require) { + if(!fill()) { + // FIXME + throw new UnpackException("insufficient buffer"); + } + } + } + + final byte unpackByte(UnpackCursor c, int offset) throws IOException, MessageTypeException { + int o = unpackInt(c, offset); + if(0x7f < o || o < -0x80) { + throw new MessageTypeException(); + } + return (byte)o; + } + + final short unpackShort(UnpackCursor c, int offset) throws IOException, MessageTypeException { + int o = unpackInt(c, offset); + if(0x7fff < o || o < -0x8000) { + throw new MessageTypeException(); + } + return (short)o; + } + + final int unpackInt(UnpackCursor c, int offset) throws IOException, MessageTypeException { + more(offset, 1); + int b = buffer[offset]; + if((b & 0x80) == 0 || (b & 0xe0) == 0xe0) { // Fixnum + return (int)b; + } + switch(b & 0xff) { + case 0xcc: // unsigned int 8 + more(offset, 2); + c.advance(2); + return (int)((short)buffer[offset+1] & 0xff); + case 0xcd: // unsigned int 16 + more(offset, 3); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 2); + c.advance(3); + return (int)((int)castBuffer.getShort(0) & 0xffff); + case 0xce: // unsigned int 32 + more(offset, 5); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 4); + { + int o = castBuffer.getInt(0); + if(o < 0) { + throw new MessageTypeException(); + } + c.advance(5); + return o; + } + case 0xcf: // unsigned int 64 + more(offset, 9); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 8); + { + long o = castBuffer.getLong(0); + if(o < 0 || o > 0x7fffffffL) { + throw new MessageTypeException(); + } + c.advance(9); + return (int)o; + } + case 0xd0: // signed int 8 + more(offset, 2); + c.advance(2); + return (int)buffer[offset+1]; + case 0xd1: // signed int 16 + more(offset, 3); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 2); + c.advance(3); + return (int)castBuffer.getShort(0); + case 0xd2: // signed int 32 + more(offset, 4); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 4); + c.advance(4); + return (int)castBuffer.getInt(0); + case 0xd3: // signed int 64 + more(offset, 9); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 8); + { + long o = castBuffer.getLong(0); + if(0x7fffffffL < o || o < -0x80000000L) { + throw new MessageTypeException(); + } + c.advance(9); + return (int)o; + } + default: + throw new MessageTypeException(); + } + } + + final long unpackLong(UnpackCursor c, int offset) throws IOException, MessageTypeException { + more(offset, 1); + int b = buffer[offset]; + if((b & 0x80) == 0 || (b & 0xe0) == 0xe0) { // Fixnum + return (long)b; + } + switch(b & 0xff) { + case 0xcc: // unsigned int 8 + more(offset, 2); + c.advance(2); + return (long)((short)buffer[offset+1] & 0xff); + case 0xcd: // unsigned int 16 + more(offset, 3); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 2); + c.advance(3); + return (long)((int)castBuffer.getShort(0) & 0xffff); + case 0xce: // unsigned int 32 + more(offset, 5); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 4); + c.advance(5); + return ((long)castBuffer.getInt(0) & 0xffffffffL); + case 0xcf: // unsigned int 64 + more(offset, 9); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 8); + { + long o = castBuffer.getLong(0); + if(o < 0) { + // FIXME + throw new MessageTypeException("uint 64 bigger than 0x7fffffff is not supported"); + } + c.advance(9); + return o; + } + case 0xd0: // signed int 8 + more(offset, 2); + c.advance(2); + return (long)buffer[offset+1]; + case 0xd1: // signed int 16 + more(offset, 3); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 2); + c.advance(3); + return (long)castBuffer.getShort(0); + case 0xd2: // signed int 32 + more(offset, 4); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 4); + c.advance(4); + return (long)castBuffer.getInt(0); + case 0xd3: // signed int 64 + more(offset, 9); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 8); + c.advance(9); + return (long)castBuffer.getLong(0); + default: + throw new MessageTypeException(); + } + } + + final float unpackFloat(UnpackCursor c, int offset) throws IOException, MessageTypeException { + more(offset, 1); + int b = buffer[offset]; + switch(b & 0xff) { + case 0xca: // float + more(offset, 5); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 4); + c.advance(5); + return castBuffer.getFloat(0); + case 0xcb: // double + more(offset, 9); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 8); + c.advance(9); + // FIXME overflow check + return (float)castBuffer.getDouble(0); + default: + throw new MessageTypeException(); + } + } + + final double unpackDouble(UnpackCursor c, int offset) throws IOException, MessageTypeException { + more(offset, 1); + int b = buffer[offset]; + switch(b & 0xff) { + case 0xca: // float + more(offset, 5); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 4); + c.advance(5); + return (double)castBuffer.getFloat(0); + case 0xcb: // double + more(offset, 9); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 8); + c.advance(9); + return castBuffer.getDouble(0); + default: + throw new MessageTypeException(); + } + } + + final Object unpackNull(UnpackCursor c, int offset) throws IOException, MessageTypeException { + more(offset, 1); + int b = buffer[offset] & 0xff; + if(b != 0xc0) { // nil + throw new MessageTypeException(); + } + c.advance(1); + return null; + } + + final boolean unpackBoolean(UnpackCursor c, int offset) throws IOException, MessageTypeException { + more(offset, 1); + int b = buffer[offset] & 0xff; + if(b == 0xc2) { // false + c.advance(1); + return false; + } else if(b == 0xc3) { // true + c.advance(1); + return true; + } else { + throw new MessageTypeException(); + } + } + + final int unpackArray(UnpackCursor c, int offset) throws IOException, MessageTypeException { + more(offset, 1); + int b = buffer[offset]; + if((b & 0xf0) == 0x90) { // FixArray + c.advance(1); + return (int)(b & 0x0f); + } + switch(b & 0xff) { + case 0xdc: // array 16 + more(offset, 3); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 2); + c.advance(3); + return (int)castBuffer.getShort(0) & 0xffff; + case 0xdd: // array 32 + more(offset, 5); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 4); + c.advance(5); + // FIXME overflow check + return castBuffer.getInt(0) & 0x7fffffff; + default: + throw new MessageTypeException(); + } + } + + final int unpackMap(UnpackCursor c, int offset) throws IOException, MessageTypeException { + more(offset, 1); + int b = buffer[offset]; + if((b & 0xf0) == 0x80) { // FixMap + c.advance(1); + return (int)(b & 0x0f); + } + switch(b & 0xff) { + case 0xde: // map 16 + more(offset, 3); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 2); + c.advance(3); + return (int)castBuffer.getShort(0) & 0xffff; + case 0xdf: // map 32 + more(offset, 5); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 4); + c.advance(5); + // FIXME overflow check + return castBuffer.getInt(0) & 0x7fffffff; + default: + throw new MessageTypeException(); + } + } + + final int unpackRaw(UnpackCursor c, int offset) throws IOException, MessageTypeException { + more(offset, 1); + int b = buffer[offset]; + if((b & 0xe0) == 0xa0) { // FixRaw + c.advance(1); + return (int)(b & 0x0f); + } + switch(b & 0xff) { + case 0xda: // raw 16 + more(offset, 3); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 2); + c.advance(3); + return (int)castBuffer.getShort(0) & 0xffff; + case 0xdb: // raw 32 + more(offset, 5); + castBuffer.rewind(); + castBuffer.put(buffer, offset+1, 4); + c.advance(5); + // FIXME overflow check + return castBuffer.getInt(0) & 0x7fffffff; + default: + throw new MessageTypeException(); + } + } + + final byte[] unpackRawBody(UnpackCursor c, int offset, int length) throws IOException, MessageTypeException { + more(offset, length); + byte[] bytes = new byte[length]; + System.arraycopy(buffer, offset, bytes, 0, length); + c.advance(length); + return bytes; + } + + final String unpackString(UnpackCursor c, int offset) throws IOException, MessageTypeException { + int length = unpackRaw(c, offset); + offset = c.getOffset(); + more(offset, length); + String s; + try { + s = new String(buffer, offset, length, "UTF-8"); + } catch (Exception e) { + throw new MessageTypeException(); + } + c.advance(length); + return s; + } +} + diff --git a/java/src/main/java/org/msgpack/MessageConvertable.java b/java/src/main/java/org/msgpack/MessageConvertable.java new file mode 100644 index 0000000..da251dc --- /dev/null +++ b/java/src/main/java/org/msgpack/MessageConvertable.java @@ -0,0 +1,23 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009-2010 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack; + +public interface MessageConvertable { + public void messageConvert(Object obj) throws MessageTypeException; +} + diff --git a/java/src/main/java/org/msgpack/MessageMergeable.java b/java/src/main/java/org/msgpack/MessageMergeable.java deleted file mode 100644 index e5a5b45..0000000 --- a/java/src/main/java/org/msgpack/MessageMergeable.java +++ /dev/null @@ -1,23 +0,0 @@ -// -// MessagePack for Java -// -// Copyright (C) 2009-2010 FURUHASHI Sadayuki -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -package org.msgpack; - -public interface MessageMergeable { - public void messageMerge(Object obj) throws MessageTypeException; -} - diff --git a/java/src/main/java/org/msgpack/MessageTypeException.java b/java/src/main/java/org/msgpack/MessageTypeException.java index feb6c08..0fa37b7 100644 --- a/java/src/main/java/org/msgpack/MessageTypeException.java +++ b/java/src/main/java/org/msgpack/MessageTypeException.java @@ -17,9 +17,7 @@ // package org.msgpack; -import java.io.IOException; - -public class MessageTypeException extends IOException { +public class MessageTypeException extends RuntimeException { public MessageTypeException() { } public MessageTypeException(String s) { diff --git a/java/src/main/java/org/msgpack/MessageUnpackable.java b/java/src/main/java/org/msgpack/MessageUnpackable.java new file mode 100644 index 0000000..20e4d56 --- /dev/null +++ b/java/src/main/java/org/msgpack/MessageUnpackable.java @@ -0,0 +1,25 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009-2010 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack; + +import java.io.IOException; + +public interface MessageUnpackable { + public void messageUnpack(Unpacker pk) throws IOException, MessageTypeException; +} + diff --git a/java/src/main/java/org/msgpack/Packer.java b/java/src/main/java/org/msgpack/Packer.java index 935728d..6d79414 100644 --- a/java/src/main/java/org/msgpack/Packer.java +++ b/java/src/main/java/org/msgpack/Packer.java @@ -401,7 +401,7 @@ public class Packer { } else if(o instanceof Double) { return packDouble((Double)o); } else { - throw new IOException("unknown object "+o+" ("+o.getClass()+")"); + throw new MessageTypeException("unknown object "+o+" ("+o.getClass()+")"); } } } diff --git a/java/src/main/java/org/msgpack/UnbufferedUnpacker.java b/java/src/main/java/org/msgpack/UnbufferedUnpacker.java deleted file mode 100644 index b427973..0000000 --- a/java/src/main/java/org/msgpack/UnbufferedUnpacker.java +++ /dev/null @@ -1,82 +0,0 @@ -// -// MessagePack for Java -// -// Copyright (C) 2009-2010 FURUHASHI Sadayuki -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -package org.msgpack; - -import java.lang.Iterable; -import java.io.InputStream; -import java.io.IOException; -import java.util.Iterator; -import org.msgpack.impl.UnpackerImpl; - -public class UnbufferedUnpacker extends UnpackerImpl { - private int offset; - private boolean finished; - private Object data; - - public UnbufferedUnpacker() { - super(); - this.offset = 0; - this.finished = false; - } - - public UnbufferedUnpacker useSchema(Schema s) { - super.setSchema(s); - return this; - } - - public Object getData() { - return data; - } - - public boolean isFinished() { - return finished; - } - - public void reset() { - super.reset(); - this.offset = 0; - } - - int getOffset() { - return offset; - } - - void setOffset(int offset) { - this.offset = offset; - } - - public int execute(byte[] buffer) throws UnpackException { - return execute(buffer, 0, buffer.length); - } - - // FIXME - public int execute(byte[] buffer, int offset, int length) throws UnpackException - { - int noffset = super.execute(buffer, offset + this.offset, length); - this.offset = noffset - offset; - if(super.isFinished()) { - this.data = super.getData(); - this.finished = true; - super.reset(); - } else { - this.finished = false; - } - return noffset; - } -} - diff --git a/java/src/main/java/org/msgpack/UnpackCursor.java b/java/src/main/java/org/msgpack/UnpackCursor.java new file mode 100644 index 0000000..33f4258 --- /dev/null +++ b/java/src/main/java/org/msgpack/UnpackCursor.java @@ -0,0 +1,96 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009-2010 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack; + +import java.io.IOException; + +public class UnpackCursor { + private Unpacker pac; + private int offset; + + UnpackCursor(Unpacker pac, int offset) + { + this.pac = pac; + this.offset = offset; + } + + final void advance(int length) { + offset += length; + } + + final int getOffset() { + return offset; + } + + public byte unpackByte() throws IOException, MessageTypeException { + return pac.impl.unpackByte(this, offset); + } + + public short unpackShort() throws IOException, MessageTypeException { + return pac.impl.unpackShort(this, offset); + } + + public int unpackInt() throws IOException, MessageTypeException { + return pac.impl.unpackInt(this, offset); + } + + public long unpackLong() throws IOException, MessageTypeException { + return pac.impl.unpackLong(this, offset); + } + + public float unpackFloat() throws IOException, MessageTypeException { + return pac.impl.unpackFloat(this, offset); + } + + public double unpackDouble() throws IOException, MessageTypeException { + return pac.impl.unpackDouble(this, offset); + } + + public Object unpackNull() throws IOException, MessageTypeException { + return pac.impl.unpackNull(this, offset); + } + + public boolean unpackBoolean() throws IOException, MessageTypeException { + return pac.impl.unpackBoolean(this, offset); + } + + public int unpackArray() throws IOException, MessageTypeException { + return pac.impl.unpackArray(this, offset); + } + + public int unpackMap() throws IOException, MessageTypeException { + return pac.impl.unpackMap(this, offset); + } + + public int unpackRaw() throws IOException, MessageTypeException { + return pac.impl.unpackRaw(this, offset); + } + + public byte[] unpackRawBody(int length) throws IOException, MessageTypeException { + return pac.impl.unpackRawBody(this, offset, length); + } + + public String unpackString() throws IOException, MessageTypeException { + return pac.impl.unpackString(this, offset); + } + + public void commit() { + pac.setOffset(offset); + } +} + diff --git a/java/src/main/java/org/msgpack/UnpackIterator.java b/java/src/main/java/org/msgpack/UnpackIterator.java index 0a78e83..5cc994d 100644 --- a/java/src/main/java/org/msgpack/UnpackIterator.java +++ b/java/src/main/java/org/msgpack/UnpackIterator.java @@ -21,41 +21,27 @@ import java.io.IOException; import java.util.Iterator; import java.util.NoSuchElementException; -public class UnpackIterator implements Iterator { +public class UnpackIterator extends UnpackResult implements Iterator { private Unpacker pac; - private boolean have; - private Object data; UnpackIterator(Unpacker pac) { + super(); this.pac = pac; - this.have = false; } public boolean hasNext() { - if(have) { return true; } try { - while(true) { - if(pac.execute()) { - data = pac.getData(); - pac.reset(); - have = true; - return true; - } - - if(!pac.fill()) { - return false; - } - } + return pac.next(this); } catch (IOException e) { return false; } } public Object next() { - if(!have && !hasNext()) { + if(!finished && !hasNext()) { throw new NoSuchElementException(); } - have = false; + finished = false; return data; } diff --git a/java/src/main/java/org/msgpack/UnpackResult.java b/java/src/main/java/org/msgpack/UnpackResult.java new file mode 100644 index 0000000..cec18a1 --- /dev/null +++ b/java/src/main/java/org/msgpack/UnpackResult.java @@ -0,0 +1,42 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009-2010 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack; + +public class UnpackResult { + protected boolean finished = false; + protected Object data = null; + + public boolean isFinished() { + return finished; + } + + public Object getData() { + return data; + } + + public void reset() { + finished = false; + data = null; + } + + void done(Object obj) { + finished = true; + data = obj; + } +} + diff --git a/java/src/main/java/org/msgpack/Unpacker.java b/java/src/main/java/org/msgpack/Unpacker.java index c8a8823..20a8c4a 100644 --- a/java/src/main/java/org/msgpack/Unpacker.java +++ b/java/src/main/java/org/msgpack/Unpacker.java @@ -22,18 +22,43 @@ import java.io.InputStream; import java.io.IOException; import java.util.Iterator; import java.nio.ByteBuffer; -import org.msgpack.impl.UnpackerImpl; -public class Unpacker extends UnpackerImpl implements Iterable { +public class Unpacker implements Iterable { + + // buffer: + // +---------------------------------------------+ + // | [object] | [obje| unparsed ... | unused ...| + // +---------------------------------------------+ + // ^ parsed + // ^ offset + // ^ filled + // ^ buffer.length + + private static final int DEFAULT_BUFFER_SIZE = 32*1024; + + protected int offset; + protected int parsed; + protected int bufferReserveSize; + protected InputStream stream; + + class BufferedUnpackerMixin extends BufferedUnpackerImpl { + boolean fill() throws IOException { + if(stream == null) { + return false; + } + reserveBuffer(bufferReserveSize); + int rl = stream.read(buffer, filled, buffer.length - filled); + // equals: stream.read(getBuffer(), getBufferOffset(), getBufferCapacity()); + if(rl <= 0) { + return false; + } + bufferConsumed(rl); + return true; + } + }; - public static final int DEFAULT_BUFFER_SIZE = 32*1024; + final BufferedUnpackerMixin impl = new BufferedUnpackerMixin(); - private int used; - private int offset; - private int parsed; - private byte[] buffer; - private int bufferReserveSize; - private InputStream stream; public Unpacker() { this(DEFAULT_BUFFER_SIZE); @@ -48,67 +73,31 @@ public class Unpacker extends UnpackerImpl implements Iterable { } public Unpacker(InputStream stream, int bufferReserveSize) { - super(); - this.used = 0; this.offset = 0; this.parsed = 0; - this.buffer = new byte[bufferReserveSize]; this.bufferReserveSize = bufferReserveSize/2; this.stream = stream; } public Unpacker useSchema(Schema s) { - super.setSchema(s); + impl.setSchema(s); return this; } - public void reserveBuffer(int size) { - if(buffer.length - used >= size) { - return; - } - /* - if(used == parsed && buffer.length >= size) { - // rewind buffer - used = 0; - offset = 0; - return; - } - */ - - int nextSize = buffer.length * 2; - while(nextSize < size + used) { - nextSize *= 2; - } - - byte[] tmp = new byte[nextSize]; - System.arraycopy(buffer, offset, tmp, 0, used - offset); - - buffer = tmp; - used -= offset; - offset = 0; - } - - public byte[] getBuffer() { - return buffer; - } - - public int getBufferOffset() { - return used; - } - public int getBufferCapacity() { - return buffer.length - used; + public InputStream getStream() { + return this.stream; } - public void bufferConsumed(int size) { - used += size; + public void setStream(InputStream stream) { + this.stream = stream; } public void feed(ByteBuffer buffer) { int length = buffer.remaining(); if (length == 0) return; reserveBuffer(length); - buffer.get(this.buffer, this.offset, length); + buffer.get(impl.buffer, this.offset, length); bufferConsumed(length); } @@ -118,48 +107,116 @@ public class Unpacker extends UnpackerImpl implements Iterable { public void feed(byte[] buffer, int offset, int length) { reserveBuffer(length); - System.arraycopy(buffer, offset, this.buffer, this.offset, length); + System.arraycopy(buffer, offset, impl.buffer, this.offset, length); bufferConsumed(length); } public boolean fill() throws IOException { - if(stream == null) { - return false; - } - reserveBuffer(bufferReserveSize); - int rl = stream.read(getBuffer(), getBufferOffset(), getBufferCapacity()); - if(rl <= 0) { - return false; - } - bufferConsumed(rl); - return true; + return impl.fill(); } public Iterator iterator() { return new UnpackIterator(this); } + public UnpackResult next() throws IOException, UnpackException { + UnpackResult result = new UnpackResult(); + this.offset = impl.next(this.offset, result); + return result; + } + + public boolean next(UnpackResult result) throws IOException, UnpackException { + this.offset = impl.next(this.offset, result); + return result.isFinished(); + } + + + public void reserveBuffer(int require) { + if(impl.buffer == null) { + int nextSize = (bufferReserveSize < require) ? require : bufferReserveSize; + impl.buffer = new byte[nextSize]; + return; + } + + if(impl.buffer.length - impl.filled >= require) { + return; + } + + int nextSize = impl.buffer.length * 2; + int notParsed = impl.filled - this.offset; + while(nextSize < require + notParsed) { + nextSize *= 2; + } + + byte[] tmp = new byte[nextSize]; + System.arraycopy(impl.buffer, this.offset, tmp, 0, impl.filled - this.offset); + + impl.buffer = tmp; + impl.filled = notParsed; + this.offset = 0; + } + + public byte[] getBuffer() { + return impl.buffer; + } + + public int getBufferOffset() { + return impl.filled; + } + + public int getBufferCapacity() { + return impl.buffer.length - impl.filled; + } + + public void bufferConsumed(int size) { + impl.filled += size; + } + public boolean execute() throws UnpackException { - int noffset = super.execute(buffer, offset, used); + int noffset = impl.execute(impl.buffer, offset, impl.filled); if(noffset <= offset) { return false; } parsed += noffset - offset; offset = noffset; - return super.isFinished(); + return impl.isFinished(); + } + + + public int execute(byte[] buffer) throws UnpackException { + return execute(buffer, 0, buffer.length); + } + + public int execute(byte[] buffer, int offset, int length) throws UnpackException { + int noffset = impl.execute(buffer, offset + this.offset, length); + this.offset = noffset - offset; + if(impl.isFinished()) { + impl.resetState(); + } + return noffset; + } + + public boolean isFinished() { + return impl.isFinished(); } public Object getData() { - return super.getData(); + return impl.getData(); } public void reset() { - super.reset(); - parsed = 0; + impl.reset(); + } + + + public UnpackCursor begin() + { + return new UnpackCursor(this, offset); } + public int getMessageSize() { - return parsed - offset + used; + return parsed - offset + impl.filled; } public int getParsedSize() { @@ -167,7 +224,7 @@ public class Unpacker extends UnpackerImpl implements Iterable { } public int getNonParsedSize() { - return used - offset; + return impl.filled - offset; } public void skipNonparsedBuffer(int size) { @@ -175,80 +232,14 @@ public class Unpacker extends UnpackerImpl implements Iterable { } public void removeNonparsedBuffer() { - used = offset; + impl.filled = offset; } - /* - public static class Context { - private boolean finished; - private Object data; - private int offset; - private UnpackerImpl impl; - public Context() - { - this.finished = false; - this.impl = new UnpackerImpl(); - } - - public boolean isFinished() - { - return finished; - } - - public Object getData() - { - return data; - } - - int getOffset() - { - return offset; - } - - void setFinished(boolean finished) - { - this.finished = finished; - } - - void setData(Object data) - { - this.data = data; - } - - void setOffset(int offset) - { - this.offset = offset; - } - - UnpackerImpl getImpl() - { - return impl; - } - } - - public static int unpack(Context ctx, byte[] buffer) throws UnpackException + void setOffset(int offset) { - return unpack(ctx, buffer, 0, buffer.length); - } - - public static int unpack(Context ctx, byte[] buffer, int offset, int length) throws UnpackException - { - UnpackerImpl impl = ctx.getImpl(); - int noffset = impl.execute(buffer, offset + ctx.getOffset(), length); - ctx.setOffset(noffset - offset); - if(impl.isFinished()) { - ctx.setData(impl.getData()); - ctx.setFinished(false); - impl.reset(); - } else { - ctx.setData(null); - ctx.setFinished(true); - } - int parsed = noffset - offset; - ctx.setOffset(parsed); - return noffset; + parsed += offset - this.offset; + this.offset = offset; } - */ } diff --git a/java/src/main/java/org/msgpack/UnpackerImpl.java b/java/src/main/java/org/msgpack/UnpackerImpl.java new file mode 100644 index 0000000..ae01289 --- /dev/null +++ b/java/src/main/java/org/msgpack/UnpackerImpl.java @@ -0,0 +1,504 @@ +// +// MessagePack for Java +// +// Copyright (C) 2009-2010 FURUHASHI Sadayuki +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +package org.msgpack; + +import java.nio.ByteBuffer; +//import java.math.BigInteger; +import org.msgpack.*; +import org.msgpack.schema.GenericSchema; +import org.msgpack.schema.IMapSchema; +import org.msgpack.schema.IArraySchema; + +public class UnpackerImpl { + static final int CS_HEADER = 0x00; + static final int CS_FLOAT = 0x0a; + static final int CS_DOUBLE = 0x0b; + static final int CS_UINT_8 = 0x0c; + static final int CS_UINT_16 = 0x0d; + static final int CS_UINT_32 = 0x0e; + static final int CS_UINT_64 = 0x0f; + static final int CS_INT_8 = 0x10; + static final int CS_INT_16 = 0x11; + static final int CS_INT_32 = 0x12; + static final int CS_INT_64 = 0x13; + static final int CS_RAW_16 = 0x1a; + static final int CS_RAW_32 = 0x1b; + static final int CS_ARRAY_16 = 0x1c; + static final int CS_ARRAY_32 = 0x1d; + static final int CS_MAP_16 = 0x1e; + static final int CS_MAP_32 = 0x1f; + static final int ACS_RAW_VALUE = 0x20; + static final int CT_ARRAY_ITEM = 0x00; + static final int CT_MAP_KEY = 0x01; + static final int CT_MAP_VALUE = 0x02; + + static final int MAX_STACK_SIZE = 32; + + private int cs; + private int trail; + private int top; + private int[] stack_ct = new int[MAX_STACK_SIZE]; + private int[] stack_count = new int[MAX_STACK_SIZE]; + private Object[] stack_obj = new Object[MAX_STACK_SIZE]; + private Schema[] stack_schema = new Schema[MAX_STACK_SIZE]; + private int top_ct; + private int top_count; + private Object top_obj; + private Schema top_schema; + private ByteBuffer castBuffer = ByteBuffer.allocate(8); + private boolean finished = false; + private Object data = null; + + private static final Schema GENERIC_SCHEMA = new GenericSchema(); + private Schema rootSchema; + + public UnpackerImpl() + { + setSchema(GENERIC_SCHEMA); + } + + public void setSchema(Schema schema) + { + this.rootSchema = schema; + reset(); + } + + public final Object getData() + { + return data; + } + + public final boolean isFinished() + { + return finished; + } + + public final void resetState() { + cs = CS_HEADER; + top = -1; + top_ct = 0; + top_count = 0; + top_obj = null; + top_schema = rootSchema; + } + + public final void reset() + { + resetState(); + finished = false; + data = null; + } + + @SuppressWarnings("unchecked") + public final int execute(byte[] src, int off, int length) throws UnpackException + { + if(off >= length) { return off; } + + int limit = length; + int i = off; + int count; + + Object obj = null; + + _out: do { + _header_again: { + //System.out.println("while i:"+i+" limit:"+limit); + + int b = src[i]; + + _push: { + _fixed_trail_again: + if(cs == CS_HEADER) { + + if((b & 0x80) == 0) { // Positive Fixnum + //System.out.println("positive fixnum "+b); + obj = top_schema.createFromByte((byte)b); + break _push; + } + + if((b & 0xe0) == 0xe0) { // Negative Fixnum + //System.out.println("negative fixnum "+b); + obj = top_schema.createFromByte((byte)b); + break _push; + } + + if((b & 0xe0) == 0xa0) { // FixRaw + trail = b & 0x1f; + if(trail == 0) { + obj = top_schema.createFromRaw(new byte[0], 0, 0); + break _push; + } + cs = ACS_RAW_VALUE; + break _fixed_trail_again; + } + + if((b & 0xf0) == 0x90) { // FixArray + if(top >= MAX_STACK_SIZE) { + throw new UnpackException("parse error"); + } + if(!(top_schema instanceof IArraySchema)) { + throw new RuntimeException("type error"); + } + count = b & 0x0f; + //System.out.println("fixarray count:"+count); + obj = new Object[count]; + if(count == 0) { break _push; } // FIXME check IArraySchema + ++top; + stack_obj[top] = top_obj; + stack_ct[top] = top_ct; + stack_count[top] = top_count; + stack_schema[top] = top_schema; + top_obj = obj; + top_ct = CT_ARRAY_ITEM; + top_count = count; + top_schema = ((IArraySchema)top_schema).getElementSchema(0); + break _header_again; + } + + if((b & 0xf0) == 0x80) { // FixMap + if(top >= MAX_STACK_SIZE) { + throw new UnpackException("parse error"); + } + if(!(top_schema instanceof IMapSchema)) { + throw new RuntimeException("type error"); + } + count = b & 0x0f; + obj = new Object[count*2]; + if(count == 0) { break _push; } // FIXME check IMapSchema + //System.out.println("fixmap count:"+count); + ++top; + stack_obj[top] = top_obj; + stack_ct[top] = top_ct; + stack_count[top] = top_count; + stack_schema[top] = top_schema; + top_obj = obj; + top_ct = CT_MAP_KEY; + top_count = count; + top_schema = ((IMapSchema)top_schema).getKeySchema(); + break _header_again; + } + + switch(b & 0xff) { // FIXME + case 0xc0: // nil + obj = top_schema.createFromNil(); + break _push; + case 0xc2: // false + obj = top_schema.createFromBoolean(false); + break _push; + case 0xc3: // true + obj = top_schema.createFromBoolean(true); + break _push; + case 0xca: // float + case 0xcb: // double + case 0xcc: // unsigned int 8 + case 0xcd: // unsigned int 16 + case 0xce: // unsigned int 32 + case 0xcf: // unsigned int 64 + case 0xd0: // signed int 8 + case 0xd1: // signed int 16 + case 0xd2: // signed int 32 + case 0xd3: // signed int 64 + trail = 1 << (b & 0x03); + cs = b & 0x1f; + //System.out.println("a trail "+trail+" cs:"+cs); + break _fixed_trail_again; + case 0xda: // raw 16 + case 0xdb: // raw 32 + case 0xdc: // array 16 + case 0xdd: // array 32 + case 0xde: // map 16 + case 0xdf: // map 32 + trail = 2 << (b & 0x01); + cs = b & 0x1f; + //System.out.println("b trail "+trail+" cs:"+cs); + break _fixed_trail_again; + default: + //System.out.println("unknown b "+(b&0xff)); + throw new UnpackException("parse error"); + } + + } // _fixed_trail_again + + do { + _fixed_trail_again: { + + if(limit - i <= trail) { break _out; } + int n = i + 1; + i += trail; + + switch(cs) { + case CS_FLOAT: + castBuffer.rewind(); + castBuffer.put(src, n, 4); + obj = top_schema.createFromFloat( castBuffer.getFloat(0) ); + //System.out.println("float "+obj); + break _push; + case CS_DOUBLE: + castBuffer.rewind(); + castBuffer.put(src, n, 8); + obj = top_schema.createFromDouble( castBuffer.getDouble(0) ); + //System.out.println("double "+obj); + break _push; + case CS_UINT_8: + //System.out.println(n); + //System.out.println(src[n]); + //System.out.println(src[n+1]); + //System.out.println(src[n-1]); + obj = top_schema.createFromShort( (short)((src[n]) & 0xff) ); + //System.out.println("uint8 "+obj); + break _push; + case CS_UINT_16: + //System.out.println(src[n]); + //System.out.println(src[n+1]); + castBuffer.rewind(); + castBuffer.put(src, n, 2); + obj = top_schema.createFromInt( ((int)castBuffer.getShort(0)) & 0xffff ); + //System.out.println("uint 16 "+obj); + break _push; + case CS_UINT_32: + castBuffer.rewind(); + castBuffer.put(src, n, 4); + obj = top_schema.createFromLong( ((long)castBuffer.getInt(0)) & 0xffffffffL ); + //System.out.println("uint 32 "+obj); + break _push; + case CS_UINT_64: + castBuffer.rewind(); + castBuffer.put(src, n, 8); + { + long o = castBuffer.getLong(0); + if(o < 0) { + // FIXME + //obj = GenericBigInteger.valueOf(o & 0x7fffffffL).setBit(31); + throw new UnpackException("uint 64 bigger than 0x7fffffff is not supported"); + } else { + obj = top_schema.createFromLong( o ); + } + } + break _push; + case CS_INT_8: + obj = top_schema.createFromByte( src[n] ); + break _push; + case CS_INT_16: + castBuffer.rewind(); + castBuffer.put(src, n, 2); + obj = top_schema.createFromShort( castBuffer.getShort(0) ); + break _push; + case CS_INT_32: + castBuffer.rewind(); + castBuffer.put(src, n, 4); + obj = top_schema.createFromInt( castBuffer.getInt(0) ); + break _push; + case CS_INT_64: + castBuffer.rewind(); + castBuffer.put(src, n, 8); + obj = top_schema.createFromLong( castBuffer.getLong(0) ); + break _push; + case CS_RAW_16: + castBuffer.rewind(); + castBuffer.put(src, n, 2); + trail = ((int)castBuffer.getShort(0)) & 0xffff; + if(trail == 0) { + obj = top_schema.createFromRaw(new byte[0], 0, 0); + break _push; + } + cs = ACS_RAW_VALUE; + break _fixed_trail_again; + case CS_RAW_32: + castBuffer.rewind(); + castBuffer.put(src, n, 4); + // FIXME overflow check + trail = castBuffer.getInt(0) & 0x7fffffff; + if(trail == 0) { + obj = top_schema.createFromRaw(new byte[0], 0, 0); + break _push; + } + cs = ACS_RAW_VALUE; + case ACS_RAW_VALUE: + obj = top_schema.createFromRaw(src, n, trail); + break _push; + case CS_ARRAY_16: + if(top >= MAX_STACK_SIZE) { + throw new UnpackException("parse error"); + } + if(!(top_schema instanceof IArraySchema)) { + throw new RuntimeException("type error"); + } + castBuffer.rewind(); + castBuffer.put(src, n, 2); + count = ((int)castBuffer.getShort(0)) & 0xffff; + obj = new Object[count]; + if(count == 0) { break _push; } // FIXME check IArraySchema + ++top; + stack_obj[top] = top_obj; + stack_ct[top] = top_ct; + stack_count[top] = top_count; + stack_schema[top] = top_schema; + top_obj = obj; + top_ct = CT_ARRAY_ITEM; + top_count = count; + top_schema = ((IArraySchema)top_schema).getElementSchema(0); + break _header_again; + case CS_ARRAY_32: + if(top >= MAX_STACK_SIZE) { + throw new UnpackException("parse error"); + } + if(!(top_schema instanceof IArraySchema)) { + throw new RuntimeException("type error"); + } + castBuffer.rewind(); + castBuffer.put(src, n, 4); + // FIXME overflow check + count = castBuffer.getInt(0) & 0x7fffffff; + obj = new Object[count]; + if(count == 0) { break _push; } // FIXME check IArraySchema + ++top; + stack_obj[top] = top_obj; + stack_ct[top] = top_ct; + stack_count[top] = top_count; + stack_schema[top] = top_schema; + top_obj = obj; + top_ct = CT_ARRAY_ITEM; + top_count = count; + top_schema = ((IArraySchema)top_schema).getElementSchema(0); + break _header_again; + case CS_MAP_16: + if(top >= MAX_STACK_SIZE) { + throw new UnpackException("parse error"); + } + if(!(top_schema instanceof IMapSchema)) { + throw new RuntimeException("type error"); + } + castBuffer.rewind(); + castBuffer.put(src, n, 2); + count = ((int)castBuffer.getShort(0)) & 0xffff; + obj = new Object[count*2]; + if(count == 0) { break _push; } // FIXME check IMapSchema + //System.out.println("fixmap count:"+count); + ++top; + stack_obj[top] = top_obj; + stack_ct[top] = top_ct; + stack_count[top] = top_count; + stack_schema[top] = top_schema; + top_obj = obj; + top_ct = CT_MAP_KEY; + top_count = count; + top_schema = ((IMapSchema)top_schema).getKeySchema(); + break _header_again; + case CS_MAP_32: + if(top >= MAX_STACK_SIZE) { + throw new UnpackException("parse error"); + } + if(!(top_schema instanceof IMapSchema)) { + throw new RuntimeException("type error"); + } + castBuffer.rewind(); + castBuffer.put(src, n, 4); + // FIXME overflow check + count = castBuffer.getInt(0) & 0x7fffffff; + obj = new Object[count*2]; + if(count == 0) { break _push; } // FIXME check IMapSchema + //System.out.println("fixmap count:"+count); + ++top; + stack_obj[top] = top_obj; + stack_ct[top] = top_ct; + stack_count[top] = top_count; + stack_schema[top] = top_schema; + top_obj = obj; + top_ct = CT_MAP_KEY; + top_count = count; + top_schema = ((IMapSchema)top_schema).getKeySchema(); + break _header_again; + default: + throw new UnpackException("parse error"); + } + + } // _fixed_trail_again + } while(true); + } // _push + + do { + _push: { + //System.out.println("push top:"+top); + if(top == -1) { + ++i; + data = obj; + finished = true; + break _out; + } + + switch(top_ct) { + case CT_ARRAY_ITEM: { + //System.out.println("array item "+obj); + Object[] ar = (Object[])top_obj; + ar[ar.length - top_count] = obj; + if(--top_count == 0) { + top_obj = stack_obj[top]; + top_ct = stack_ct[top]; + top_count = stack_count[top]; + top_schema = stack_schema[top]; + obj = ((IArraySchema)top_schema).createFromArray(ar); + stack_obj[top] = null; + stack_schema[top] = null; + --top; + break _push; + } else { + top_schema = ((IArraySchema)stack_schema[top]).getElementSchema(ar.length - top_count); + } + break _header_again; + } + case CT_MAP_KEY: { + //System.out.println("map key:"+top+" "+obj); + Object[] mp = (Object[])top_obj; + mp[mp.length - top_count*2] = obj; + top_ct = CT_MAP_VALUE; + top_schema = ((IMapSchema)stack_schema[top]).getValueSchema(); + break _header_again; + } + case CT_MAP_VALUE: { + //System.out.println("map value:"+top+" "+obj); + Object[] mp = (Object[])top_obj; + mp[mp.length - top_count*2 + 1] = obj; + if(--top_count == 0) { + top_obj = stack_obj[top]; + top_ct = stack_ct[top]; + top_count = stack_count[top]; + top_schema = stack_schema[top]; + obj = ((IMapSchema)top_schema).createFromMap(mp); + stack_obj[top] = null; + stack_schema[top] = null; + --top; + break _push; + } + top_ct = CT_MAP_KEY; + break _header_again; + } + default: + throw new UnpackException("parse error"); + } + } // _push + } while(true); + + } // _header_again + cs = CS_HEADER; + ++i; + } while(i < limit); // _out + + return i; + } +} + diff --git a/java/src/main/java/org/msgpack/impl/UnpackerImpl.java b/java/src/main/java/org/msgpack/impl/UnpackerImpl.java deleted file mode 100644 index adc62b0..0000000 --- a/java/src/main/java/org/msgpack/impl/UnpackerImpl.java +++ /dev/null @@ -1,500 +0,0 @@ -// -// MessagePack for Java -// -// Copyright (C) 2009-2010 FURUHASHI Sadayuki -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -package org.msgpack.impl; - -import java.nio.ByteBuffer; -//import java.math.BigInteger; -import org.msgpack.*; -import org.msgpack.schema.GenericSchema; -import org.msgpack.schema.IMapSchema; -import org.msgpack.schema.IArraySchema; - -public class UnpackerImpl { - static final int CS_HEADER = 0x00; - static final int CS_FLOAT = 0x0a; - static final int CS_DOUBLE = 0x0b; - static final int CS_UINT_8 = 0x0c; - static final int CS_UINT_16 = 0x0d; - static final int CS_UINT_32 = 0x0e; - static final int CS_UINT_64 = 0x0f; - static final int CS_INT_8 = 0x10; - static final int CS_INT_16 = 0x11; - static final int CS_INT_32 = 0x12; - static final int CS_INT_64 = 0x13; - static final int CS_RAW_16 = 0x1a; - static final int CS_RAW_32 = 0x1b; - static final int CS_ARRAY_16 = 0x1c; - static final int CS_ARRAY_32 = 0x1d; - static final int CS_MAP_16 = 0x1e; - static final int CS_MAP_32 = 0x1f; - static final int ACS_RAW_VALUE = 0x20; - static final int CT_ARRAY_ITEM = 0x00; - static final int CT_MAP_KEY = 0x01; - static final int CT_MAP_VALUE = 0x02; - - static final int MAX_STACK_SIZE = 16; - - private int cs; - private int trail; - private int top; - private int[] stack_ct = new int[MAX_STACK_SIZE]; - private int[] stack_count = new int[MAX_STACK_SIZE]; - private Object[] stack_obj = new Object[MAX_STACK_SIZE]; - private Schema[] stack_schema = new Schema[MAX_STACK_SIZE]; - private int top_ct; - private int top_count; - private Object top_obj; - private Schema top_schema; - private ByteBuffer castBuffer = ByteBuffer.allocate(8); - private boolean finished = false; - private Object data = null; - - private static final Schema GENERIC_SCHEMA = new GenericSchema(); - private Schema rootSchema; - - protected UnpackerImpl() - { - setSchema(GENERIC_SCHEMA); - } - - protected void setSchema(Schema schema) - { - this.rootSchema = schema; - reset(); - } - - protected Object getData() - { - return data; - } - - protected boolean isFinished() - { - return finished; - } - - protected void reset() - { - cs = CS_HEADER; - top = -1; - finished = false; - data = null; - top_ct = 0; - top_count = 0; - top_obj = null; - top_schema = rootSchema; - } - - @SuppressWarnings("unchecked") - protected int execute(byte[] src, int off, int length) throws UnpackException - { - if(off >= length) { return off; } - - int limit = length; - int i = off; - int count; - - Object obj = null; - - _out: do { - _header_again: { - //System.out.println("while i:"+i+" limit:"+limit); - - int b = src[i]; - - _push: { - _fixed_trail_again: - if(cs == CS_HEADER) { - - if((b & 0x80) == 0) { // Positive Fixnum - //System.out.println("positive fixnum "+b); - obj = top_schema.createFromByte((byte)b); - break _push; - } - - if((b & 0xe0) == 0xe0) { // Negative Fixnum - //System.out.println("negative fixnum "+b); - obj = top_schema.createFromByte((byte)b); - break _push; - } - - if((b & 0xe0) == 0xa0) { // FixRaw - trail = b & 0x1f; - if(trail == 0) { - obj = top_schema.createFromRaw(new byte[0], 0, 0); - break _push; - } - cs = ACS_RAW_VALUE; - break _fixed_trail_again; - } - - if((b & 0xf0) == 0x90) { // FixArray - if(top >= MAX_STACK_SIZE) { - throw new UnpackException("parse error"); - } - if(!(top_schema instanceof IArraySchema)) { - throw new RuntimeException("type error"); - } - count = b & 0x0f; - //System.out.println("fixarray count:"+count); - obj = new Object[count]; - if(count == 0) { break _push; } // FIXME check IArraySchema - ++top; - stack_obj[top] = top_obj; - stack_ct[top] = top_ct; - stack_count[top] = top_count; - stack_schema[top] = top_schema; - top_obj = obj; - top_ct = CT_ARRAY_ITEM; - top_count = count; - top_schema = ((IArraySchema)top_schema).getElementSchema(0); - break _header_again; - } - - if((b & 0xf0) == 0x80) { // FixMap - if(top >= MAX_STACK_SIZE) { - throw new UnpackException("parse error"); - } - if(!(top_schema instanceof IMapSchema)) { - throw new RuntimeException("type error"); - } - count = b & 0x0f; - obj = new Object[count*2]; - if(count == 0) { break _push; } // FIXME check IMapSchema - //System.out.println("fixmap count:"+count); - ++top; - stack_obj[top] = top_obj; - stack_ct[top] = top_ct; - stack_count[top] = top_count; - stack_schema[top] = top_schema; - top_obj = obj; - top_ct = CT_MAP_KEY; - top_count = count; - top_schema = ((IMapSchema)top_schema).getKeySchema(); - break _header_again; - } - - switch(b & 0xff) { // FIXME - case 0xc0: // nil - obj = top_schema.createFromNil(); - break _push; - case 0xc2: // false - obj = top_schema.createFromBoolean(false); - break _push; - case 0xc3: // true - obj = top_schema.createFromBoolean(true); - break _push; - case 0xca: // float - case 0xcb: // double - case 0xcc: // unsigned int 8 - case 0xcd: // unsigned int 16 - case 0xce: // unsigned int 32 - case 0xcf: // unsigned int 64 - case 0xd0: // signed int 8 - case 0xd1: // signed int 16 - case 0xd2: // signed int 32 - case 0xd3: // signed int 64 - trail = 1 << (b & 0x03); - cs = b & 0x1f; - //System.out.println("a trail "+trail+" cs:"+cs); - break _fixed_trail_again; - case 0xda: // raw 16 - case 0xdb: // raw 32 - case 0xdc: // array 16 - case 0xdd: // array 32 - case 0xde: // map 16 - case 0xdf: // map 32 - trail = 2 << (b & 0x01); - cs = b & 0x1f; - //System.out.println("b trail "+trail+" cs:"+cs); - break _fixed_trail_again; - default: - //System.out.println("unknown b "+(b&0xff)); - throw new UnpackException("parse error"); - } - - } // _fixed_trail_again - - do { - _fixed_trail_again: { - - if(limit - i <= trail) { break _out; } - int n = i + 1; - i += trail; - - switch(cs) { - case CS_FLOAT: - castBuffer.rewind(); - castBuffer.put(src, n, 4); - obj = top_schema.createFromFloat( castBuffer.getFloat(0) ); - //System.out.println("float "+obj); - break _push; - case CS_DOUBLE: - castBuffer.rewind(); - castBuffer.put(src, n, 8); - obj = top_schema.createFromDouble( castBuffer.getDouble(0) ); - //System.out.println("double "+obj); - break _push; - case CS_UINT_8: - //System.out.println(n); - //System.out.println(src[n]); - //System.out.println(src[n+1]); - //System.out.println(src[n-1]); - obj = top_schema.createFromShort( (short)((src[n]) & 0xff) ); - //System.out.println("uint8 "+obj); - break _push; - case CS_UINT_16: - //System.out.println(src[n]); - //System.out.println(src[n+1]); - castBuffer.rewind(); - castBuffer.put(src, n, 2); - obj = top_schema.createFromInt( ((int)castBuffer.getShort(0)) & 0xffff ); - //System.out.println("uint 16 "+obj); - break _push; - case CS_UINT_32: - castBuffer.rewind(); - castBuffer.put(src, n, 4); - obj = top_schema.createFromLong( ((long)castBuffer.getInt(0)) & 0xffffffffL ); - //System.out.println("uint 32 "+obj); - break _push; - case CS_UINT_64: - castBuffer.rewind(); - castBuffer.put(src, n, 8); - { - long o = castBuffer.getLong(0); - if(o < 0) { - // FIXME - //obj = GenericBigInteger.valueOf(o & 0x7fffffffL).setBit(31); - throw new UnpackException("uint 64 bigger than 0x7fffffff is not supported"); - } else { - obj = top_schema.createFromLong( o ); - } - } - break _push; - case CS_INT_8: - obj = top_schema.createFromByte( src[n] ); - break _push; - case CS_INT_16: - castBuffer.rewind(); - castBuffer.put(src, n, 2); - obj = top_schema.createFromShort( castBuffer.getShort(0) ); - break _push; - case CS_INT_32: - castBuffer.rewind(); - castBuffer.put(src, n, 4); - obj = top_schema.createFromInt( castBuffer.getInt(0) ); - break _push; - case CS_INT_64: - castBuffer.rewind(); - castBuffer.put(src, n, 8); - obj = top_schema.createFromLong( castBuffer.getLong(0) ); - break _push; - case CS_RAW_16: - castBuffer.rewind(); - castBuffer.put(src, n, 2); - trail = ((int)castBuffer.getShort(0)) & 0xffff; - if(trail == 0) { - obj = top_schema.createFromRaw(new byte[0], 0, 0); - break _push; - } - cs = ACS_RAW_VALUE; - break _fixed_trail_again; - case CS_RAW_32: - castBuffer.rewind(); - castBuffer.put(src, n, 4); - // FIXME overflow check - trail = castBuffer.getInt(0) & 0x7fffffff; - if(trail == 0) { - obj = top_schema.createFromRaw(new byte[0], 0, 0); - break _push; - } - cs = ACS_RAW_VALUE; - case ACS_RAW_VALUE: - obj = top_schema.createFromRaw(src, n, trail); - break _push; - case CS_ARRAY_16: - if(top >= MAX_STACK_SIZE) { - throw new UnpackException("parse error"); - } - if(!(top_schema instanceof IArraySchema)) { - throw new RuntimeException("type error"); - } - castBuffer.rewind(); - castBuffer.put(src, n, 2); - count = ((int)castBuffer.getShort(0)) & 0xffff; - obj = new Object[count]; - if(count == 0) { break _push; } // FIXME check IArraySchema - ++top; - stack_obj[top] = top_obj; - stack_ct[top] = top_ct; - stack_count[top] = top_count; - stack_schema[top] = top_schema; - top_obj = obj; - top_ct = CT_ARRAY_ITEM; - top_count = count; - top_schema = ((IArraySchema)top_schema).getElementSchema(0); - break _header_again; - case CS_ARRAY_32: - if(top >= MAX_STACK_SIZE) { - throw new UnpackException("parse error"); - } - if(!(top_schema instanceof IArraySchema)) { - throw new RuntimeException("type error"); - } - castBuffer.rewind(); - castBuffer.put(src, n, 4); - // FIXME overflow check - count = castBuffer.getInt(0) & 0x7fffffff; - obj = new Object[count]; - if(count == 0) { break _push; } // FIXME check IArraySchema - ++top; - stack_obj[top] = top_obj; - stack_ct[top] = top_ct; - stack_count[top] = top_count; - stack_schema[top] = top_schema; - top_obj = obj; - top_ct = CT_ARRAY_ITEM; - top_count = count; - top_schema = ((IArraySchema)top_schema).getElementSchema(0); - break _header_again; - case CS_MAP_16: - if(top >= MAX_STACK_SIZE) { - throw new UnpackException("parse error"); - } - if(!(top_schema instanceof IMapSchema)) { - throw new RuntimeException("type error"); - } - castBuffer.rewind(); - castBuffer.put(src, n, 2); - count = ((int)castBuffer.getShort(0)) & 0xffff; - obj = new Object[count*2]; - if(count == 0) { break _push; } // FIXME check IMapSchema - //System.out.println("fixmap count:"+count); - ++top; - stack_obj[top] = top_obj; - stack_ct[top] = top_ct; - stack_count[top] = top_count; - stack_schema[top] = top_schema; - top_obj = obj; - top_ct = CT_MAP_KEY; - top_count = count; - top_schema = ((IMapSchema)top_schema).getKeySchema(); - break _header_again; - case CS_MAP_32: - if(top >= MAX_STACK_SIZE) { - throw new UnpackException("parse error"); - } - if(!(top_schema instanceof IMapSchema)) { - throw new RuntimeException("type error"); - } - castBuffer.rewind(); - castBuffer.put(src, n, 4); - // FIXME overflow check - count = castBuffer.getInt(0) & 0x7fffffff; - obj = new Object[count*2]; - if(count == 0) { break _push; } // FIXME check IMapSchema - //System.out.println("fixmap count:"+count); - ++top; - stack_obj[top] = top_obj; - stack_ct[top] = top_ct; - stack_count[top] = top_count; - stack_schema[top] = top_schema; - top_obj = obj; - top_ct = CT_MAP_KEY; - top_count = count; - top_schema = ((IMapSchema)top_schema).getKeySchema(); - break _header_again; - default: - throw new UnpackException("parse error"); - } - - } // _fixed_trail_again - } while(true); - } // _push - - do { - _push: { - //System.out.println("push top:"+top); - if(top == -1) { - ++i; - data = obj; - finished = true; - break _out; - } - - switch(top_ct) { - case CT_ARRAY_ITEM: { - //System.out.println("array item "+obj); - Object[] ar = (Object[])top_obj; - ar[ar.length - top_count] = obj; - if(--top_count == 0) { - top_obj = stack_obj[top]; - top_ct = stack_ct[top]; - top_count = stack_count[top]; - top_schema = stack_schema[top]; - obj = ((IArraySchema)top_schema).createFromArray(ar); - stack_obj[top] = null; - stack_schema[top] = null; - --top; - break _push; - } else { - top_schema = ((IArraySchema)stack_schema[top]).getElementSchema(ar.length - top_count); - } - break _header_again; - } - case CT_MAP_KEY: { - //System.out.println("map key:"+top+" "+obj); - Object[] mp = (Object[])top_obj; - mp[mp.length - top_count*2] = obj; - top_ct = CT_MAP_VALUE; - top_schema = ((IMapSchema)stack_schema[top]).getValueSchema(); - break _header_again; - } - case CT_MAP_VALUE: { - //System.out.println("map value:"+top+" "+obj); - Object[] mp = (Object[])top_obj; - mp[mp.length - top_count*2 + 1] = obj; - if(--top_count == 0) { - top_obj = stack_obj[top]; - top_ct = stack_ct[top]; - top_count = stack_count[top]; - top_schema = stack_schema[top]; - obj = ((IMapSchema)top_schema).createFromMap(mp); - stack_obj[top] = null; - stack_schema[top] = null; - --top; - break _push; - } - top_ct = CT_MAP_KEY; - break _header_again; - } - default: - throw new UnpackException("parse error"); - } - } // _push - } while(true); - - } // _header_again - cs = CS_HEADER; - ++i; - } while(i < limit); // _out - - return i; - } -} - diff --git a/java/src/test/java/org/msgpack/TestDirectConversion.java b/java/src/test/java/org/msgpack/TestDirectConversion.java new file mode 100644 index 0000000..d77fe13 --- /dev/null +++ b/java/src/test/java/org/msgpack/TestDirectConversion.java @@ -0,0 +1,154 @@ +package org.msgpack; + +import org.msgpack.*; +import java.io.*; +import java.util.*; + +import org.junit.Test; +import static org.junit.Assert.*; + +public class TestDirectConversion { + private UnpackCursor prepareCursor(ByteArrayOutputStream out) { + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + Unpacker upk = new Unpacker(in); + return upk.begin(); + } + + @Test + public void testInt() throws Exception { + testInt(0); + testInt(-1); + testInt(1); + testInt(Integer.MIN_VALUE); + testInt(Integer.MAX_VALUE); + Random rand = new Random(); + for (int i = 0; i < 1000; i++) + testInt(rand.nextInt()); + } + public void testInt(int val) throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + new Packer(out).pack(val); + UnpackCursor c = prepareCursor(out); + assertEquals(val, c.unpackInt()); + c.commit(); + } + + @Test + public void testFloat() throws Exception { + testFloat((float)0.0); + testFloat((float)-0.0); + testFloat((float)1.0); + testFloat((float)-1.0); + testFloat((float)Float.MAX_VALUE); + testFloat((float)Float.MIN_VALUE); + testFloat((float)Float.NaN); + testFloat((float)Float.NEGATIVE_INFINITY); + testFloat((float)Float.POSITIVE_INFINITY); + Random rand = new Random(); + for (int i = 0; i < 1000; i++) + testFloat(rand.nextFloat()); + } + public void testFloat(float val) throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + new Packer(out).pack(val); + UnpackCursor c = prepareCursor(out); + float f = c.unpackFloat(); + if(Float.isNaN(val)) { + assertTrue(Float.isNaN(f)); + } else { + assertEquals(val, f, 10e-10); + } + c.commit(); + } + + @Test + public void testDouble() throws Exception { + testDouble((double)0.0); + testDouble((double)-0.0); + testDouble((double)1.0); + testDouble((double)-1.0); + testDouble((double)Double.MAX_VALUE); + testDouble((double)Double.MIN_VALUE); + testDouble((double)Double.NaN); + testDouble((double)Double.NEGATIVE_INFINITY); + testDouble((double)Double.POSITIVE_INFINITY); + Random rand = new Random(); + for (int i = 0; i < 1000; i++) + testDouble(rand.nextDouble()); + } + public void testDouble(double val) throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + new Packer(out).pack(val); + UnpackCursor c = prepareCursor(out); + double f = c.unpackDouble(); + if(Double.isNaN(val)) { + assertTrue(Double.isNaN(f)); + } else { + assertEquals(val, f, 10e-10); + } + c.commit(); + } + + @Test + public void testNil() throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + new Packer(out).packNil(); + UnpackCursor c = prepareCursor(out); + assertEquals(null, c.unpackNull()); + c.commit(); + } + + @Test + public void testBoolean() throws Exception { + testBoolean(false); + testBoolean(true); + } + public void testBoolean(boolean val) throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + new Packer(out).pack(val); + UnpackCursor c = prepareCursor(out); + assertEquals(val, c.unpackBoolean()); + c.commit(); + } + + @Test + public void testString() throws Exception { + testString(""); + testString("a"); + testString("ab"); + testString("abc"); + // small size string + for (int i = 0; i < 100; i++) { + StringBuilder sb = new StringBuilder(); + int len = (int)Math.random() % 31 + 1; + for (int j = 0; j < len; j++) + sb.append('a' + ((int)Math.random()) & 26); + testString(sb.toString()); + } + // medium size string + for (int i = 0; i < 100; i++) { + StringBuilder sb = new StringBuilder(); + int len = (int)Math.random() % 100 + (1 << 15); + for (int j = 0; j < len; j++) + sb.append('a' + ((int)Math.random()) & 26); + testString(sb.toString()); + } + // large size string + for (int i = 0; i < 10; i++) { + StringBuilder sb = new StringBuilder(); + int len = (int)Math.random() % 100 + (1 << 31); + for (int j = 0; j < len; j++) + sb.append('a' + ((int)Math.random()) & 26); + testString(sb.toString()); + } + } + public void testString(String val) throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + new Packer(out).pack(val); + UnpackCursor c = prepareCursor(out); + assertEquals(val, c.unpackString()); + c.commit(); + } + + // FIXME container types +}; diff --git a/java/src/test/java/org/msgpack/TestPackUnpack.java b/java/src/test/java/org/msgpack/TestPackUnpack.java index 6877853..a16b5b1 100644 --- a/java/src/test/java/org/msgpack/TestPackUnpack.java +++ b/java/src/test/java/org/msgpack/TestPackUnpack.java @@ -237,5 +237,5 @@ public class TestPackUnpack { System.out.println("Got unexpected class: " + obj.getClass()); assertTrue(false); } - } + } }; -- cgit v1.2.1 From 135a9f558600ddbd4cd0d07a57ae1f7fb5b8634a Mon Sep 17 00:00:00 2001 From: frsyuki Date: Thu, 20 May 2010 05:44:44 +0900 Subject: java: fix direct conversion API --- .../java/org/msgpack/BufferedUnpackerImpl.java | 205 +++++++++++---------- .../main/java/org/msgpack/MessageUnpackable.java | 2 +- java/src/main/java/org/msgpack/UnpackCursor.java | 96 ---------- java/src/main/java/org/msgpack/UnpackIterator.java | 1 + java/src/main/java/org/msgpack/Unpacker.java | 102 ++++++---- .../java/org/msgpack/schema/ClassGenerator.java | 10 +- .../org/msgpack/schema/SpecificClassSchema.java | 4 +- .../java/org/msgpack/TestDirectConversion.java | 42 ++--- java/test/README | 2 +- .../tpc/src/serializers/BenchmarkRunner.java | 2 + .../tpc/src/serializers/msgpack/MediaContent.java | 78 +++++++- .../msgpack/MessagePackDirectSerializer.java | 68 +++++++ .../msgpack/MessagePackDynamicSerializer.java | 2 +- .../msgpack/MessagePackGenericSerializer.java | 2 +- .../msgpack/MessagePackIndirectSerializer.java | 2 +- .../msgpack/MessagePackSpecificSerializer.java | 2 +- 16 files changed, 356 insertions(+), 264 deletions(-) delete mode 100644 java/src/main/java/org/msgpack/UnpackCursor.java create mode 100644 java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackDirectSerializer.java (limited to 'java') diff --git a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java index 0ef9c12..5fde4e1 100644 --- a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java +++ b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java @@ -22,16 +22,17 @@ import java.nio.ByteBuffer; //import java.math.BigInteger; abstract class BufferedUnpackerImpl extends UnpackerImpl { + int offset = 0; int filled = 0; byte[] buffer = null; private ByteBuffer castBuffer = ByteBuffer.allocate(8); abstract boolean fill() throws IOException; - final int next(int offset, UnpackResult result) throws IOException, UnpackException { + final boolean next(UnpackResult result) throws IOException, UnpackException { if(filled == 0) { if(!fill()) { - return offset; + return false; } } @@ -39,8 +40,9 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { int noffset = super.execute(buffer, offset, filled); if(noffset <= offset) { if(!fill()) { - return offset; + return false; } + continue; } offset = noffset; } while(!super.isFinished()); @@ -49,10 +51,10 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { super.reset(); result.done(obj); - return offset; + return true; } - private final void more(int offset, int require) throws IOException, UnpackException { + private final void more(int require) throws IOException, UnpackException { while(filled - offset < require) { if(!fill()) { // FIXME @@ -61,41 +63,46 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { } } - final byte unpackByte(UnpackCursor c, int offset) throws IOException, MessageTypeException { - int o = unpackInt(c, offset); + private final void advance(int length) { + offset += length; + } + + final byte unpackByte() throws IOException, MessageTypeException { + int o = unpackInt(); if(0x7f < o || o < -0x80) { throw new MessageTypeException(); } return (byte)o; } - final short unpackShort(UnpackCursor c, int offset) throws IOException, MessageTypeException { - int o = unpackInt(c, offset); + final short unpackShort() throws IOException, MessageTypeException { + int o = unpackInt(); if(0x7fff < o || o < -0x8000) { throw new MessageTypeException(); } return (short)o; } - final int unpackInt(UnpackCursor c, int offset) throws IOException, MessageTypeException { - more(offset, 1); + final int unpackInt() throws IOException, MessageTypeException { + more(1); int b = buffer[offset]; if((b & 0x80) == 0 || (b & 0xe0) == 0xe0) { // Fixnum + advance(1); return (int)b; } switch(b & 0xff) { case 0xcc: // unsigned int 8 - more(offset, 2); - c.advance(2); + more(2); + advance(2); return (int)((short)buffer[offset+1] & 0xff); case 0xcd: // unsigned int 16 - more(offset, 3); + more(3); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 2); - c.advance(3); + advance(3); return (int)((int)castBuffer.getShort(0) & 0xffff); case 0xce: // unsigned int 32 - more(offset, 5); + more(5); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 4); { @@ -103,11 +110,11 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { if(o < 0) { throw new MessageTypeException(); } - c.advance(5); + advance(5); return o; } case 0xcf: // unsigned int 64 - more(offset, 9); + more(9); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 8); { @@ -115,27 +122,27 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { if(o < 0 || o > 0x7fffffffL) { throw new MessageTypeException(); } - c.advance(9); + advance(9); return (int)o; } case 0xd0: // signed int 8 - more(offset, 2); - c.advance(2); + more(2); + advance(2); return (int)buffer[offset+1]; case 0xd1: // signed int 16 - more(offset, 3); + more(3); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 2); - c.advance(3); + advance(3); return (int)castBuffer.getShort(0); case 0xd2: // signed int 32 - more(offset, 4); + more(4); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 4); - c.advance(4); + advance(4); return (int)castBuffer.getInt(0); case 0xd3: // signed int 64 - more(offset, 9); + more(9); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 8); { @@ -143,7 +150,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { if(0x7fffffffL < o || o < -0x80000000L) { throw new MessageTypeException(); } - c.advance(9); + advance(9); return (int)o; } default: @@ -151,31 +158,32 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { } } - final long unpackLong(UnpackCursor c, int offset) throws IOException, MessageTypeException { - more(offset, 1); + final long unpackLong() throws IOException, MessageTypeException { + more(1); int b = buffer[offset]; if((b & 0x80) == 0 || (b & 0xe0) == 0xe0) { // Fixnum + advance(1); return (long)b; } switch(b & 0xff) { case 0xcc: // unsigned int 8 - more(offset, 2); - c.advance(2); + more(2); + advance(2); return (long)((short)buffer[offset+1] & 0xff); case 0xcd: // unsigned int 16 - more(offset, 3); + more(3); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 2); - c.advance(3); + advance(3); return (long)((int)castBuffer.getShort(0) & 0xffff); case 0xce: // unsigned int 32 - more(offset, 5); + more(5); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 4); - c.advance(5); + advance(5); return ((long)castBuffer.getInt(0) & 0xffffffffL); case 0xcf: // unsigned int 64 - more(offset, 9); + more(9); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 8); { @@ -184,51 +192,51 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { // FIXME throw new MessageTypeException("uint 64 bigger than 0x7fffffff is not supported"); } - c.advance(9); + advance(9); return o; } case 0xd0: // signed int 8 - more(offset, 2); - c.advance(2); + more(2); + advance(2); return (long)buffer[offset+1]; case 0xd1: // signed int 16 - more(offset, 3); + more(3); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 2); - c.advance(3); + advance(3); return (long)castBuffer.getShort(0); case 0xd2: // signed int 32 - more(offset, 4); + more(4); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 4); - c.advance(4); + advance(4); return (long)castBuffer.getInt(0); case 0xd3: // signed int 64 - more(offset, 9); + more(9); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 8); - c.advance(9); + advance(9); return (long)castBuffer.getLong(0); default: throw new MessageTypeException(); } } - final float unpackFloat(UnpackCursor c, int offset) throws IOException, MessageTypeException { - more(offset, 1); + final float unpackFloat() throws IOException, MessageTypeException { + more(1); int b = buffer[offset]; switch(b & 0xff) { case 0xca: // float - more(offset, 5); + more(5); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 4); - c.advance(5); + advance(5); return castBuffer.getFloat(0); case 0xcb: // double - more(offset, 9); + more(9); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 8); - c.advance(9); + advance(9); // FIXME overflow check return (float)castBuffer.getDouble(0); default: @@ -236,70 +244,70 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { } } - final double unpackDouble(UnpackCursor c, int offset) throws IOException, MessageTypeException { - more(offset, 1); + final double unpackDouble() throws IOException, MessageTypeException { + more(1); int b = buffer[offset]; switch(b & 0xff) { case 0xca: // float - more(offset, 5); + more(5); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 4); - c.advance(5); + advance(5); return (double)castBuffer.getFloat(0); case 0xcb: // double - more(offset, 9); + more(9); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 8); - c.advance(9); + advance(9); return castBuffer.getDouble(0); default: throw new MessageTypeException(); } } - final Object unpackNull(UnpackCursor c, int offset) throws IOException, MessageTypeException { - more(offset, 1); + final Object unpackNull() throws IOException, MessageTypeException { + more(1); int b = buffer[offset] & 0xff; if(b != 0xc0) { // nil throw new MessageTypeException(); } - c.advance(1); + advance(1); return null; } - final boolean unpackBoolean(UnpackCursor c, int offset) throws IOException, MessageTypeException { - more(offset, 1); + final boolean unpackBoolean() throws IOException, MessageTypeException { + more(1); int b = buffer[offset] & 0xff; if(b == 0xc2) { // false - c.advance(1); + advance(1); return false; } else if(b == 0xc3) { // true - c.advance(1); + advance(1); return true; } else { throw new MessageTypeException(); } } - final int unpackArray(UnpackCursor c, int offset) throws IOException, MessageTypeException { - more(offset, 1); + final int unpackArray() throws IOException, MessageTypeException { + more(1); int b = buffer[offset]; if((b & 0xf0) == 0x90) { // FixArray - c.advance(1); + advance(1); return (int)(b & 0x0f); } switch(b & 0xff) { case 0xdc: // array 16 - more(offset, 3); + more(3); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 2); - c.advance(3); + advance(3); return (int)castBuffer.getShort(0) & 0xffff; case 0xdd: // array 32 - more(offset, 5); + more(5); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 4); - c.advance(5); + advance(5); // FIXME overflow check return castBuffer.getInt(0) & 0x7fffffff; default: @@ -307,25 +315,25 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { } } - final int unpackMap(UnpackCursor c, int offset) throws IOException, MessageTypeException { - more(offset, 1); + final int unpackMap() throws IOException, MessageTypeException { + more(1); int b = buffer[offset]; if((b & 0xf0) == 0x80) { // FixMap - c.advance(1); + advance(1); return (int)(b & 0x0f); } switch(b & 0xff) { case 0xde: // map 16 - more(offset, 3); + more(3); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 2); - c.advance(3); + advance(3); return (int)castBuffer.getShort(0) & 0xffff; case 0xdf: // map 32 - more(offset, 5); + more(5); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 4); - c.advance(5); + advance(5); // FIXME overflow check return castBuffer.getInt(0) & 0x7fffffff; default: @@ -333,25 +341,25 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { } } - final int unpackRaw(UnpackCursor c, int offset) throws IOException, MessageTypeException { - more(offset, 1); + final int unpackRaw() throws IOException, MessageTypeException { + more(1); int b = buffer[offset]; if((b & 0xe0) == 0xa0) { // FixRaw - c.advance(1); - return (int)(b & 0x0f); + advance(1); + return (int)(b & 0x1f); } switch(b & 0xff) { case 0xda: // raw 16 - more(offset, 3); + more(3); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 2); - c.advance(3); + advance(3); return (int)castBuffer.getShort(0) & 0xffff; case 0xdb: // raw 32 - more(offset, 5); + more(5); castBuffer.rewind(); castBuffer.put(buffer, offset+1, 4); - c.advance(5); + advance(5); // FIXME overflow check return castBuffer.getInt(0) & 0x7fffffff; default: @@ -359,26 +367,35 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { } } - final byte[] unpackRawBody(UnpackCursor c, int offset, int length) throws IOException, MessageTypeException { - more(offset, length); + final byte[] unpackRawBody(int length) throws IOException, MessageTypeException { + more(length); byte[] bytes = new byte[length]; System.arraycopy(buffer, offset, bytes, 0, length); - c.advance(length); + advance(length); return bytes; } - final String unpackString(UnpackCursor c, int offset) throws IOException, MessageTypeException { - int length = unpackRaw(c, offset); - offset = c.getOffset(); - more(offset, length); + final String unpackString() throws IOException, MessageTypeException { + int length = unpackRaw(); + more(length); String s; try { s = new String(buffer, offset, length, "UTF-8"); } catch (Exception e) { throw new MessageTypeException(); } - c.advance(length); + advance(length); return s; } + + final Object unpackObject() throws IOException, MessageTypeException { + // FIXME save state, restore state + UnpackResult result = new UnpackResult(); + if(!next(result)) { + super.reset(); + throw new MessageTypeException(); + } + return result.getData(); + } } diff --git a/java/src/main/java/org/msgpack/MessageUnpackable.java b/java/src/main/java/org/msgpack/MessageUnpackable.java index 20e4d56..cc206e7 100644 --- a/java/src/main/java/org/msgpack/MessageUnpackable.java +++ b/java/src/main/java/org/msgpack/MessageUnpackable.java @@ -20,6 +20,6 @@ package org.msgpack; import java.io.IOException; public interface MessageUnpackable { - public void messageUnpack(Unpacker pk) throws IOException, MessageTypeException; + public void messageUnpack(Unpacker pac) throws IOException, MessageTypeException; } diff --git a/java/src/main/java/org/msgpack/UnpackCursor.java b/java/src/main/java/org/msgpack/UnpackCursor.java deleted file mode 100644 index 33f4258..0000000 --- a/java/src/main/java/org/msgpack/UnpackCursor.java +++ /dev/null @@ -1,96 +0,0 @@ -// -// MessagePack for Java -// -// Copyright (C) 2009-2010 FURUHASHI Sadayuki -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -package org.msgpack; - -import java.io.IOException; - -public class UnpackCursor { - private Unpacker pac; - private int offset; - - UnpackCursor(Unpacker pac, int offset) - { - this.pac = pac; - this.offset = offset; - } - - final void advance(int length) { - offset += length; - } - - final int getOffset() { - return offset; - } - - public byte unpackByte() throws IOException, MessageTypeException { - return pac.impl.unpackByte(this, offset); - } - - public short unpackShort() throws IOException, MessageTypeException { - return pac.impl.unpackShort(this, offset); - } - - public int unpackInt() throws IOException, MessageTypeException { - return pac.impl.unpackInt(this, offset); - } - - public long unpackLong() throws IOException, MessageTypeException { - return pac.impl.unpackLong(this, offset); - } - - public float unpackFloat() throws IOException, MessageTypeException { - return pac.impl.unpackFloat(this, offset); - } - - public double unpackDouble() throws IOException, MessageTypeException { - return pac.impl.unpackDouble(this, offset); - } - - public Object unpackNull() throws IOException, MessageTypeException { - return pac.impl.unpackNull(this, offset); - } - - public boolean unpackBoolean() throws IOException, MessageTypeException { - return pac.impl.unpackBoolean(this, offset); - } - - public int unpackArray() throws IOException, MessageTypeException { - return pac.impl.unpackArray(this, offset); - } - - public int unpackMap() throws IOException, MessageTypeException { - return pac.impl.unpackMap(this, offset); - } - - public int unpackRaw() throws IOException, MessageTypeException { - return pac.impl.unpackRaw(this, offset); - } - - public byte[] unpackRawBody(int length) throws IOException, MessageTypeException { - return pac.impl.unpackRawBody(this, offset, length); - } - - public String unpackString() throws IOException, MessageTypeException { - return pac.impl.unpackString(this, offset); - } - - public void commit() { - pac.setOffset(offset); - } -} - diff --git a/java/src/main/java/org/msgpack/UnpackIterator.java b/java/src/main/java/org/msgpack/UnpackIterator.java index 5cc994d..f17e229 100644 --- a/java/src/main/java/org/msgpack/UnpackIterator.java +++ b/java/src/main/java/org/msgpack/UnpackIterator.java @@ -30,6 +30,7 @@ public class UnpackIterator extends UnpackResult implements Iterator { } public boolean hasNext() { + if(finished) { return true; } try { return pac.next(this); } catch (IOException e) { diff --git a/java/src/main/java/org/msgpack/Unpacker.java b/java/src/main/java/org/msgpack/Unpacker.java index 20a8c4a..4d8da7b 100644 --- a/java/src/main/java/org/msgpack/Unpacker.java +++ b/java/src/main/java/org/msgpack/Unpacker.java @@ -36,7 +36,6 @@ public class Unpacker implements Iterable { private static final int DEFAULT_BUFFER_SIZE = 32*1024; - protected int offset; protected int parsed; protected int bufferReserveSize; protected InputStream stream; @@ -73,7 +72,6 @@ public class Unpacker implements Iterable { } public Unpacker(InputStream stream, int bufferReserveSize) { - this.offset = 0; this.parsed = 0; this.bufferReserveSize = bufferReserveSize/2; this.stream = stream; @@ -97,7 +95,7 @@ public class Unpacker implements Iterable { int length = buffer.remaining(); if (length == 0) return; reserveBuffer(length); - buffer.get(impl.buffer, this.offset, length); + buffer.get(impl.buffer, impl.offset, length); bufferConsumed(length); } @@ -107,7 +105,7 @@ public class Unpacker implements Iterable { public void feed(byte[] buffer, int offset, int length) { reserveBuffer(length); - System.arraycopy(buffer, offset, impl.buffer, this.offset, length); + System.arraycopy(buffer, offset, impl.buffer, impl.offset, length); bufferConsumed(length); } @@ -121,13 +119,12 @@ public class Unpacker implements Iterable { public UnpackResult next() throws IOException, UnpackException { UnpackResult result = new UnpackResult(); - this.offset = impl.next(this.offset, result); + impl.next(result); return result; } public boolean next(UnpackResult result) throws IOException, UnpackException { - this.offset = impl.next(this.offset, result); - return result.isFinished(); + return impl.next(result); } @@ -143,17 +140,17 @@ public class Unpacker implements Iterable { } int nextSize = impl.buffer.length * 2; - int notParsed = impl.filled - this.offset; + int notParsed = impl.filled - impl.offset; while(nextSize < require + notParsed) { nextSize *= 2; } byte[] tmp = new byte[nextSize]; - System.arraycopy(impl.buffer, this.offset, tmp, 0, impl.filled - this.offset); + System.arraycopy(impl.buffer, impl.offset, tmp, 0, impl.filled - impl.offset); impl.buffer = tmp; impl.filled = notParsed; - this.offset = 0; + impl.offset = 0; } public byte[] getBuffer() { @@ -173,12 +170,12 @@ public class Unpacker implements Iterable { } public boolean execute() throws UnpackException { - int noffset = impl.execute(impl.buffer, offset, impl.filled); - if(noffset <= offset) { + int noffset = impl.execute(impl.buffer, impl.offset, impl.filled); + if(noffset <= impl.offset) { return false; } - parsed += noffset - offset; - offset = noffset; + parsed += noffset - impl.offset; + impl.offset = noffset; return impl.isFinished(); } @@ -188,8 +185,8 @@ public class Unpacker implements Iterable { } public int execute(byte[] buffer, int offset, int length) throws UnpackException { - int noffset = impl.execute(buffer, offset + this.offset, length); - this.offset = noffset - offset; + int noffset = impl.execute(buffer, offset + impl.offset, length); + impl.offset = noffset - offset; if(impl.isFinished()) { impl.resetState(); } @@ -208,15 +205,8 @@ public class Unpacker implements Iterable { impl.reset(); } - - public UnpackCursor begin() - { - return new UnpackCursor(this, offset); - } - - public int getMessageSize() { - return parsed - offset + impl.filled; + return parsed - impl.offset + impl.filled; } public int getParsedSize() { @@ -224,22 +214,72 @@ public class Unpacker implements Iterable { } public int getNonParsedSize() { - return impl.filled - offset; + return impl.filled - impl.offset; } public void skipNonparsedBuffer(int size) { - offset += size; + impl.offset += size; } public void removeNonparsedBuffer() { - impl.filled = offset; + impl.filled = impl.offset; + } + + + final public byte unpackByte() throws IOException, MessageTypeException { + return impl.unpackByte(); + } + + final public short unpackShort() throws IOException, MessageTypeException { + return impl.unpackShort(); + } + + final public int unpackInt() throws IOException, MessageTypeException { + return impl.unpackInt(); + } + + final public long unpackLong() throws IOException, MessageTypeException { + return impl.unpackLong(); + } + + final public float unpackFloat() throws IOException, MessageTypeException { + return impl.unpackFloat(); } + final public double unpackDouble() throws IOException, MessageTypeException { + return impl.unpackDouble(); + } + + final public Object unpackNull() throws IOException, MessageTypeException { + return impl.unpackNull(); + } + + final public boolean unpackBoolean() throws IOException, MessageTypeException { + return impl.unpackBoolean(); + } + + final public int unpackArray() throws IOException, MessageTypeException { + return impl.unpackArray(); + } + + final public int unpackMap() throws IOException, MessageTypeException { + return impl.unpackMap(); + } + + final public int unpackRaw() throws IOException, MessageTypeException { + return impl.unpackRaw(); + } + + final public byte[] unpackRawBody(int length) throws IOException, MessageTypeException { + return impl.unpackRawBody(length); + } + + final public String unpackString() throws IOException, MessageTypeException { + return impl.unpackString(); + } - void setOffset(int offset) - { - parsed += offset - this.offset; - this.offset = offset; + final public Object unpackObject() throws IOException, MessageTypeException { + return impl.unpackObject(); } } diff --git a/java/src/main/java/org/msgpack/schema/ClassGenerator.java b/java/src/main/java/org/msgpack/schema/ClassGenerator.java index 061dcbb..f8a13fa 100644 --- a/java/src/main/java/org/msgpack/schema/ClassGenerator.java +++ b/java/src/main/java/org/msgpack/schema/ClassGenerator.java @@ -105,7 +105,7 @@ public class ClassGenerator { private void writeClass() throws IOException { line(); - line("public final class "+schema.getName()+" implements MessagePackable, MessageMergeable"); + line("public final class "+schema.getName()+" implements MessagePackable, MessageConvertable"); line("{"); pushIndent(); writeSchema(); @@ -117,7 +117,7 @@ public class ClassGenerator { private void writeSubclass() throws IOException { line(); - line("final class "+schema.getName()+" implements MessagePackable, MessageMergeable"); + line("final class "+schema.getName()+" implements MessagePackable, MessageConvertable"); line("{"); pushIndent(); writeSchema(); @@ -150,7 +150,7 @@ public class ClassGenerator { writeConstructors(); writeAccessors(); writePackFunction(); - writeMergeFunction(); + writeConvertFunction(); writeFactoryFunction(); } @@ -184,11 +184,11 @@ public class ClassGenerator { line("}"); } - private void writeMergeFunction() throws IOException { + private void writeConvertFunction() throws IOException { line(); line("@Override"); line("@SuppressWarnings(\"unchecked\")"); - line("public void messageMerge(Object obj) throws MessageTypeException"); + line("public void messageConvert(Object obj) throws MessageTypeException"); line("{"); pushIndent(); line("Object[] _source = ((List)obj).toArray();"); diff --git a/java/src/main/java/org/msgpack/schema/SpecificClassSchema.java b/java/src/main/java/org/msgpack/schema/SpecificClassSchema.java index 30bd9e1..850f621 100644 --- a/java/src/main/java/org/msgpack/schema/SpecificClassSchema.java +++ b/java/src/main/java/org/msgpack/schema/SpecificClassSchema.java @@ -59,8 +59,8 @@ public class SpecificClassSchema extends ClassSchema { cacheConstructor(); } try { - MessageMergeable o = (MessageMergeable)constructorCache.newInstance((Object[])null); - o.messageMerge(obj); + MessageConvertable o = (MessageConvertable)constructorCache.newInstance((Object[])null); + o.messageConvert(obj); return o; } catch (InvocationTargetException e) { throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage()); diff --git a/java/src/test/java/org/msgpack/TestDirectConversion.java b/java/src/test/java/org/msgpack/TestDirectConversion.java index d77fe13..77bbc58 100644 --- a/java/src/test/java/org/msgpack/TestDirectConversion.java +++ b/java/src/test/java/org/msgpack/TestDirectConversion.java @@ -8,12 +8,6 @@ import org.junit.Test; import static org.junit.Assert.*; public class TestDirectConversion { - private UnpackCursor prepareCursor(ByteArrayOutputStream out) { - ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); - Unpacker upk = new Unpacker(in); - return upk.begin(); - } - @Test public void testInt() throws Exception { testInt(0); @@ -28,9 +22,9 @@ public class TestDirectConversion { public void testInt(int val) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); new Packer(out).pack(val); - UnpackCursor c = prepareCursor(out); - assertEquals(val, c.unpackInt()); - c.commit(); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + Unpacker upk = new Unpacker(in); + assertEquals(val, upk.unpackInt()); } @Test @@ -51,14 +45,14 @@ public class TestDirectConversion { public void testFloat(float val) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); new Packer(out).pack(val); - UnpackCursor c = prepareCursor(out); - float f = c.unpackFloat(); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + Unpacker upk = new Unpacker(in); + float f = upk.unpackFloat(); if(Float.isNaN(val)) { assertTrue(Float.isNaN(f)); } else { assertEquals(val, f, 10e-10); } - c.commit(); } @Test @@ -79,23 +73,23 @@ public class TestDirectConversion { public void testDouble(double val) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); new Packer(out).pack(val); - UnpackCursor c = prepareCursor(out); - double f = c.unpackDouble(); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + Unpacker upk = new Unpacker(in); + double f = upk.unpackDouble(); if(Double.isNaN(val)) { assertTrue(Double.isNaN(f)); } else { assertEquals(val, f, 10e-10); } - c.commit(); } @Test public void testNil() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); new Packer(out).packNil(); - UnpackCursor c = prepareCursor(out); - assertEquals(null, c.unpackNull()); - c.commit(); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + Unpacker upk = new Unpacker(in); + assertEquals(null, upk.unpackNull()); } @Test @@ -106,9 +100,9 @@ public class TestDirectConversion { public void testBoolean(boolean val) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); new Packer(out).pack(val); - UnpackCursor c = prepareCursor(out); - assertEquals(val, c.unpackBoolean()); - c.commit(); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + Unpacker upk = new Unpacker(in); + assertEquals(val, upk.unpackBoolean()); } @Test @@ -145,9 +139,9 @@ public class TestDirectConversion { public void testString(String val) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); new Packer(out).pack(val); - UnpackCursor c = prepareCursor(out); - assertEquals(val, c.unpackString()); - c.commit(); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + Unpacker upk = new Unpacker(in); + assertEquals(val, upk.unpackString()); } // FIXME container types diff --git a/java/test/README b/java/test/README index 4e16454..9b98d91 100644 --- a/java/test/README +++ b/java/test/README @@ -1,7 +1,7 @@ #!/bin/sh svn checkout -r114 http://thrift-protobuf-compare.googlecode.com/svn/trunk/ thrift-protobuf-compare-base cp -rf thrift-protobuf-compare/tpc thrift-protobuf-compare-base -cp ../dist/msgpack.jar thrift-protobuf-compare-base/tpc/lib/ +cp ../target/msgpack*.jar thrift-protobuf-compare-base/tpc/lib/msgpack.jar cd thrift-protobuf-compare-base/tpc/ ant compile ./run-benchmark.sh diff --git a/java/test/thrift-protobuf-compare/tpc/src/serializers/BenchmarkRunner.java b/java/test/thrift-protobuf-compare/tpc/src/serializers/BenchmarkRunner.java index b17dfb2..fa88b6b 100644 --- a/java/test/thrift-protobuf-compare/tpc/src/serializers/BenchmarkRunner.java +++ b/java/test/thrift-protobuf-compare/tpc/src/serializers/BenchmarkRunner.java @@ -11,6 +11,7 @@ import java.util.Map; import java.util.Set; import java.util.Map.Entry; +import serializers.msgpack.MessagePackDirectSerializer; import serializers.msgpack.MessagePackSpecificSerializer; import serializers.msgpack.MessagePackIndirectSerializer; import serializers.msgpack.MessagePackDynamicSerializer; @@ -39,6 +40,7 @@ public class BenchmarkRunner BenchmarkRunner runner = new BenchmarkRunner(); // binary codecs first + runner.addObjectSerializer(new MessagePackDirectSerializer()); runner.addObjectSerializer(new MessagePackSpecificSerializer()); runner.addObjectSerializer(new MessagePackIndirectSerializer()); runner.addObjectSerializer(new MessagePackDynamicSerializer()); diff --git a/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MediaContent.java b/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MediaContent.java index 5dfbc8d..e750b5a 100644 --- a/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MediaContent.java +++ b/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MediaContent.java @@ -6,7 +6,7 @@ import org.msgpack.*; import org.msgpack.schema.ClassSchema; import org.msgpack.schema.FieldSchema; -public final class MediaContent implements MessagePackable, MessageMergeable +public final class MediaContent implements MessagePackable, MessageConvertable, MessageUnpackable { private static final ClassSchema _SCHEMA = (ClassSchema)Schema.load("(class MediaContent (package serializers.msgpack) (field image (array (class Image (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field size int)))) (field media (class Media (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field format string) (field duration long) (field size long) (field bitrate int) (field person (array string)) (field player int) (field copyright string))))"); public static ClassSchema getSchema() { return _SCHEMA; } @@ -27,7 +27,7 @@ public final class MediaContent implements MessagePackable, MessageMergeable @Override @SuppressWarnings("unchecked") - public void messageMerge(Object obj) throws MessageTypeException + public void messageConvert(Object obj) throws MessageTypeException { Object[] _source = ((List)obj).toArray(); FieldSchema[] _fields = _SCHEMA.getFields(); @@ -35,6 +35,23 @@ public final class MediaContent implements MessagePackable, MessageMergeable if(_source.length <= 1) { return; } this.media = (Media)_fields[1].getSchema().convert(_source[1]); } + @Override + public void messageUnpack(Unpacker _pac) throws IOException, MessageTypeException { + int _length = _pac.unpackArray(); + if(_length <= 0) { return; } + int _image_length = _pac.unpackArray(); + this.image = new ArrayList(_image_length); + for(int _i=0; _i < _image_length; ++_i) { + Image _image_i = new Image(); + _image_i.messageUnpack(_pac); + this.image.add(_image_i); + } + if(_length <= 1) { return; } + this.media = new Media(); + this.media.messageUnpack(_pac); + for(int _i=2; _i < _length; ++_i) { _pac.unpackObject(); } + } + @SuppressWarnings("unchecked") public static MediaContent createFromMessage(Object[] _message) { @@ -45,7 +62,7 @@ public final class MediaContent implements MessagePackable, MessageMergeable } } -final class Image implements MessagePackable, MessageMergeable +final class Image implements MessagePackable, MessageConvertable, MessageUnpackable { private static final ClassSchema _SCHEMA = (ClassSchema)Schema.load("(class Image (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field size int))"); public static ClassSchema getSchema() { return _SCHEMA; } @@ -72,7 +89,7 @@ final class Image implements MessagePackable, MessageMergeable @Override @SuppressWarnings("unchecked") - public void messageMerge(Object obj) throws MessageTypeException + public void messageConvert(Object obj) throws MessageTypeException { Object[] _source = ((List)obj).toArray(); FieldSchema[] _fields = _SCHEMA.getFields(); @@ -83,6 +100,22 @@ final class Image implements MessagePackable, MessageMergeable if(_source.length <= 4) { return; } this.size = (Integer)_fields[4].getSchema().convert(_source[4]); } + @Override + public void messageUnpack(Unpacker _pac) throws IOException, MessageTypeException { + int _length = _pac.unpackArray(); + if(_length <= 0) { return; } + this.uri = _pac.unpackString(); + if(_length <= 1) { return; } + this.title = _pac.unpackString(); + if(_length <= 2) { return; } + this.width = _pac.unpackInt(); + if(_length <= 3) { return; } + this.height = _pac.unpackInt(); + if(_length <= 4) { return; } + this.size = _pac.unpackInt(); + for(int _i=5; _i < _length; ++_i) { _pac.unpackObject(); } + } + @SuppressWarnings("unchecked") public static Image createFromMessage(Object[] _message) { @@ -96,7 +129,7 @@ final class Image implements MessagePackable, MessageMergeable } } -final class Media implements MessagePackable, MessageMergeable +final class Media implements MessagePackable, MessageConvertable, MessageUnpackable { private static final ClassSchema _SCHEMA = (ClassSchema)Schema.load("(class Media (package serializers.msgpack) (field uri string) (field title string) (field width int) (field height int) (field format string) (field duration long) (field size long) (field bitrate int) (field person (array string)) (field player int) (field copyright string))"); public static ClassSchema getSchema() { return _SCHEMA; } @@ -135,7 +168,7 @@ final class Media implements MessagePackable, MessageMergeable @Override @SuppressWarnings("unchecked") - public void messageMerge(Object obj) throws MessageTypeException + public void messageConvert(Object obj) throws MessageTypeException { Object[] _source = ((List)obj).toArray(); FieldSchema[] _fields = _SCHEMA.getFields(); @@ -152,6 +185,39 @@ final class Media implements MessagePackable, MessageMergeable if(_source.length <= 10) { return; } this.copyright = (String)_fields[10].getSchema().convert(_source[10]); } + @Override + public void messageUnpack(Unpacker _pac) throws IOException, MessageTypeException { + int _length = _pac.unpackArray(); + if(_length <= 0) { return; } + this.uri = _pac.unpackString(); + if(_length <= 1) { return; } + this.title = _pac.unpackString(); + if(_length <= 2) { return; } + this.width = _pac.unpackInt(); + if(_length <= 3) { return; } + this.height = _pac.unpackInt(); + if(_length <= 4) { return; } + this.format = _pac.unpackString(); + if(_length <= 5) { return; } + this.duration = _pac.unpackLong(); + if(_length <= 6) { return; } + this.size = _pac.unpackLong(); + if(_length <= 7) { return; } + this.bitrate = _pac.unpackInt(); + if(_length <= 8) { return; } + int _person_length = _pac.unpackArray(); + this.person = new ArrayList(_person_length); + for(int _i=0; _i < _person_length; ++_i) { + String _person_i = _pac.unpackString(); + this.person.add(_person_i); + } + if(_length <= 9) { return; } + this.player = _pac.unpackInt(); + if(_length <= 10) { return; } + this.copyright = _pac.unpackString(); + for(int _i=11; _i < _length; ++_i) { _pac.unpackObject(); } + } + @SuppressWarnings("unchecked") public static Media createFromMessage(Object[] _message) { diff --git a/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackDirectSerializer.java b/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackDirectSerializer.java new file mode 100644 index 0000000..721e95b --- /dev/null +++ b/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackDirectSerializer.java @@ -0,0 +1,68 @@ +package serializers.msgpack; + +import java.io.*; +import java.util.*; +import org.msgpack.*; +import serializers.ObjectSerializer; + +public class MessagePackDirectSerializer implements ObjectSerializer +{ + public String getName() { + return "msgpack-direct"; + } + + public MediaContent create() throws Exception { + Media media = new Media(); + media.uri = "http://javaone.com/keynote.mpg"; + media.format = "video/mpg4"; + media.title = "Javaone Keynote"; + media.duration = 1234567L; + media.bitrate = 0; + media.person = new ArrayList(2); + media.person.add("Bill Gates"); + media.person.add("Steve Jobs"); + media.player = 0; + media.height = 0; + media.width = 0; + media.size = 123L; + media.copyright = ""; + + Image image1 = new Image(); + image1.uri = "http://javaone.com/keynote_large.jpg"; + image1.width = 0; + image1.height = 0; + image1.size = 2; + image1.title = "Javaone Keynote"; + + Image image2 = new Image(); + image2.uri = "http://javaone.com/keynote_thumbnail.jpg"; + image2.width = 0; + image2.height = 0; + image2.size = 1; + image2.title = "Javaone Keynote"; + + MediaContent content = new MediaContent(); + content.media = media; + content.image = new ArrayList(2); + content.image.add(image1); + content.image.add(image2); + + return content; + } + + public byte[] serialize(MediaContent content) throws Exception { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + Packer pk = new Packer(os); + pk.pack(content); + return os.toByteArray(); + } + + public MediaContent deserialize(byte[] array) throws Exception { + Unpacker pac = new Unpacker(); + pac.feed(array); + MediaContent obj = new MediaContent(); + obj.messageUnpack(pac); + return obj; + } +} + diff --git a/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackDynamicSerializer.java b/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackDynamicSerializer.java index c8a88ac..9c8ccbe 100644 --- a/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackDynamicSerializer.java +++ b/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackDynamicSerializer.java @@ -60,7 +60,7 @@ public class MessagePackDynamicSerializer implements ObjectSerializer } public Object deserialize(byte[] array) throws Exception { - UnbufferedUnpacker pac = new UnbufferedUnpacker(); + Unpacker pac = new Unpacker(); pac.execute(array); return (Object)pac.getData(); } diff --git a/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackGenericSerializer.java b/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackGenericSerializer.java index 4935899..316389a 100644 --- a/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackGenericSerializer.java +++ b/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackGenericSerializer.java @@ -62,7 +62,7 @@ public class MessagePackGenericSerializer implements ObjectSerializer } public Object deserialize(byte[] array) throws Exception { - UnbufferedUnpacker pac = new UnbufferedUnpacker().useSchema(MEDIA_CONTENT_SCHEMA); + Unpacker pac = new Unpacker().useSchema(MEDIA_CONTENT_SCHEMA); pac.execute(array); return (Object)pac.getData(); } diff --git a/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackIndirectSerializer.java b/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackIndirectSerializer.java index 2767474..e24472b 100644 --- a/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackIndirectSerializer.java +++ b/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackIndirectSerializer.java @@ -58,7 +58,7 @@ public class MessagePackIndirectSerializer implements ObjectSerializer Date: Thu, 20 May 2010 06:18:32 +0900 Subject: java: add Unpacker.wrap method --- java/src/main/java/org/msgpack/Unpacker.java | 36 ++++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'java') diff --git a/java/src/main/java/org/msgpack/Unpacker.java b/java/src/main/java/org/msgpack/Unpacker.java index 4d8da7b..7fd6fcd 100644 --- a/java/src/main/java/org/msgpack/Unpacker.java +++ b/java/src/main/java/org/msgpack/Unpacker.java @@ -40,7 +40,7 @@ public class Unpacker implements Iterable { protected int bufferReserveSize; protected InputStream stream; - class BufferedUnpackerMixin extends BufferedUnpackerImpl { + final class BufferedUnpackerMixin extends BufferedUnpackerImpl { boolean fill() throws IOException { if(stream == null) { return false; @@ -109,6 +109,16 @@ public class Unpacker implements Iterable { bufferConsumed(length); } + public void wrap(byte[] buffer) { + wrap(buffer, 0, buffer.length); + } + + public void wrap(byte[] buffer, int offset, int length) { + impl.buffer = buffer; + impl.offset = offset; + impl.filled = length; + } + public boolean fill() throws IOException { return impl.fill(); } @@ -226,51 +236,51 @@ public class Unpacker implements Iterable { } - final public byte unpackByte() throws IOException, MessageTypeException { + public byte unpackByte() throws IOException, MessageTypeException { return impl.unpackByte(); } - final public short unpackShort() throws IOException, MessageTypeException { + public short unpackShort() throws IOException, MessageTypeException { return impl.unpackShort(); } - final public int unpackInt() throws IOException, MessageTypeException { + public int unpackInt() throws IOException, MessageTypeException { return impl.unpackInt(); } - final public long unpackLong() throws IOException, MessageTypeException { + public long unpackLong() throws IOException, MessageTypeException { return impl.unpackLong(); } - final public float unpackFloat() throws IOException, MessageTypeException { + public float unpackFloat() throws IOException, MessageTypeException { return impl.unpackFloat(); } - final public double unpackDouble() throws IOException, MessageTypeException { + public double unpackDouble() throws IOException, MessageTypeException { return impl.unpackDouble(); } - final public Object unpackNull() throws IOException, MessageTypeException { + public Object unpackNull() throws IOException, MessageTypeException { return impl.unpackNull(); } - final public boolean unpackBoolean() throws IOException, MessageTypeException { + public boolean unpackBoolean() throws IOException, MessageTypeException { return impl.unpackBoolean(); } - final public int unpackArray() throws IOException, MessageTypeException { + public int unpackArray() throws IOException, MessageTypeException { return impl.unpackArray(); } - final public int unpackMap() throws IOException, MessageTypeException { + public int unpackMap() throws IOException, MessageTypeException { return impl.unpackMap(); } - final public int unpackRaw() throws IOException, MessageTypeException { + public int unpackRaw() throws IOException, MessageTypeException { return impl.unpackRaw(); } - final public byte[] unpackRawBody(int length) throws IOException, MessageTypeException { + public byte[] unpackRawBody(int length) throws IOException, MessageTypeException { return impl.unpackRawBody(length); } -- cgit v1.2.1 From c2525bcc05477600f8c093483df179d89e8f0707 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Thu, 20 May 2010 06:19:26 +0900 Subject: java: add Unpacker.wrap method --- .../tpc/src/serializers/msgpack/MessagePackDirectSerializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java') diff --git a/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackDirectSerializer.java b/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackDirectSerializer.java index 721e95b..25f932b 100644 --- a/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackDirectSerializer.java +++ b/java/test/thrift-protobuf-compare/tpc/src/serializers/msgpack/MessagePackDirectSerializer.java @@ -59,7 +59,7 @@ public class MessagePackDirectSerializer implements ObjectSerializer Date: Thu, 20 May 2010 17:32:15 +0900 Subject: java: javadoc --- .../java/org/msgpack/BufferedUnpackerImpl.java | 6 +- java/src/main/java/org/msgpack/Unpacker.java | 287 +++++++++++++++++++-- 2 files changed, 273 insertions(+), 20 deletions(-) (limited to 'java') diff --git a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java index 5fde4e1..0aba62b 100644 --- a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java +++ b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java @@ -367,7 +367,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { } } - final byte[] unpackRawBody(int length) throws IOException, MessageTypeException { + final byte[] unpackRawBody(int length) throws IOException { more(length); byte[] bytes = new byte[length]; System.arraycopy(buffer, offset, bytes, 0, length); @@ -388,12 +388,12 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { return s; } - final Object unpackObject() throws IOException, MessageTypeException { + final Object unpackObject() throws IOException { // FIXME save state, restore state UnpackResult result = new UnpackResult(); if(!next(result)) { super.reset(); - throw new MessageTypeException(); + throw new UnpackException("insufficient buffer"); } return result.getData(); } diff --git a/java/src/main/java/org/msgpack/Unpacker.java b/java/src/main/java/org/msgpack/Unpacker.java index 7fd6fcd..7563b39 100644 --- a/java/src/main/java/org/msgpack/Unpacker.java +++ b/java/src/main/java/org/msgpack/Unpacker.java @@ -23,6 +23,82 @@ import java.io.IOException; import java.util.Iterator; import java.nio.ByteBuffer; +/** + * Deserializer class that includes Buffered API, Unbuffered API, + * Schema API and Direct Conversion API. + * + * Buffered API uses the internal buffer of the Unpacker. + * Following code uses Buffered API with an input stream: + *
+ * // create an unpacker with input stream
+ * Unpacker pac = new Unpacker(System.in);
+ *
+ * // take a object out using next() method, or ...
+ * UnpackResult result = pac.next();
+ *
+ * // use an iterator.
+ * for(Object obj : pac) {
+ *   // use MessageConvertable interface to convert the
+ *   // the generic object to the specific type.
+ * }
+ * 
+ * + * Following code doesn't use the input stream and feeds buffer + * using {@link feed(byte[])} method. This is useful to use + * special stream like zlib or event-driven I/O library. + *
+ * // create an unpacker without input stream
+ * Unpacker pac = new Unpacker();
+ *
+ * // feed buffer to the internal buffer.
+ * pac.feed(input_bytes);
+ *
+ * // use next() method or iterators.
+ * for(Object obj : pac) {
+ *   // ...
+ * }
+ * 
+ * + * The combination of {@link reserveBuffer()}, {@link getBuffer()}, + * {@link getBufferOffset()}, {@link getBufferCapacity()} and + * {@link bufferConsumed()} is useful to omit copying. + *
+ * // create an unpacker without input stream
+ * Unpacker pac = new Unpacker();
+ *
+ * // reserve internal buffer at least 1024 bytes.
+ * pac.reserveBuffer(1024);
+ *
+ * // feed buffer to the internal buffer upto pac.getBufferCapacity() bytes.
+ * System.in.read(pac.getBuffer(), pac.getBufferOffset(), pac.getBufferCapacity());
+ *
+ * // use next() method or iterators.
+ * for(Object obj : pac) {
+ *     // ...
+ * }
+ * 
+ * + * Unbuffered API doesn't initialize the internal buffer. + * You can manage the buffer manually. + *
+ * // create an unpacker with input stream
+ * Unpacker pac = new Unpacker(System.in);
+ *
+ * // manage the buffer manually.
+ * byte[] buffer = new byte[1024];
+ * int filled = System.in.read(buffer);
+ * int offset = 0;
+ *
+ * // deserialize objects using execute() method.
+ * int nextOffset = pac.execute(buffer, offset, filled);
+ *
+ * // take out object if deserialized object is ready.
+ * if(pac.isFinished()) {
+ *     Object obj = pac.getData();
+ *     // ...
+ * }
+ * 
+ */ public class Unpacker implements Iterable { // buffer: @@ -59,85 +135,150 @@ public class Unpacker implements Iterable { final BufferedUnpackerMixin impl = new BufferedUnpackerMixin(); + /** + * Calls {@link Unpacker(DEFAULT_BUFFER_SIZE)} + */ public Unpacker() { this(DEFAULT_BUFFER_SIZE); } + /** + * Calls {@link Unpacker(null, bufferReserveSize)} + */ public Unpacker(int bufferReserveSize) { this(null, bufferReserveSize); } + /** + * Calls {@link Unpacker(stream, DEFAULT_BUFFER_SIZE)} + */ public Unpacker(InputStream stream) { this(stream, DEFAULT_BUFFER_SIZE); } + /** + * Constructs the unpacker. + * The stream is used to fill the buffer when more buffer is required by {@link next()} or {@link UnpackIterator#hasNext()} method. + * @param stream input stream to fill the buffer + * @param bufferReserveSize threshold size to expand the size of buffer + */ public Unpacker(InputStream stream, int bufferReserveSize) { this.parsed = 0; this.bufferReserveSize = bufferReserveSize/2; this.stream = stream; } + /** + * Sets schema to convert deserialized object into specific type. + * Default schema is {@link GenericSchema} that leaves objects for generic type. Use {@link MessageConvertable#messageConvert(Object)} method to convert the generic object. + * @param s schem to use + */ public Unpacker useSchema(Schema s) { impl.setSchema(s); return this; } + /** + * Gets the input stream. + * @return the input stream. it may be null. + */ public InputStream getStream() { return this.stream; } + /** + * Sets the input stream. + * @param stream the input stream to set. + */ public void setStream(InputStream stream) { this.stream = stream; } - public void feed(ByteBuffer buffer) { - int length = buffer.remaining(); - if (length == 0) return; - reserveBuffer(length); - buffer.get(impl.buffer, impl.offset, length); - bufferConsumed(length); - } + /** + * Fills the buffer with the specified buffer. + */ public void feed(byte[] buffer) { feed(buffer, 0, buffer.length); } + /** + * Fills the buffer with the specified buffer. + */ public void feed(byte[] buffer, int offset, int length) { reserveBuffer(length); System.arraycopy(buffer, offset, impl.buffer, impl.offset, length); bufferConsumed(length); } + /** + * Fills the buffer with the specified buffer. + */ + public void feed(ByteBuffer buffer) { + int length = buffer.remaining(); + if (length == 0) return; + reserveBuffer(length); + buffer.get(impl.buffer, impl.offset, length); + bufferConsumed(length); + } + + /** + * Swaps the internal buffer with the specified buffer. + * This method doesn't copy the buffer and the its contents will be rewritten by {@link fill()} or {@link feed(byte[])} method. + */ public void wrap(byte[] buffer) { wrap(buffer, 0, buffer.length); } + /** + * Swaps the internal buffer with the specified buffer. + * This method doesn't copy the buffer and the its contents will be rewritten by {@link fill()} or {@link feed(byte[])} method. + */ public void wrap(byte[] buffer, int offset, int length) { impl.buffer = buffer; impl.offset = offset; impl.filled = length; } + /** + * Fills the internal using the input stream. + * @return false if the stream is null or stream.read returns <= 0. + */ public boolean fill() throws IOException { return impl.fill(); } + + /** + * Returns the iterator that calls {@link next()} method repeatedly. + */ public Iterator iterator() { return new UnpackIterator(this); } + /** + * Deserializes one object and returns it. + * @return {@link UnpackResult#isFinished()} returns false if the buffer is insufficient to deserialize one object. + */ public UnpackResult next() throws IOException, UnpackException { UnpackResult result = new UnpackResult(); impl.next(result); return result; } + /** + * Deserializes one object and returns it. + * @return false if the buffer is insufficient to deserialize one object. + */ public boolean next(UnpackResult result) throws IOException, UnpackException { return impl.next(result); } + /** + * Reserve free space of the internal buffer at least specified size and expands {@link getBufferCapacity()}. + */ public void reserveBuffer(int require) { if(impl.buffer == null) { int nextSize = (bufferReserveSize < require) ? require : bufferReserveSize; @@ -163,22 +304,40 @@ public class Unpacker implements Iterable { impl.offset = 0; } + /** + * Returns the internal buffer. + */ public byte[] getBuffer() { return impl.buffer; } - public int getBufferOffset() { - return impl.filled; - } - + /** + * Returns the size of free space of the internal buffer. + */ public int getBufferCapacity() { return impl.buffer.length - impl.filled; } + /** + * Returns the offset of free space in the internal buffer. + */ + public int getBufferOffset() { + return impl.filled; + } + + /** + * Moves front the offset of the free space in the internal buffer. + * Call this method after fill the buffer manually using {@link reserveBuffer()}, {@link getBuffer()}, {@link getBufferOffset()} and {@link getBufferCapacity()} methods. + */ public void bufferConsumed(int size) { impl.filled += size; } + /** + * Deserializes one object upto the offset of the internal buffer. + * Call {@link reset()} method before calling this method again. + * @return true if one object is deserialized. Use {@link getData()} to get the deserialized object. + */ public boolean execute() throws UnpackException { int noffset = impl.execute(impl.buffer, impl.offset, impl.filled); if(noffset <= impl.offset) { @@ -190,10 +349,24 @@ public class Unpacker implements Iterable { } + /** + * Deserializes one object over the specified buffer. + * This method doesn't use the internal buffer. + * Use {@link isFinished()} method to known a object is ready to get. + * Call {@link reset()} method before calling this method again. + * @return offset position that is parsed. + */ public int execute(byte[] buffer) throws UnpackException { return execute(buffer, 0, buffer.length); } + /** + * Deserializes one object over the specified buffer. + * This method doesn't use the internal buffer. + * Use {@link isFinished()} method to known a object is ready to get. + * Call {@link reset()} method before calling this method again. + * @return offset position that is parsed. + */ public int execute(byte[] buffer, int offset, int length) throws UnpackException { int noffset = impl.execute(buffer, offset + impl.offset, length); impl.offset = noffset - offset; @@ -203,14 +376,23 @@ public class Unpacker implements Iterable { return noffset; } - public boolean isFinished() { - return impl.isFinished(); - } - + /** + * Gets the object deserialized by {@link execute(byte[])} method. + */ public Object getData() { return impl.getData(); } + /** + * Returns true if an object is ready to get with {@link getData()} method. + */ + public boolean isFinished() { + return impl.isFinished(); + } + + /** + * Resets the internal state of the unpacker. + */ public void reset() { impl.reset(); } @@ -236,59 +418,130 @@ public class Unpacker implements Iterable { } + /** + * Gets one {@code byte} value from the buffer. + * This method calls {@link fill()} method if needed. + * @throws MessageTypeException the first value of the buffer is not a {@code byte}. + */ public byte unpackByte() throws IOException, MessageTypeException { return impl.unpackByte(); } + /** + * Gets one {@code short} value from the buffer. + * This method calls {@link fill()} method if needed. + * @throws MessageTypeException the first value of the buffer is not a {@code short}. + */ public short unpackShort() throws IOException, MessageTypeException { return impl.unpackShort(); } + /** + * Gets one {@code int} value from the buffer. + * This method calls {@link fill()} method if needed. + * @throws MessageTypeException the first value of the buffer is not a {@code int}. + */ public int unpackInt() throws IOException, MessageTypeException { return impl.unpackInt(); } + /** + * Gets one {@code long} value from the buffer. + * This method calls {@link fill()} method if needed. + * @throws MessageTypeException the first value of the buffer is not a {@code long}. + */ public long unpackLong() throws IOException, MessageTypeException { return impl.unpackLong(); } + /** + * Gets one {@code float} value from the buffer. + * This method calls {@link fill()} method if needed. + * @throws MessageTypeException the first value of the buffer is not a {@code float}. + */ public float unpackFloat() throws IOException, MessageTypeException { return impl.unpackFloat(); } + /** + * Gets one {@code double} value from the buffer. + * This method calls {@link fill()} method if needed. + * @throws MessageTypeException the first value of the buffer is not a {@code double}. + */ public double unpackDouble() throws IOException, MessageTypeException { return impl.unpackDouble(); } + /** + * Gets one {@code null} value from the buffer. + * This method calls {@link fill()} method if needed. + * @throws MessageTypeException the first value of the buffer is not a {@code null}. + */ public Object unpackNull() throws IOException, MessageTypeException { return impl.unpackNull(); } + /** + * Gets one {@code boolean} value from the buffer. + * This method calls {@link fill()} method if needed. + * @throws MessageTypeException the first value of the buffer is not a {@code boolean}. + */ public boolean unpackBoolean() throws IOException, MessageTypeException { return impl.unpackBoolean(); } + /** + * Gets one array header from the buffer. + * This method calls {@link fill()} method if needed. + * @return the length of the map. There are {@code retval} objects to get. + * @throws MessageTypeException the first value of the buffer is not a array. + */ public int unpackArray() throws IOException, MessageTypeException { return impl.unpackArray(); } + /** + * Gets one map header from the buffer. + * This method calls {@link fill()} method if needed. + * @return the length of the map. There are {@code retval * 2} objects to get. + * @throws MessageTypeException the first value of the buffer is not a map. + */ public int unpackMap() throws IOException, MessageTypeException { return impl.unpackMap(); } + /** + * Gets one raw header from the buffer. + * This method calls {@link fill()} method if needed. + * @return the length of the raw bytes. There are {@code retval} bytes to get. + * @throws MessageTypeException the first value of the buffer is not a raw bytes. + */ public int unpackRaw() throws IOException, MessageTypeException { return impl.unpackRaw(); } - public byte[] unpackRawBody(int length) throws IOException, MessageTypeException { + /** + * Gets one raw header from the buffer. + * This method calls {@link fill()} method if needed. + */ + public byte[] unpackRawBody(int length) throws IOException { return impl.unpackRawBody(length); } + /** + * Gets one {@code String} value from the buffer. + * This method calls {@link fill()} method if needed. + * @throws MessageTypeException the first value of the buffer is not a {@code String}. + */ final public String unpackString() throws IOException, MessageTypeException { return impl.unpackString(); } - final public Object unpackObject() throws IOException, MessageTypeException { + /** + * Gets one {@code Object} value from the buffer. + * This method calls {@link fill()} method if needed. + */ + final public Object unpackObject() throws IOException { return impl.unpackObject(); } } -- cgit v1.2.1 From 1fe35d7efe4d5a4993d2392cc259dec17fc744e4 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Sat, 22 May 2010 03:34:17 +0900 Subject: java: fix Packer.packByte --- java/src/main/java/org/msgpack/Packer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java') diff --git a/java/src/main/java/org/msgpack/Packer.java b/java/src/main/java/org/msgpack/Packer.java index 6d79414..3fa421f 100644 --- a/java/src/main/java/org/msgpack/Packer.java +++ b/java/src/main/java/org/msgpack/Packer.java @@ -34,7 +34,7 @@ public class Packer { public Packer packByte(byte d) throws IOException { if(d < -(1<<5)) { - castBytes[0] = (byte)0xd1; + castBytes[0] = (byte)0xd0; castBytes[1] = d; out.write(castBytes, 0, 2); } else { -- cgit v1.2.1 From b9cb270b8f771e5504e36469112daa6a32b24d63 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Sat, 22 May 2010 03:34:43 +0900 Subject: java: add Unpacker.unpack(MessageUnpackable) and Unpacker.tryUnpackNil() --- .../java/org/msgpack/BufferedUnpackerImpl.java | 22 +++++++++++++++++++++- java/src/main/java/org/msgpack/Unpacker.java | 8 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'java') diff --git a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java index 0aba62b..4b2f302 100644 --- a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java +++ b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java @@ -63,6 +63,15 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { } } + private final boolean tryMore(int require) throws IOException, UnpackException { + while(filled - offset < require) { + if(!fill()) { + return false; + } + } + return true; + } + private final void advance(int length) { offset += length; } @@ -275,6 +284,18 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { return null; } + final boolean tryUnpackNull() throws IOException { + if(!tryMore(1)) { + return false; + } + int b = buffer[offset] & 0xff; + if(b != 0xc0) { // nil + return false; + } + advance(1); + return 1; + } + final boolean unpackBoolean() throws IOException, MessageTypeException { more(1); int b = buffer[offset] & 0xff; @@ -389,7 +410,6 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { } final Object unpackObject() throws IOException { - // FIXME save state, restore state UnpackResult result = new UnpackResult(); if(!next(result)) { super.reset(); diff --git a/java/src/main/java/org/msgpack/Unpacker.java b/java/src/main/java/org/msgpack/Unpacker.java index 7563b39..1917b9f 100644 --- a/java/src/main/java/org/msgpack/Unpacker.java +++ b/java/src/main/java/org/msgpack/Unpacker.java @@ -544,5 +544,13 @@ public class Unpacker implements Iterable { final public Object unpackObject() throws IOException { return impl.unpackObject(); } + + final void unpack(MessageUnpackable obj) throws IOException, MessageTypeException { + obj.unpackMessage(this); + } + + final boolean tryUnpackNull() throws IOException { + return impl.tryUnpackNull(); + } } -- cgit v1.2.1 From b4fc79c38ee44a1da5c2973fa213753a2d309666 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Sat, 22 May 2010 17:05:17 +0900 Subject: java: fixes compile error --- java/src/main/java/org/msgpack/BufferedUnpackerImpl.java | 7 ++++++- java/src/main/java/org/msgpack/Unpacker.java | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'java') diff --git a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java index 4b2f302..cc6604d 100644 --- a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java +++ b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java @@ -293,7 +293,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { return false; } advance(1); - return 1; + return true; } final boolean unpackBoolean() throws IOException, MessageTypeException { @@ -396,6 +396,11 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl { return bytes; } + final byte[] unpackByteArray() throws IOException, MessageTypeException { + int length = unpackRaw(); + return unpackRawBody(length); + } + final String unpackString() throws IOException, MessageTypeException { int length = unpackRaw(); more(length); diff --git a/java/src/main/java/org/msgpack/Unpacker.java b/java/src/main/java/org/msgpack/Unpacker.java index 1917b9f..e84aff9 100644 --- a/java/src/main/java/org/msgpack/Unpacker.java +++ b/java/src/main/java/org/msgpack/Unpacker.java @@ -521,13 +521,21 @@ public class Unpacker implements Iterable { } /** - * Gets one raw header from the buffer. + * Gets one raw body from the buffer. * This method calls {@link fill()} method if needed. */ public byte[] unpackRawBody(int length) throws IOException { return impl.unpackRawBody(length); } + /** + * Gets one raw bytes from the buffer. + * This method calls {@link fill()} method if needed. + */ + public byte[] unpackByteArray() throws IOException { + return impl.unpackByteArray(); + } + /** * Gets one {@code String} value from the buffer. * This method calls {@link fill()} method if needed. @@ -546,7 +554,7 @@ public class Unpacker implements Iterable { } final void unpack(MessageUnpackable obj) throws IOException, MessageTypeException { - obj.unpackMessage(this); + obj.messageUnpack(this); } final boolean tryUnpackNull() throws IOException { -- cgit v1.2.1 From c43e5e0c95105c0dbf17e41d15068bfdb08450ce Mon Sep 17 00:00:00 2001 From: Kazuki Ohta Date: Sun, 23 May 2010 01:31:15 +0900 Subject: java: added testcases for empty array and empty map --- java/src/test/java/org/msgpack/TestPackUnpack.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'java') diff --git a/java/src/test/java/org/msgpack/TestPackUnpack.java b/java/src/test/java/org/msgpack/TestPackUnpack.java index a16b5b1..b02bbb4 100644 --- a/java/src/test/java/org/msgpack/TestPackUnpack.java +++ b/java/src/test/java/org/msgpack/TestPackUnpack.java @@ -177,6 +177,9 @@ public class TestPackUnpack { @Test public void testArray() throws Exception { + List emptyList = new ArrayList(); + testArray(emptyList, Schema.parse("(array int)")); + for (int i = 0; i < 1000; i++) { Schema schema = Schema.parse("(array int)"); List l = new ArrayList(); @@ -209,6 +212,9 @@ public class TestPackUnpack { @Test public void testMap() throws Exception { + Map emptyMap = new HashMap(); + testMap(emptyMap, Schema.parse("(map int int)")); + for (int i = 0; i < 1000; i++) { Schema schema = Schema.parse("(map int int)"); Map m = new HashMap(); -- cgit v1.2.1 From 5982970e21d9bab7ea2bd507b360317f40628260 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Sun, 23 May 2010 01:34:45 +0900 Subject: java: fixed problem that empty array and empty map don't check Schema --- java/src/main/java/org/msgpack/UnpackerImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'java') diff --git a/java/src/main/java/org/msgpack/UnpackerImpl.java b/java/src/main/java/org/msgpack/UnpackerImpl.java index ae01289..9b885a0 100644 --- a/java/src/main/java/org/msgpack/UnpackerImpl.java +++ b/java/src/main/java/org/msgpack/UnpackerImpl.java @@ -157,7 +157,10 @@ public class UnpackerImpl { count = b & 0x0f; //System.out.println("fixarray count:"+count); obj = new Object[count]; - if(count == 0) { break _push; } // FIXME check IArraySchema + if(count == 0) { + obj = ((IArraySchema)top_schema).createFromArray((Object[])obj); + break _push; + } ++top; stack_obj[top] = top_obj; stack_ct[top] = top_ct; @@ -179,7 +182,10 @@ public class UnpackerImpl { } count = b & 0x0f; obj = new Object[count*2]; - if(count == 0) { break _push; } // FIXME check IMapSchema + if(count == 0) { + obj = ((IMapSchema)top_schema).createFromMap((Object[])obj); + break _push; + } //System.out.println("fixmap count:"+count); ++top; stack_obj[top] = top_obj; -- cgit v1.2.1 From fa6ea6848f3c639d64e223afe31d0fa2ba13d333 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Sun, 23 May 2010 01:38:01 +0900 Subject: java: fixed problem that empty array and empty map don't check Schema --- java/src/main/java/org/msgpack/UnpackerImpl.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'java') diff --git a/java/src/main/java/org/msgpack/UnpackerImpl.java b/java/src/main/java/org/msgpack/UnpackerImpl.java index 9b885a0..10cf5f0 100644 --- a/java/src/main/java/org/msgpack/UnpackerImpl.java +++ b/java/src/main/java/org/msgpack/UnpackerImpl.java @@ -348,7 +348,10 @@ public class UnpackerImpl { castBuffer.put(src, n, 2); count = ((int)castBuffer.getShort(0)) & 0xffff; obj = new Object[count]; - if(count == 0) { break _push; } // FIXME check IArraySchema + if(count == 0) { + obj = ((IArraySchema)top_schema).createFromArray((Object[])obj); + break _push; + } ++top; stack_obj[top] = top_obj; stack_ct[top] = top_ct; @@ -371,7 +374,10 @@ public class UnpackerImpl { // FIXME overflow check count = castBuffer.getInt(0) & 0x7fffffff; obj = new Object[count]; - if(count == 0) { break _push; } // FIXME check IArraySchema + if(count == 0) { + obj = ((IArraySchema)top_schema).createFromArray((Object[])obj); + break _push; + } ++top; stack_obj[top] = top_obj; stack_ct[top] = top_ct; @@ -393,7 +399,10 @@ public class UnpackerImpl { castBuffer.put(src, n, 2); count = ((int)castBuffer.getShort(0)) & 0xffff; obj = new Object[count*2]; - if(count == 0) { break _push; } // FIXME check IMapSchema + if(count == 0) { + obj = ((IMapSchema)top_schema).createFromMap((Object[])obj); + break _push; + } //System.out.println("fixmap count:"+count); ++top; stack_obj[top] = top_obj; @@ -417,7 +426,10 @@ public class UnpackerImpl { // FIXME overflow check count = castBuffer.getInt(0) & 0x7fffffff; obj = new Object[count*2]; - if(count == 0) { break _push; } // FIXME check IMapSchema + if(count == 0) { + obj = ((IMapSchema)top_schema).createFromMap((Object[])obj); + break _push; + } //System.out.println("fixmap count:"+count); ++top; stack_obj[top] = top_obj; -- cgit v1.2.1 From f8173e93f5df4c6c0289d58b92a4acde816f1cf3 Mon Sep 17 00:00:00 2001 From: Kazuki Ohta Date: Sun, 23 May 2010 01:48:20 +0900 Subject: java: version 0.3 (added CHANGES.txt and LICENSE.txt) --- java/CHANGES.txt | 9 +++ java/LICENSE.txt | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ java/pom.xml | 2 +- 3 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 java/CHANGES.txt create mode 100644 java/LICENSE.txt (limited to 'java') diff --git a/java/CHANGES.txt b/java/CHANGES.txt new file mode 100644 index 0000000..77e9318 --- /dev/null +++ b/java/CHANGES.txt @@ -0,0 +1,9 @@ +Release 0.3 - 2010/05/23 + NEW FEATURES + Added Unbuffered API + Direct Conversion API to the Unpacker. + + BUG FIXES + Zero-length Array and Map is deserialized as List and Map, instead of the + array of the Object. + + fixed the bug around Packer.packByte(). diff --git a/java/LICENSE.txt b/java/LICENSE.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/java/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/java/pom.xml b/java/pom.xml index d1f6c34..9b74b4c 100755 --- a/java/pom.xml +++ b/java/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.msgpack msgpack - 0.2 + 0.3 MessagePack for Java MessagePack for Java -- cgit v1.2.1 From 6df86384ca2e20c34b78aeb5d9f72a885bd50a16 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Sat, 29 May 2010 07:54:49 +0900 Subject: java: update javadoc --- java/src/main/java/org/msgpack/Packer.java | 16 ++++++++++++++++ java/src/main/java/org/msgpack/Unpacker.java | 8 +++++--- java/src/main/java/org/msgpack/package-info.java | 8 ++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 java/src/main/java/org/msgpack/package-info.java (limited to 'java') diff --git a/java/src/main/java/org/msgpack/Packer.java b/java/src/main/java/org/msgpack/Packer.java index 3fa421f..a92d2b6 100644 --- a/java/src/main/java/org/msgpack/Packer.java +++ b/java/src/main/java/org/msgpack/Packer.java @@ -23,6 +23,22 @@ import java.nio.ByteBuffer; import java.util.List; import java.util.Map; +/** + * Packer enables you to serialize objects into OutputStream. + * + *
+ * // create a packer with output stream
+ * Packer pk = new Packer(System.out);
+ *
+ * // store an object with pack() method.
+ * pk.pack(1);
+ *
+ * // you can store String, List, Map, byte[] and primitive types.
+ * pk.pack(new ArrayList());
+ * 
+ * + * You can serialize objects that implements {@link MessagePackable} interface. + */ public class Packer { protected byte[] castBytes = new byte[9]; protected ByteBuffer castBuffer = ByteBuffer.wrap(castBytes); diff --git a/java/src/main/java/org/msgpack/Unpacker.java b/java/src/main/java/org/msgpack/Unpacker.java index e84aff9..39bd8fa 100644 --- a/java/src/main/java/org/msgpack/Unpacker.java +++ b/java/src/main/java/org/msgpack/Unpacker.java @@ -24,11 +24,13 @@ import java.util.Iterator; import java.nio.ByteBuffer; /** - * Deserializer class that includes Buffered API, Unbuffered API, - * Schema API and Direct Conversion API. + * Unpacker enables you to deserialize objects from stream. + * + * Unpacker provides Buffered API, Unbuffered API, Schema API + * and Direct Conversion API. * * Buffered API uses the internal buffer of the Unpacker. - * Following code uses Buffered API with an input stream: + * Following code uses Buffered API with an InputStream: *
  * // create an unpacker with input stream
  * Unpacker pac = new Unpacker(System.in);
diff --git a/java/src/main/java/org/msgpack/package-info.java b/java/src/main/java/org/msgpack/package-info.java
new file mode 100644
index 0000000..7e9b8a2
--- /dev/null
+++ b/java/src/main/java/org/msgpack/package-info.java
@@ -0,0 +1,8 @@
+/**
+ * MessagePack is a binary-based efficient object serialization library.
+ * It enables to exchange structured objects between many languages like JSON.
+ * But unlike JSON, it is very fast and small.
+ *
+ * Use {@link Packer} to serialize and {@link Unpacker} to deserialize.
+ */
+package org.msgpack;
-- 
cgit v1.2.1


From 81b0c316cda14629821005cba5ce34c80ccd61d2 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Sun, 30 May 2010 01:39:48 +0900
Subject: java: Unpacker: rewind internal buffer on filled <= offset

---
 java/src/main/java/org/msgpack/Unpacker.java | 6 ++++++
 1 file changed, 6 insertions(+)

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/Unpacker.java b/java/src/main/java/org/msgpack/Unpacker.java
index 39bd8fa..f22c58b 100644
--- a/java/src/main/java/org/msgpack/Unpacker.java
+++ b/java/src/main/java/org/msgpack/Unpacker.java
@@ -288,6 +288,12 @@ public class Unpacker implements Iterable {
 			return;
 		}
 
+		if(impl.filled <= impl.offset) {
+			// rewind the buffer
+			impl.filled = 0;
+			impl.offset = 0;
+		}
+
 		if(impl.buffer.length - impl.filled >= require) {
 			return;
 		}
-- 
cgit v1.2.1


From 82a5dd6cf9a49f6ffa444d5fc0ba5d4e3f10eb3e Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Thu, 10 Jun 2010 14:02:58 -0700
Subject: java: update

---
 java/src/main/java/org/msgpack/Packer.java         |   4 +
 java/src/main/java/org/msgpack/Schema.java         |  79 ++-----------
 java/src/main/java/org/msgpack/Unpacker.java       |   4 +-
 .../main/java/org/msgpack/schema/ArraySchema.java  | 125 ---------------------
 .../java/org/msgpack/schema/BooleanSchema.java     |  64 +++++++++++
 .../java/org/msgpack/schema/ByteArraySchema.java   |  97 ++++++++++++++++
 .../main/java/org/msgpack/schema/ByteSchema.java   |  55 +++++----
 .../java/org/msgpack/schema/ClassGenerator.java    |  23 ++--
 .../main/java/org/msgpack/schema/ClassSchema.java  |  58 +++++-----
 .../main/java/org/msgpack/schema/DoubleSchema.java |  42 +++----
 .../main/java/org/msgpack/schema/FloatSchema.java  |  44 +++-----
 .../org/msgpack/schema/GenericClassSchema.java     |   4 -
 .../java/org/msgpack/schema/GenericSchema.java     |  73 +-----------
 .../main/java/org/msgpack/schema/IntSchema.java    |  55 +++++----
 .../main/java/org/msgpack/schema/ListSchema.java   | 111 ++++++++++++++++++
 .../main/java/org/msgpack/schema/LongSchema.java   |  39 +++----
 .../main/java/org/msgpack/schema/MapSchema.java    |  43 +++----
 .../main/java/org/msgpack/schema/RawSchema.java    | 105 -----------------
 .../java/org/msgpack/schema/SSchemaParser.java     |  22 +++-
 .../main/java/org/msgpack/schema/SetSchema.java    | 115 +++++++++++++++++++
 .../main/java/org/msgpack/schema/ShortSchema.java  |  52 +++++----
 .../main/java/org/msgpack/schema/StringSchema.java |  65 +++++------
 22 files changed, 655 insertions(+), 624 deletions(-)
 delete mode 100644 java/src/main/java/org/msgpack/schema/ArraySchema.java
 create mode 100644 java/src/main/java/org/msgpack/schema/BooleanSchema.java
 create mode 100644 java/src/main/java/org/msgpack/schema/ByteArraySchema.java
 create mode 100644 java/src/main/java/org/msgpack/schema/ListSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/RawSchema.java
 create mode 100644 java/src/main/java/org/msgpack/schema/SetSchema.java

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/Packer.java b/java/src/main/java/org/msgpack/Packer.java
index a92d2b6..dd510f3 100644
--- a/java/src/main/java/org/msgpack/Packer.java
+++ b/java/src/main/java/org/msgpack/Packer.java
@@ -223,6 +223,10 @@ public class Packer {
 		return this;
 	}
 
+	public Packer packBoolean(boolean d) throws IOException {
+		return d ? packTrue() : packFalse();
+	}
+
 	public Packer packArray(int n) throws IOException {
 		if(n < 16) {
 			final int d = 0x90 | n;
diff --git a/java/src/main/java/org/msgpack/Schema.java b/java/src/main/java/org/msgpack/Schema.java
index f191f7a..25e10f9 100644
--- a/java/src/main/java/org/msgpack/Schema.java
+++ b/java/src/main/java/org/msgpack/Schema.java
@@ -20,28 +20,13 @@ package org.msgpack;
 import java.io.Writer;
 import java.io.IOException;
 import org.msgpack.schema.SSchemaParser;
-import org.msgpack.schema.ClassGenerator;
+//import org.msgpack.schema.ClassGenerator;
 
 public abstract class Schema {
-	private String expression;
-	private String name;
+	public Schema() { }
 
-	public Schema(String name) {
-		this.expression = expression;
-		this.name = name;
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public String getFullName() {
-		return name;
-	}
-
-	public String getExpression() {
-		return name;
-	}
+	public abstract String getClassName();
+	public abstract String getExpression();
 
 	public static Schema parse(String source) {
 		return SSchemaParser.parse(source);
@@ -51,83 +36,43 @@ public abstract class Schema {
 		return SSchemaParser.load(source);
 	}
 
-	public void write(Writer output) throws IOException {
-		ClassGenerator.write(this, output);
-	}
-
 	public abstract void pack(Packer pk, Object obj) throws IOException;
-
 	public abstract Object convert(Object obj) throws MessageTypeException;
 
-
 	public Object createFromNil() {
 		return null;
 	}
 
 	public Object createFromBoolean(boolean v) {
-		throw new RuntimeException("type error");
-	}
-
-	public Object createFromByte(byte v) {
-		throw new RuntimeException("type error");
-	}
-
-	public Object createFromShort(short v) {
-		throw new RuntimeException("type error");
-	}
-
-	public Object createFromInt(int v) {
-		throw new RuntimeException("type error");
-	}
-
-	public Object createFromLong(long v) {
-		throw new RuntimeException("type error");
-	}
-
-	public Object createFromFloat(float v) {
-		throw new RuntimeException("type error");
-	}
-
-	public Object createFromDouble(double v) {
-		throw new RuntimeException("type error");
-	}
-
-	public Object createFromRaw(byte[] b, int offset, int length) {
-		throw new RuntimeException("type error");
-	}
-
-	/* FIXME
-	public Object createFromBoolean(boolean v) {
-		throw MessageTypeException.schemaMismatch(this);
+		throw new MessageTypeException("type error");
 	}
 
 	public Object createFromByte(byte v) {
-		throw MessageTypeException.schemaMismatch(this);
+		throw new MessageTypeException("type error");
 	}
 
 	public Object createFromShort(short v) {
-		throw MessageTypeException.schemaMismatch(this);
+		throw new MessageTypeException("type error");
 	}
 
 	public Object createFromInt(int v) {
-		throw MessageTypeException.schemaMismatch(this);
+		throw new MessageTypeException("type error");
 	}
 
 	public Object createFromLong(long v) {
-		throw MessageTypeException.schemaMismatch(this);
+		throw new MessageTypeException("type error");
 	}
 
 	public Object createFromFloat(float v) {
-		throw MessageTypeException.schemaMismatch(this);
+		throw new MessageTypeException("type error");
 	}
 
 	public Object createFromDouble(double v) {
-		throw MessageTypeException.schemaMismatch(this);
+		throw new MessageTypeException("type error");
 	}
 
 	public Object createFromRaw(byte[] b, int offset, int length) {
-		throw MessageTypeException.schemaMismatch(this);
+		throw new MessageTypeException("type error");
 	}
-	*/
 }
 
diff --git a/java/src/main/java/org/msgpack/Unpacker.java b/java/src/main/java/org/msgpack/Unpacker.java
index f22c58b..32bab64 100644
--- a/java/src/main/java/org/msgpack/Unpacker.java
+++ b/java/src/main/java/org/msgpack/Unpacker.java
@@ -561,11 +561,11 @@ public class Unpacker implements Iterable {
 		return impl.unpackObject();
 	}
 
-	final void unpack(MessageUnpackable obj) throws IOException, MessageTypeException {
+	final public void unpack(MessageUnpackable obj) throws IOException, MessageTypeException {
 		obj.messageUnpack(this);
 	}
 
-	final boolean tryUnpackNull() throws IOException {
+	final public boolean tryUnpackNull() throws IOException {
 		return impl.tryUnpackNull();
 	}
 }
diff --git a/java/src/main/java/org/msgpack/schema/ArraySchema.java b/java/src/main/java/org/msgpack/schema/ArraySchema.java
deleted file mode 100644
index fd47143..0000000
--- a/java/src/main/java/org/msgpack/schema/ArraySchema.java
+++ /dev/null
@@ -1,125 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.RandomAccess;
-import java.io.IOException;
-import org.msgpack.*;
-
-public class ArraySchema extends Schema implements IArraySchema {
-	private Schema elementSchema;
-
-	public ArraySchema(Schema elementSchema)
-	{
-		super("array");
-		this.elementSchema = elementSchema;
-	}
-
-	@Override
-	public String getFullName()
-	{
-		return "List<"+elementSchema.getFullName()+">";
-	}
-
-	@Override
-	public String getExpression()
-	{
-		return "(array "+elementSchema.getExpression()+")";
-	}
-
-	@Override
-	@SuppressWarnings("unchecked")
-	public void pack(Packer pk, Object obj) throws IOException
-	{
-		if(obj instanceof List) {
-			ArrayList d = (ArrayList)obj;
-			pk.packArray(d.size());
-			if(obj instanceof RandomAccess) {
-				for(int i=0; i < d.size(); ++i) {
-					elementSchema.pack(pk, d.get(i));
-				}
-			} else {
-				for(Object e : d) {
-					elementSchema.pack(pk, e);
-				}
-			}
-
-		} else if(obj instanceof Set) {
-			Set d = (Set)obj;
-			pk.packArray(d.size());
-			for(Object e : d) {
-				elementSchema.pack(pk, e);
-			}
-
-		} else if(obj == null) {
-			pk.packNil();
-
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	@Override
-	@SuppressWarnings("unchecked")
-	public Object convert(Object obj) throws MessageTypeException
-	{
-		if(obj instanceof List) {
-			List d = (List)obj;
-			ArrayList ar = new ArrayList(d.size());
-			if(obj instanceof RandomAccess) {
-				for(int i=0; i < d.size(); ++i) {
-					ar.add( elementSchema.convert(d.get(i)) );
-				}
-			} else {
-				for(Object e : d) {
-					ar.add( elementSchema.convert(e) );
-				}
-			}
-			return ar;
-
-		} else if(obj instanceof Collection) {
-			Collection d = (Collection)obj;
-			ArrayList ar = new ArrayList(d.size());
-			for(Object e : (Collection)obj) {
-				ar.add( elementSchema.convert(e) );
-			}
-			return ar;
-
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	@Override
-	public Schema getElementSchema(int index)
-	{
-		return elementSchema;
-	}
-
-	@Override
-	public Object createFromArray(Object[] obj)
-	{
-		return Arrays.asList(obj);
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/BooleanSchema.java b/java/src/main/java/org/msgpack/schema/BooleanSchema.java
new file mode 100644
index 0000000..2c325f1
--- /dev/null
+++ b/java/src/main/java/org/msgpack/schema/BooleanSchema.java
@@ -0,0 +1,64 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.schema;
+
+import java.io.IOException;
+import org.msgpack.*;
+
+public class BooleanSchema extends Schema {
+	public BooleanSchema() { }
+
+	@Override
+	public String getClassName() {
+		return "Boolean";
+	}
+
+	@Override
+	public String getExpression() {
+		return "boolean";
+	}
+
+	@Override
+	public void pack(Packer pk, Object obj) throws IOException {
+		if(obj instanceof Boolean) {
+			pk.packBoolean((Boolean)obj);
+		} else if(obj == null) {
+			pk.packNil();
+		} else {
+			throw MessageTypeException.invalidConvert(obj, this);
+		}
+	}
+
+	public static final boolean convertBoolean(Object obj) throws MessageTypeException {
+		if(obj instanceof Boolean) {
+			return (Boolean)obj;
+		}
+		throw new MessageTypeException();
+	}
+
+	@Override
+	public Object convert(Object obj) throws MessageTypeException {
+		return convertBoolean(obj);
+	}
+
+	@Override
+	public Object createFromBoolean(boolean v) {
+		return v;
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/schema/ByteArraySchema.java b/java/src/main/java/org/msgpack/schema/ByteArraySchema.java
new file mode 100644
index 0000000..af9c0ed
--- /dev/null
+++ b/java/src/main/java/org/msgpack/schema/ByteArraySchema.java
@@ -0,0 +1,97 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.schema;
+
+import java.nio.ByteBuffer;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import org.msgpack.*;
+
+public class ByteArraySchema extends Schema {
+	public ByteArraySchema() { }
+
+	@Override
+	public String getClassName() {
+		return "byte[]";
+	}
+
+	@Override
+	public String getExpression() {
+		return "raw";
+	}
+
+	@Override
+	public void pack(Packer pk, Object obj) throws IOException {
+		if(obj instanceof byte[]) {
+			byte[] b = (byte[])obj;
+			pk.packRaw(b.length);
+			pk.packRawBody(b);
+		} else if(obj instanceof String) {
+			try {
+				byte[] b = ((String)obj).getBytes("UTF-8");
+				pk.packRaw(b.length);
+				pk.packRawBody(b);
+			} catch (UnsupportedEncodingException e) {
+				throw new MessageTypeException();
+			}
+		} else if(obj == null) {
+			pk.packNil();
+		} else {
+			throw MessageTypeException.invalidConvert(obj, this);
+		}
+	}
+
+	public static final byte[] convertByteArray(Object obj) throws MessageTypeException {
+		if(obj instanceof byte[]) {
+			// FIXME copy?
+			//byte[] d = (byte[])obj;
+			//byte[] v = new byte[d.length];
+			//System.arraycopy(d, 0, v, 0, d.length);
+			//return v;
+			return (byte[])obj;
+		} else if(obj instanceof ByteBuffer) {
+			ByteBuffer d = (ByteBuffer)obj;
+			byte[] v = new byte[d.capacity()];
+			int pos = d.position();
+			d.get(v);
+			d.position(pos);
+			return v;
+		} else if(obj instanceof String) {
+			try {
+				return ((String)obj).getBytes("UTF-8");
+			} catch (UnsupportedEncodingException e) {
+				throw new MessageTypeException();
+			}
+		} else {
+			throw new MessageTypeException();
+		}
+	}
+
+	@Override
+	public Object convert(Object obj) throws MessageTypeException {
+		return convertByteArray(obj);
+	}
+
+	@Override
+	public Object createFromRaw(byte[] b, int offset, int length) {
+		byte[] d = new byte[length];
+		System.arraycopy(b, offset, d, 0, length);
+		return d;
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/schema/ByteSchema.java b/java/src/main/java/org/msgpack/schema/ByteSchema.java
index 9ee6a82..6003a0f 100644
--- a/java/src/main/java/org/msgpack/schema/ByteSchema.java
+++ b/java/src/main/java/org/msgpack/schema/ByteSchema.java
@@ -21,8 +21,11 @@ import java.io.IOException;
 import org.msgpack.*;
 
 public class ByteSchema extends Schema {
-	public ByteSchema() {
-		super("Byte");
+	public ByteSchema() { }
+
+	@Override
+	public String getClassName() {
+		return "Byte";
 	}
 
 	@Override
@@ -33,27 +36,32 @@ public class ByteSchema extends Schema {
 	@Override
 	public void pack(Packer pk, Object obj) throws IOException {
 		if(obj instanceof Number) {
-			pk.packByte( ((Number)obj).byteValue() );
-
+			short value = ((Number)obj).shortValue();
+			if(value > Byte.MAX_VALUE) {
+				throw new MessageTypeException();
+			}
+			pk.packByte((byte)value);
 		} else if(obj == null) {
 			pk.packNil();
-
 		} else {
 			throw MessageTypeException.invalidConvert(obj, this);
 		}
 	}
 
+	public static final byte convertByte(Object obj) throws MessageTypeException {
+		if(obj instanceof Number) {
+			short value = ((Number)obj).shortValue();
+			if(value > Byte.MAX_VALUE) {
+				throw new MessageTypeException();
+			}
+			return (byte)value;
+		}
+		throw new MessageTypeException();
+	}
+
 	@Override
 	public Object convert(Object obj) throws MessageTypeException {
-		if(obj instanceof Byte) {
-			return obj;
-
-		} else if(obj instanceof Number) {
-			return ((Number)obj).byteValue();
-
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
+		return convertByte(obj);
 	}
 
 	@Override
@@ -63,26 +71,25 @@ public class ByteSchema extends Schema {
 
 	@Override
 	public Object createFromShort(short v) {
+		if(v > Byte.MAX_VALUE) {
+			throw new MessageTypeException();
+		}
 		return (byte)v;
 	}
 
 	@Override
 	public Object createFromInt(int v) {
+		if(v > Byte.MAX_VALUE) {
+			throw new MessageTypeException();
+		}
 		return (byte)v;
 	}
 
 	@Override
 	public Object createFromLong(long v) {
-		return (byte)v;
-	}
-
-	@Override
-	public Object createFromFloat(float v) {
-		return (byte)v;
-	}
-
-	@Override
-	public Object createFromDouble(double v) {
+		if(v > Byte.MAX_VALUE) {
+			throw new MessageTypeException();
+		}
 		return (byte)v;
 	}
 }
diff --git a/java/src/main/java/org/msgpack/schema/ClassGenerator.java b/java/src/main/java/org/msgpack/schema/ClassGenerator.java
index f8a13fa..a515996 100644
--- a/java/src/main/java/org/msgpack/schema/ClassGenerator.java
+++ b/java/src/main/java/org/msgpack/schema/ClassGenerator.java
@@ -77,8 +77,11 @@ public class ClassGenerator {
 			for(FieldSchema f : cs.getFields()) {
 				findSubclassSchema(dst, f.getSchema());
 			}
-		} else if(s instanceof ArraySchema) {
-			ArraySchema as = (ArraySchema)s;
+		} else if(s instanceof ListSchema) {
+			ListSchema as = (ListSchema)s;
+			findSubclassSchema(dst, as.getElementSchema(0));
+		} else if(s instanceof SetSchema) {
+			SetSchema as = (SetSchema)s;
 			findSubclassSchema(dst, as.getElementSchema(0));
 		} else if(s instanceof MapSchema) {
 			MapSchema as = (MapSchema)s;
@@ -105,7 +108,7 @@ public class ClassGenerator {
 
 	private void writeClass() throws IOException {
 		line();
-		line("public final class "+schema.getName()+" implements MessagePackable, MessageConvertable");
+		line("public final class "+schema.getClassName()+" implements MessagePackable, MessageConvertable");
 		line("{");
 		pushIndent();
 			writeSchema();
@@ -117,7 +120,7 @@ public class ClassGenerator {
 
 	private void writeSubclass() throws IOException {
 		line();
-		line("final class "+schema.getName()+" implements MessagePackable, MessageConvertable");
+		line("final class "+schema.getClassName()+" implements MessagePackable, MessageConvertable");
 		line("{");
 		pushIndent();
 			writeSchema();
@@ -135,7 +138,7 @@ public class ClassGenerator {
 	private void writeMemberVariables() throws IOException {
 		line();
 		for(FieldSchema f : schema.getFields()) {
-			line("public "+f.getSchema().getFullName()+" "+f.getName()+";");
+			line("public "+f.getSchema().getClassName()+" "+f.getName()+";");
 		}
 	}
 
@@ -156,7 +159,7 @@ public class ClassGenerator {
 
 	private void writeConstructors() throws IOException {
 		line();
-		line("public "+schema.getName()+"() { }");
+		line("public "+schema.getClassName()+"() { }");
 	}
 
 	private void writeAccessors() throws IOException {
@@ -195,7 +198,7 @@ public class ClassGenerator {
 			line("FieldSchema[] _fields = _SCHEMA.getFields();");
 			int i = 0;
 			for(FieldSchema f : schema.getFields()) {
-				line("if(_source.length <= "+i+") { return; } this."+f.getName()+" = ("+f.getSchema().getFullName()+")_fields["+i+"].getSchema().convert(_source["+i+"]);");
+				line("if(_source.length <= "+i+") { return; } this."+f.getName()+" = ("+f.getSchema().getClassName()+")_fields["+i+"].getSchema().convert(_source["+i+"]);");
 				++i;
 			}
 		popIndent();
@@ -205,13 +208,13 @@ public class ClassGenerator {
 	private void writeFactoryFunction() throws IOException {
 		line();
 		line("@SuppressWarnings(\"unchecked\")");
-		line("public static "+schema.getName()+" createFromMessage(Object[] _message)");
+		line("public static "+schema.getClassName()+" createFromMessage(Object[] _message)");
 		line("{");
 		pushIndent();
-			line(schema.getName()+" _self = new "+schema.getName()+"();");
+			line(schema.getClassName()+" _self = new "+schema.getClassName()+"();");
 			int i = 0;
 			for(FieldSchema f : schema.getFields()) {
-				line("if(_message.length <= "+i+") { return _self; } _self."+f.getName()+" = ("+f.getSchema().getFullName()+")_message["+i+"];");
+				line("if(_message.length <= "+i+") { return _self; } _self."+f.getName()+" = ("+f.getSchema().getClassName()+")_message["+i+"];");
 				++i;
 			}
 			line("return _self;");
diff --git a/java/src/main/java/org/msgpack/schema/ClassSchema.java b/java/src/main/java/org/msgpack/schema/ClassSchema.java
index cd5c008..cd59755 100644
--- a/java/src/main/java/org/msgpack/schema/ClassSchema.java
+++ b/java/src/main/java/org/msgpack/schema/ClassSchema.java
@@ -22,6 +22,7 @@ import java.util.List;
 import org.msgpack.*;
 
 public abstract class ClassSchema extends Schema implements IArraySchema {
+	protected String name;
 	protected FieldSchema[] fields;
 	protected List imports;
 	protected String namespace;
@@ -30,7 +31,7 @@ public abstract class ClassSchema extends Schema implements IArraySchema {
 	public ClassSchema(
 			String name, String namespace,
 			List imports, List fields) {
-		super(name);
+		this.name = name;
 		this.namespace = namespace;
 		this.imports = imports;  // FIXME clone?
 		this.fields = new FieldSchema[fields.size()];
@@ -42,6 +43,31 @@ public abstract class ClassSchema extends Schema implements IArraySchema {
 		}
 	}
 
+	@Override
+	public String getClassName() {
+		return name;
+	}
+
+	@Override
+	public String getExpression() {
+		StringBuffer b = new StringBuffer();
+		b.append("(class ");
+		b.append(name);
+		if(namespace != null) {
+			b.append(" (package "+namespace+")");
+		}
+		for(FieldSchema f : fields) {
+			b.append(" "+f.getExpression());
+		}
+		b.append(")");
+		return b.toString();
+	}
+
+	public boolean equals(ClassSchema o) {
+		return (namespace != null ? namespace.equals(o.getNamespace()) : o.getNamespace() == null) &&
+			name.equals(o.name);
+	}
+
 	public final FieldSchema[] getFields() {
 		return fields;
 	}
@@ -61,35 +87,5 @@ public abstract class ClassSchema extends Schema implements IArraySchema {
 	void setImports(List imports) {
 		this.imports = imports;  // FIXME clone?
 	}
-
-	//@Override
-	//public String getFullName()
-	//{
-	//	if(namespace == null) {
-	//		return getName();
-	//	} else {
-	//		return namespace+"."+getName();
-	//	}
-	//}
-
-	@Override
-	public String getExpression() {
-		StringBuffer b = new StringBuffer();
-		b.append("(class ");
-		b.append(getName());
-		if(namespace != null) {
-			b.append(" (package "+namespace+")");
-		}
-		for(FieldSchema f : fields) {
-			b.append(" "+f.getExpression());
-		}
-		b.append(")");
-		return b.toString();
-	}
-
-	public boolean equals(SpecificClassSchema o) {
-		return (namespace != null ? namespace.equals(o.getNamespace()) : o.getNamespace() == null) &&
-			getName().equals(o.getName());
-	}
 }
 
diff --git a/java/src/main/java/org/msgpack/schema/DoubleSchema.java b/java/src/main/java/org/msgpack/schema/DoubleSchema.java
index d53e47d..cb857c3 100644
--- a/java/src/main/java/org/msgpack/schema/DoubleSchema.java
+++ b/java/src/main/java/org/msgpack/schema/DoubleSchema.java
@@ -21,8 +21,11 @@ import java.io.IOException;
 import org.msgpack.*;
 
 public class DoubleSchema extends Schema {
-	public DoubleSchema() {
-		super("Double");
+	public DoubleSchema() { }
+
+	@Override
+	public String getClassName() {
+		return "Double";
 	}
 
 	@Override
@@ -32,43 +35,30 @@ public class DoubleSchema extends Schema {
 
 	@Override
 	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof Number) {
-			pk.packDouble( ((Number)obj).doubleValue() );
-
+		if(obj instanceof Double) {
+			pk.packDouble((Double)obj);
+		} else if(obj instanceof Float) {
+			pk.packFloat((Float)obj);
 		} else if(obj == null) {
 			pk.packNil();
-
 		} else {
 			throw MessageTypeException.invalidConvert(obj, this);
 		}
 	}
 
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
+	public static final double convertDouble(Object obj) throws MessageTypeException {
 		if(obj instanceof Double) {
-			return obj;
-
-		} else if(obj instanceof Number) {
-			return ((Number)obj).doubleValue();
-
+			return (Double)obj;
+		} else if(obj instanceof Float) {
+			return ((Float)obj).doubleValue();
 		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
+			throw new MessageTypeException();
 		}
 	}
 
 	@Override
-	public Object createFromByte(byte v) {
-		return (double)v;
-	}
-
-	@Override
-	public Object createFromShort(short v) {
-		return (double)v;
-	}
-
-	@Override
-	public Object createFromInt(int v) {
-		return (double)v;
+	public Object convert(Object obj) throws MessageTypeException {
+		return convertDouble(obj);
 	}
 
 	@Override
diff --git a/java/src/main/java/org/msgpack/schema/FloatSchema.java b/java/src/main/java/org/msgpack/schema/FloatSchema.java
index 2777521..cd73201 100644
--- a/java/src/main/java/org/msgpack/schema/FloatSchema.java
+++ b/java/src/main/java/org/msgpack/schema/FloatSchema.java
@@ -21,8 +21,11 @@ import java.io.IOException;
 import org.msgpack.*;
 
 public class FloatSchema extends Schema {
-	public FloatSchema() {
-		super("Float");
+	public FloatSchema() { }
+
+	@Override
+	public String getClassName() {
+		return "Float";
 	}
 
 	@Override
@@ -32,43 +35,30 @@ public class FloatSchema extends Schema {
 
 	@Override
 	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof Number) {
-			pk.packFloat( ((Number)obj).floatValue() );
-
+		if(obj instanceof Double) {
+			pk.packDouble((Double)obj);
+		} else if(obj instanceof Float) {
+			pk.packFloat((Float)obj);
 		} else if(obj == null) {
 			pk.packNil();
-
 		} else {
 			throw MessageTypeException.invalidConvert(obj, this);
 		}
 	}
 
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		if(obj instanceof Float) {
-			return obj;
-
-		} else if(obj instanceof Number) {
-			return ((Number)obj).floatValue();
-
+	public static final float convertFloat(Object obj) throws MessageTypeException {
+		if(obj instanceof Double) {
+			return ((Double)obj).floatValue();
+		} else if(obj instanceof Float) {
+			return (Float)obj;
 		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
+			throw new MessageTypeException();
 		}
 	}
 
 	@Override
-	public Object createFromByte(byte v) {
-		return (float)v;
-	}
-
-	@Override
-	public Object createFromShort(short v) {
-		return (float)v;
-	}
-
-	@Override
-	public Object createFromInt(int v) {
-		return (float)v;
+	public Object convert(Object obj) throws MessageTypeException {
+		return convertFloat(obj);
 	}
 
 	@Override
diff --git a/java/src/main/java/org/msgpack/schema/GenericClassSchema.java b/java/src/main/java/org/msgpack/schema/GenericClassSchema.java
index ffdd4ab..1ab4c33 100644
--- a/java/src/main/java/org/msgpack/schema/GenericClassSchema.java
+++ b/java/src/main/java/org/msgpack/schema/GenericClassSchema.java
@@ -41,10 +41,8 @@ public class GenericClassSchema extends ClassSchema {
 				FieldSchema f = fields[i];
 				f.getSchema().pack(pk, d.get(f.getName()));
 			}
-
 		} else if(obj == null) {
 			pk.packNil();
-
 		} else {
 			throw MessageTypeException.invalidConvert(obj, this);
 		}
@@ -55,7 +53,6 @@ public class GenericClassSchema extends ClassSchema {
 		if(obj instanceof Collection) {
 			// FIXME optimize
 			return createFromArray( ((Collection)obj).toArray() );
-
 		} else if(obj instanceof Map) {
 			HashMap m = new HashMap(fields.length);
 			Map d = (Map)obj;
@@ -65,7 +62,6 @@ public class GenericClassSchema extends ClassSchema {
 				m.put(fieldName, f.getSchema().convert(d.get(fieldName)));
 			}
 			return m;
-
 		} else {
 			throw MessageTypeException.invalidConvert(obj, this);
 		}
diff --git a/java/src/main/java/org/msgpack/schema/GenericSchema.java b/java/src/main/java/org/msgpack/schema/GenericSchema.java
index 0adf898..f9098ed 100644
--- a/java/src/main/java/org/msgpack/schema/GenericSchema.java
+++ b/java/src/main/java/org/msgpack/schema/GenericSchema.java
@@ -22,11 +22,13 @@ import java.util.List;
 import java.util.HashMap;
 import java.io.IOException;
 import org.msgpack.*;
-//import org.msgpack.generic.*;
 
 public class GenericSchema extends Schema implements IArraySchema, IMapSchema {
-	public GenericSchema() {
-		super("Object");
+	public GenericSchema() { }
+
+	@Override
+	public String getClassName() {
+		return "Object";
 	}
 
 	@Override
@@ -123,70 +125,5 @@ public class GenericSchema extends Schema implements IArraySchema, IMapSchema {
 		}
 		return m;
 	}
-
-	/*
-   @Override
-	public Object createFromNil() {
-		return null;
-	}
-
-	@Override
-	public Object createFromBoolean(boolean v) {
-		return new GenericBoolean(v);
-	}
-
-	@Override
-	public Object createFromFromByte(byte v) {
-		return new GenericByte(v);
-	}
-
-	@Override
-	public Object createFromShort(short v) {
-		return new GenericShort(v);
-	}
-
-	@Override
-	public Object createFromInt(int v) {
-		return new GenericInt(v);
-	}
-
-	@Override
-	public Object createFromLong(long v) {
-		return new GenericLong(v);
-	}
-
-	@Override
-	public Object createFromFloat(float v) {
-		return new GenericFloat(v);
-	}
-
-	@Override
-	public Object createFromDouble(double v) {
-		return new GenericDouble(v);
-	}
-
-	@Override
-	public Object createFromRaw(byte[] b, int offset, int length) {
-		return new GenericRaw(b, offset, length);
-	}
-
-	@Override
-	public Object createFromArray(Object[] obj) {
-		// FIXME GenericArray
-		return Arrays.asList(obj);
-	}
-
-	@Override
-	public Object createFromMap(Object[] obj) {
-		GenericMap m = new GenericMap(obj.length / 2);
-		int i = 0;
-		while(i < obj.length) {
-			Object k = obj[i++];
-			Object v = obj[i++];
-			m.put(k, v);
-		}
-		return m;
-	}
-	*/
 }
 
diff --git a/java/src/main/java/org/msgpack/schema/IntSchema.java b/java/src/main/java/org/msgpack/schema/IntSchema.java
index 5a7e281..269f4fb 100644
--- a/java/src/main/java/org/msgpack/schema/IntSchema.java
+++ b/java/src/main/java/org/msgpack/schema/IntSchema.java
@@ -21,8 +21,11 @@ import java.io.IOException;
 import org.msgpack.*;
 
 public class IntSchema extends Schema {
-	public IntSchema() {
-		super("Integer");
+	public IntSchema() { }
+
+	@Override
+	public String getClassName() {
+		return "Integer";
 	}
 
 	@Override
@@ -33,27 +36,38 @@ public class IntSchema extends Schema {
 	@Override
 	public void pack(Packer pk, Object obj) throws IOException {
 		if(obj instanceof Number) {
-			pk.packInt( ((Number)obj).intValue() );
-
+			int value = ((Number)obj).intValue();
+			if(value >= Short.MAX_VALUE) {
+				long lvalue = ((Number)obj).longValue();
+				if(lvalue > Integer.MAX_VALUE) {
+					throw new MessageTypeException();
+				}
+			}
+			pk.packInt(value);
 		} else if(obj == null) {
 			pk.packNil();
-
 		} else {
 			throw MessageTypeException.invalidConvert(obj, this);
 		}
 	}
 
+	public static final int convertInt(Object obj) throws MessageTypeException {
+		if(obj instanceof Number) {
+			int value = ((Number)obj).intValue();
+			if(value >= Integer.MAX_VALUE) {
+				long lvalue = ((Number)obj).longValue();
+				if(lvalue > Integer.MAX_VALUE) {
+					throw new MessageTypeException();
+				}
+			}
+			return value;
+		}
+		throw new MessageTypeException();
+	}
+
 	@Override
 	public Object convert(Object obj) throws MessageTypeException {
-		if(obj instanceof Integer) {
-			return obj;
-
-		} else if(obj instanceof Number) {
-			return ((Number)obj).intValue();
-
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
+		return convertInt(obj);
 	}
 
 	@Override
@@ -73,16 +87,9 @@ public class IntSchema extends Schema {
 
 	@Override
 	public Object createFromLong(long v) {
-		return (int)v;
-	}
-
-	@Override
-	public Object createFromFloat(float v) {
-		return (int)v;
-	}
-
-	@Override
-	public Object createFromDouble(double v) {
+		if(v > Integer.MAX_VALUE) {
+			throw new MessageTypeException();
+		}
 		return (int)v;
 	}
 }
diff --git a/java/src/main/java/org/msgpack/schema/ListSchema.java b/java/src/main/java/org/msgpack/schema/ListSchema.java
new file mode 100644
index 0000000..bef8cc4
--- /dev/null
+++ b/java/src/main/java/org/msgpack/schema/ListSchema.java
@@ -0,0 +1,111 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.schema;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.RandomAccess;
+import java.io.IOException;
+import org.msgpack.*;
+
+public class ListSchema extends Schema implements IArraySchema {
+	private Schema elementSchema;
+
+	public ListSchema(Schema elementSchema) {
+		this.elementSchema = elementSchema;
+	}
+
+	@Override
+	public String getClassName() {
+		return "List<"+elementSchema.getClassName()+">";
+	}
+
+	@Override
+	public String getExpression() {
+		return "(array "+elementSchema.getExpression()+")";
+	}
+
+	@Override
+	public void pack(Packer pk, Object obj) throws IOException {
+		if(obj instanceof List) {
+			List d = (List)obj;
+			pk.packArray(d.size());
+			if(obj instanceof RandomAccess) {
+				for(int i=0; i < d.size(); ++i) {
+					elementSchema.pack(pk, d.get(i));
+				}
+			} else {
+				for(Object e : d) {
+					elementSchema.pack(pk, e);
+				}
+			}
+		} else if(obj instanceof Set) {
+			Set d = (Set)obj;
+			pk.packArray(d.size());
+			for(Object e : d) {
+				elementSchema.pack(pk, e);
+			}
+		} else if(obj == null) {
+			pk.packNil();
+		} else {
+			throw MessageTypeException.invalidConvert(obj, this);
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	public static final  List convertList(Object obj,
+			Schema elementSchema, List dest) throws MessageTypeException {
+		if(!(obj instanceof List)) {
+			throw new MessageTypeException();
+		}
+		List d = (List)obj;
+		if(dest == null) {
+			dest = new ArrayList(d.size());
+		}
+		if(obj instanceof RandomAccess) {
+			for(int i=0; i < d.size(); ++i) {
+				dest.add( (T)elementSchema.convert(d.get(i)) );
+			}
+		} else {
+			for(Object e : d) {
+				dest.add( (T)elementSchema.convert(e) );
+			}
+		}
+		return dest;
+	}
+
+	@Override
+	public Object convert(Object obj) throws MessageTypeException {
+		return convertList(obj, elementSchema, null);
+	}
+
+	@Override
+	public Schema getElementSchema(int index) {
+		return elementSchema;
+	}
+
+	@Override
+	public Object createFromArray(Object[] obj) {
+		return Arrays.asList(obj);
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/schema/LongSchema.java b/java/src/main/java/org/msgpack/schema/LongSchema.java
index 83a30e3..728fa21 100644
--- a/java/src/main/java/org/msgpack/schema/LongSchema.java
+++ b/java/src/main/java/org/msgpack/schema/LongSchema.java
@@ -21,8 +21,11 @@ import java.io.IOException;
 import org.msgpack.*;
 
 public class LongSchema extends Schema {
-	public LongSchema() {
-		super("Long");
+	public LongSchema() { }
+
+	@Override
+	public String getClassName() {
+		return "Long";
 	}
 
 	@Override
@@ -33,27 +36,25 @@ public class LongSchema extends Schema {
 	@Override
 	public void pack(Packer pk, Object obj) throws IOException {
 		if(obj instanceof Number) {
-			pk.packLong( ((Number)obj).longValue() );
-
+			long value = ((Number)obj).longValue();
+			pk.packLong(value);
 		} else if(obj == null) {
 			pk.packNil();
-
 		} else {
 			throw MessageTypeException.invalidConvert(obj, this);
 		}
 	}
 
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		if(obj instanceof Long) {
-			return obj;
-
-		} else if(obj instanceof Number) {
+	public static final long convertLong(Object obj) throws MessageTypeException {
+		if(obj instanceof Number) {
 			return ((Number)obj).longValue();
-
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
 		}
+		throw new MessageTypeException();
+	}
+
+	@Override
+	public Object convert(Object obj) throws MessageTypeException {
+		return convertLong(obj);
 	}
 
 	@Override
@@ -75,15 +76,5 @@ public class LongSchema extends Schema {
 	public Object createFromLong(long v) {
 		return (long)v;
 	}
-
-	@Override
-	public Object createFromFloat(float v) {
-		return (long)v;
-	}
-
-	@Override
-	public Object createFromDouble(double v) {
-		return (long)v;
-	}
 }
 
diff --git a/java/src/main/java/org/msgpack/schema/MapSchema.java b/java/src/main/java/org/msgpack/schema/MapSchema.java
index ba75993..339a5c2 100644
--- a/java/src/main/java/org/msgpack/schema/MapSchema.java
+++ b/java/src/main/java/org/msgpack/schema/MapSchema.java
@@ -27,14 +27,13 @@ public class MapSchema extends Schema implements IMapSchema {
 	private Schema valueSchema;
 
 	public MapSchema(Schema keySchema, Schema valueSchema) {
-		super("map");
 		this.keySchema = keySchema;
 		this.valueSchema = valueSchema;
 	}
 
 	@Override
-	public String getFullName() {
-		return "HashList<"+keySchema.getFullName()+", "+valueSchema.getFullName()+">";
+	public String getClassName() {
+		return "Map<"+keySchema.getClassName()+", "+valueSchema.getClassName()+">";
 	}
 
 	@Override
@@ -52,29 +51,33 @@ public class MapSchema extends Schema implements IMapSchema {
 				keySchema.pack(pk, e.getKey());
 				valueSchema.pack(pk, e.getValue());
 			}
-
 		} else if(obj == null) {
 			pk.packNil();
-
 		} else {
 			throw MessageTypeException.invalidConvert(obj, this);
 		}
 	}
 
-	@Override
 	@SuppressWarnings("unchecked")
-	public Object convert(Object obj) throws MessageTypeException {
-		if(obj instanceof Map) {
-			Map d = (Map)obj;
-			Map m = new HashMap();
-			for(Map.Entry e : d.entrySet()) {
-				m.put(keySchema.convert(e.getKey()), valueSchema.convert(e.getValue()));
-			}
-			return m;
-
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
+	public static final  Map convertMap(Object obj,
+			Schema keySchema, Schema valueSchema, Map dest) throws MessageTypeException {
+		if(!(obj instanceof Map)) {
+			throw new MessageTypeException();
+		}
+		Map d = (Map)obj;
+		if(dest == null) {
+			dest = new HashMap(d.size());
+		}
+		for(Map.Entry e : d.entrySet()) {
+			dest.put((K)keySchema.convert(e.getKey()),
+					(V)valueSchema.convert(e.getValue()));
 		}
+		return (Map)d;
+	}
+
+	@Override
+	public Object convert(Object obj) throws MessageTypeException {
+		return convertMap(obj, keySchema, valueSchema, null);
 	}
 
 	@Override
@@ -90,14 +93,14 @@ public class MapSchema extends Schema implements IMapSchema {
 	@Override
 	@SuppressWarnings("unchecked")
 	public Object createFromMap(Object[] obj) {
-		HashMap m = new HashMap(obj.length / 2);
+		HashMap dest = new HashMap(obj.length / 2);
 		int i = 0;
 		while(i < obj.length) {
 			Object k = obj[i++];
 			Object v = obj[i++];
-			m.put(k, v);
+			dest.put(k, v);
 		}
-		return m;
+		return dest;
 	}
 }
 
diff --git a/java/src/main/java/org/msgpack/schema/RawSchema.java b/java/src/main/java/org/msgpack/schema/RawSchema.java
deleted file mode 100644
index f621e4c..0000000
--- a/java/src/main/java/org/msgpack/schema/RawSchema.java
+++ /dev/null
@@ -1,105 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.nio.ByteBuffer;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import org.msgpack.*;
-
-public class RawSchema extends Schema {
-	public RawSchema() {
-		super("raw");
-	}
-
-	public String getFullName() {
-		return "byte[]";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		// FIXME instanceof GenericObject
-		if(obj instanceof byte[]) {
-			byte[] d = (byte[])obj;
-			pk.packRaw(d.length);
-			pk.packRawBody(d);
-
-		} else if(obj instanceof ByteBuffer) {
-			ByteBuffer d = (ByteBuffer)obj;
-			if(!d.hasArray()) {
-				throw MessageTypeException.invalidConvert(obj, this);
-			}
-			pk.packRaw(d.capacity());
-			pk.packRawBody(d.array(), d.position(), d.capacity());
-
-		} else if(obj instanceof String) {
-			try {
-				byte[] d = ((String)obj).getBytes("UTF-8");
-				pk.packRaw(d.length);
-				pk.packRawBody(d);
-			} catch (UnsupportedEncodingException e) {
-				throw MessageTypeException.invalidConvert(obj, this);
-			}
-
-		} else if(obj == null) {
-			pk.packNil();
-
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		// FIXME instanceof GenericObject
-		if(obj instanceof byte[]) {
-			// FIXME copy?
-			//byte[] d = (byte[])obj;
-			//byte[] v = new byte[d.length];
-			//System.arraycopy(d, 0, v, 0, d.length);
-			//return v;
-			return obj;
-
-		} else if(obj instanceof ByteBuffer) {
-			ByteBuffer d = (ByteBuffer)obj;
-			byte[] v = new byte[d.capacity()];
-			int pos = d.position();
-			d.get(v);
-			d.position(pos);
-			return v;
-
-		} else if(obj instanceof String) {
-			try {
-				return ((String)obj).getBytes("UTF-8");
-			} catch (UnsupportedEncodingException e) {
-				throw MessageTypeException.invalidConvert(obj, this);
-			}
-
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	@Override
-	public Object createFromRaw(byte[] b, int offset, int length) {
-		byte[] d = new byte[length];
-		System.arraycopy(b, offset, d, 0, length);
-		return d;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/SSchemaParser.java b/java/src/main/java/org/msgpack/schema/SSchemaParser.java
index 4ae8a4b..4345e92 100644
--- a/java/src/main/java/org/msgpack/schema/SSchemaParser.java
+++ b/java/src/main/java/org/msgpack/schema/SSchemaParser.java
@@ -140,7 +140,7 @@ public class SSchemaParser {
 			if(type.equals("string")) {
 				return new StringSchema();
 			} else if(type.equals("raw")) {
-				return new RawSchema();
+				return new ByteArraySchema();
 			} else if(type.equals("byte")) {
 				return new ByteSchema();
 			} else if(type.equals("short")) {
@@ -163,11 +163,13 @@ public class SSchemaParser {
 			if(type.equals("class")) {
 				return parseClass(exp);
 			} else if(type.equals("array")) {
-				return parseArray(exp);
+				return parseList(exp);
+			} else if(type.equals("set")) {
+				return parseSet(exp);
 			} else if(type.equals("map")) {
 				return parseMap(exp);
 			} else {
-				throw new RuntimeException("class, array or map is expected but got '"+type+"': "+exp);
+				throw new RuntimeException("class, list, set or map is expected but got '"+type+"': "+exp);
 			}
 		}
 	}
@@ -209,12 +211,20 @@ public class SSchemaParser {
 		}
 	}
 
-	private ArraySchema parseArray(SExp exp) {
+	private ListSchema parseList(SExp exp) {
 		if(exp.size() != 2) {
-			throw new RuntimeException("array is (array ELEMENT_TYPE): "+exp);
+			throw new RuntimeException("list is (list ELEMENT_TYPE): "+exp);
 		}
 		Schema elementType = readType(exp.getTuple(1));
-		return new ArraySchema(elementType);
+		return new ListSchema(elementType);
+	}
+
+	private SetSchema parseSet(SExp exp) {
+		if(exp.size() != 2) {
+			throw new RuntimeException("list is (list ELEMENT_TYPE): "+exp);
+		}
+		Schema elementType = readType(exp.getTuple(1));
+		return new SetSchema(elementType);
 	}
 
 	private MapSchema parseMap(SExp exp) {
diff --git a/java/src/main/java/org/msgpack/schema/SetSchema.java b/java/src/main/java/org/msgpack/schema/SetSchema.java
new file mode 100644
index 0000000..a3e1974
--- /dev/null
+++ b/java/src/main/java/org/msgpack/schema/SetSchema.java
@@ -0,0 +1,115 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.schema;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.RandomAccess;
+import java.io.IOException;
+import org.msgpack.*;
+
+public class SetSchema extends Schema implements IArraySchema {
+	private Schema elementSchema;
+
+	public SetSchema(Schema elementSchema) {
+		this.elementSchema = elementSchema;
+	}
+
+	@Override
+	public String getClassName() {
+		return "Set<"+elementSchema.getClassName()+">";
+	}
+
+	@Override
+	public String getExpression() {
+		return "(set "+elementSchema.getExpression()+")";
+	}
+
+	@Override
+	public void pack(Packer pk, Object obj) throws IOException {
+		if(obj instanceof List) {
+			List d = (List)obj;
+			pk.packArray(d.size());
+			if(obj instanceof RandomAccess) {
+				for(int i=0; i < d.size(); ++i) {
+					elementSchema.pack(pk, d.get(i));
+				}
+			} else {
+				for(Object e : d) {
+					elementSchema.pack(pk, e);
+				}
+			}
+		} else if(obj instanceof Set) {
+			Set d = (Set)obj;
+			pk.packArray(d.size());
+			for(Object e : d) {
+				elementSchema.pack(pk, e);
+			}
+		} else if(obj == null) {
+			pk.packNil();
+		} else {
+			throw MessageTypeException.invalidConvert(obj, this);
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	public static final  Set convertSet(Object obj,
+			Schema elementSchema, Set dest) throws MessageTypeException {
+		if(!(obj instanceof List)) {
+			throw new MessageTypeException();
+		}
+		List d = (List)obj;
+		if(dest == null) {
+			dest = new HashSet(d.size());
+		}
+		if(obj instanceof RandomAccess) {
+			for(int i=0; i < d.size(); ++i) {
+				dest.add( (T)elementSchema.convert(d.get(i)) );
+			}
+		} else {
+			for(Object e : d) {
+				dest.add( (T)elementSchema.convert(e) );
+			}
+		}
+		return dest;
+	}
+
+	@Override
+	public Object convert(Object obj) throws MessageTypeException {
+		return convertSet(obj, elementSchema, null);
+	}
+
+	@Override
+	public Schema getElementSchema(int index) {
+		return elementSchema;
+	}
+
+	@Override
+	public Object createFromArray(Object[] obj) {
+		Set m = new HashSet(obj.length);
+		for(int i=0; i < obj.length; i++) {
+			m.add(obj[i]);
+		}
+		return m;
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/schema/ShortSchema.java b/java/src/main/java/org/msgpack/schema/ShortSchema.java
index f32ab41..21b9327 100644
--- a/java/src/main/java/org/msgpack/schema/ShortSchema.java
+++ b/java/src/main/java/org/msgpack/schema/ShortSchema.java
@@ -21,8 +21,11 @@ import java.io.IOException;
 import org.msgpack.*;
 
 public class ShortSchema extends Schema {
-	public ShortSchema() {
-		super("Short");
+	public ShortSchema() { }
+
+	@Override
+	public String getClassName() {
+		return "Short";
 	}
 
 	@Override
@@ -33,27 +36,32 @@ public class ShortSchema extends Schema {
 	@Override
 	public void pack(Packer pk, Object obj) throws IOException {
 		if(obj instanceof Number) {
-			pk.packShort( ((Number)obj).shortValue() );
-
+			int value = ((Number)obj).intValue();
+			if(value > Short.MAX_VALUE) {
+				throw new MessageTypeException();
+			}
+			pk.packShort((short)value);
 		} else if(obj == null) {
 			pk.packNil();
-
 		} else {
 			throw MessageTypeException.invalidConvert(obj, this);
 		}
 	}
 
+	public static final short convertShort(Object obj) throws MessageTypeException {
+		if(obj instanceof Number) {
+			int value = ((Number)obj).intValue();
+			if(value > Short.MAX_VALUE) {
+				throw new MessageTypeException();
+			}
+			return (short)value;
+		}
+		throw new MessageTypeException();
+	}
+
 	@Override
 	public Object convert(Object obj) throws MessageTypeException {
-		if(obj instanceof Short) {
-			return obj;
-
-		} else if(obj instanceof Number) {
-			return ((Number)obj).shortValue();
-
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
+		return convertShort(obj);
 	}
 
 	@Override
@@ -68,21 +76,17 @@ public class ShortSchema extends Schema {
 
 	@Override
 	public Object createFromInt(int v) {
+		if(v > Short.MAX_VALUE) {
+			throw new MessageTypeException();
+		}
 		return (short)v;
 	}
 
 	@Override
 	public Object createFromLong(long v) {
-		return (short)v;
-	}
-
-	@Override
-	public Object createFromFloat(float v) {
-		return (short)v;
-	}
-
-	@Override
-	public Object createFromDouble(double v) {
+		if(v > Short.MAX_VALUE) {
+			throw new MessageTypeException();
+		}
 		return (short)v;
 	}
 }
diff --git a/java/src/main/java/org/msgpack/schema/StringSchema.java b/java/src/main/java/org/msgpack/schema/StringSchema.java
index 46d515b..23e4e64 100644
--- a/java/src/main/java/org/msgpack/schema/StringSchema.java
+++ b/java/src/main/java/org/msgpack/schema/StringSchema.java
@@ -23,61 +23,48 @@ import java.io.UnsupportedEncodingException;
 import org.msgpack.*;
 
 public class StringSchema extends Schema {
-	public StringSchema() {
-		super("string");
-	}
+	public StringSchema() { }
 
 	@Override
-	public String getFullName() {
+	public String getClassName() {
 		return "String";
 	}
 
+	@Override
+	public String getExpression() {
+		return "string";
+	}
+
 	@Override
 	public void pack(Packer pk, Object obj) throws IOException {
-		// FIXME instanceof GenericObject
-		if(obj instanceof String) {
+		if(obj instanceof byte[]) {
+			byte[] b = (byte[])obj;
+			pk.packRaw(b.length);
+			pk.packRawBody(b);
+		} else if(obj instanceof String) {
 			try {
-				byte[] d = ((String)obj).getBytes("UTF-8");
-				pk.packRaw(d.length);
-				pk.packRawBody(d);
+				byte[] b = ((String)obj).getBytes("UTF-8");
+				pk.packRaw(b.length);
+				pk.packRawBody(b);
 			} catch (UnsupportedEncodingException e) {
-				throw MessageTypeException.invalidConvert(obj, this);
+				throw new MessageTypeException();
 			}
-
-		} else if(obj instanceof byte[]) {
-			byte[] d = (byte[])obj;
-			pk.packRaw(d.length);
-			pk.packRawBody(d);
-
-		} else if(obj instanceof ByteBuffer) {
-			ByteBuffer d = (ByteBuffer)obj;
-			if(!d.hasArray()) {
-				throw MessageTypeException.invalidConvert(obj, this);
-			}
-			pk.packRaw(d.capacity());
-			pk.packRawBody(d.array(), d.position(), d.capacity());
-
 		} else if(obj == null) {
 			pk.packNil();
-
 		} else {
 			throw MessageTypeException.invalidConvert(obj, this);
 		}
 	}
 
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		// FIXME instanceof GenericObject
-		if(obj instanceof String) {
-			return obj;
-
-		} else if(obj instanceof byte[]) {
+	public static final String convertString(Object obj) throws MessageTypeException {
+		if(obj instanceof byte[]) {
 			try {
 				return new String((byte[])obj, "UTF-8");
 			} catch (UnsupportedEncodingException e) {
-				throw MessageTypeException.invalidConvert(obj, this);
+				throw new MessageTypeException();
 			}
-
+		} else if(obj instanceof String) {
+			return (String)obj;
 		} else if(obj instanceof ByteBuffer) {
 			ByteBuffer d = (ByteBuffer)obj;
 			try {
@@ -91,14 +78,18 @@ public class StringSchema extends Schema {
 					return new String(v, "UTF-8");
 				}
 			} catch (UnsupportedEncodingException e) {
-				throw MessageTypeException.invalidConvert(obj, this);
+				throw new MessageTypeException();
 			}
-
 		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
+			throw new MessageTypeException();
 		}
 	}
 
+	@Override
+	public Object convert(Object obj) throws MessageTypeException {
+		return convertString(obj);
+	}
+
 	@Override
 	public Object createFromRaw(byte[] b, int offset, int length) {
 		try {
-- 
cgit v1.2.1


From 227c168b65be72e5e3a843af38d9382b59fc858a Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Sat, 24 Jul 2010 18:07:22 +0900
Subject: java: fixes fatal offset calculation bugs on
 BufferedUnpackerIMPL.unpackInt()

---
 java/src/main/java/org/msgpack/BufferedUnpackerImpl.java | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
index cc6604d..f4ed35b 100644
--- a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
+++ b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
@@ -103,7 +103,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
 		case 0xcc:  // unsigned int  8
 			more(2);
 			advance(2);
-			return (int)((short)buffer[offset+1] & 0xff);
+			return (int)((short)(buffer[offset-1]) & 0xff);
 		case 0xcd:  // unsigned int 16
 			more(3);
 			castBuffer.rewind();
@@ -137,7 +137,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
 		case 0xd0:  // signed int  8
 			more(2);
 			advance(2);
-			return (int)buffer[offset+1];
+			return (int)buffer[offset-1];
 		case 0xd1:  // signed int 16
 			more(3);
 			castBuffer.rewind();
@@ -178,7 +178,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
 		case 0xcc:  // unsigned int  8
 			more(2);
 			advance(2);
-			return (long)((short)buffer[offset+1] & 0xff);
+			return (long)((short)(buffer[offset-1]) & 0xff);
 		case 0xcd:  // unsigned int 16
 			more(3);
 			castBuffer.rewind();
@@ -207,7 +207,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
 		case 0xd0:  // signed int  8
 			more(2);
 			advance(2);
-			return (long)buffer[offset+1];
+			return (long)buffer[offset-1];
 		case 0xd1:  // signed int 16
 			more(3);
 			castBuffer.rewind();
-- 
cgit v1.2.1


From 2aef495d62d19b2f1721989225700942ea71e582 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Sat, 24 Jul 2010 18:08:00 +0900
Subject: java: adds MessagePackObject class

---
 .../main/java/org/msgpack/MessagePackObject.java   | 130 +++++++++++++++++++++
 .../main/java/org/msgpack/object/ArrayType.java    |  48 ++++++++
 .../org/msgpack/object/BigIntegerTypeIMPL.java     |  92 +++++++++++++++
 .../main/java/org/msgpack/object/BooleanType.java  |  39 +++++++
 .../java/org/msgpack/object/DoubleTypeIMPL.java    |  71 +++++++++++
 .../main/java/org/msgpack/object/FloatType.java    |  28 +++++
 .../java/org/msgpack/object/FloatTypeIMPL.java     |  70 +++++++++++
 .../main/java/org/msgpack/object/IntegerType.java  |  49 ++++++++
 .../org/msgpack/object/LongIntegerTypeIMPL.java    |  89 ++++++++++++++
 java/src/main/java/org/msgpack/object/MapType.java |  48 ++++++++
 java/src/main/java/org/msgpack/object/NilType.java |  28 +++++
 .../org/msgpack/object/ShortIntegerTypeIMPL.java   |  91 +++++++++++++++
 12 files changed, 783 insertions(+)
 create mode 100644 java/src/main/java/org/msgpack/MessagePackObject.java
 create mode 100644 java/src/main/java/org/msgpack/object/ArrayType.java
 create mode 100644 java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
 create mode 100644 java/src/main/java/org/msgpack/object/BooleanType.java
 create mode 100644 java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
 create mode 100644 java/src/main/java/org/msgpack/object/FloatType.java
 create mode 100644 java/src/main/java/org/msgpack/object/FloatTypeIMPL.java
 create mode 100644 java/src/main/java/org/msgpack/object/IntegerType.java
 create mode 100644 java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
 create mode 100644 java/src/main/java/org/msgpack/object/MapType.java
 create mode 100644 java/src/main/java/org/msgpack/object/NilType.java
 create mode 100644 java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/MessagePackObject.java b/java/src/main/java/org/msgpack/MessagePackObject.java
new file mode 100644
index 0000000..aba27e4
--- /dev/null
+++ b/java/src/main/java/org/msgpack/MessagePackObject.java
@@ -0,0 +1,130 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack;
+
+import java.util.List;
+import java.util.Set;
+import java.util.Map;
+import java.math.BigInteger;
+
+public abstract class MessagePackObject {
+	public boolean isNull() {
+		return false;
+	}
+
+	public boolean isBooleanType() {
+		return false;
+	}
+
+	public boolean isIntegerType() {
+		return false;
+	}
+
+	public boolean isFloatType() {
+		return false;
+	}
+
+	public boolean isArrayType() {
+		return false;
+	}
+
+	public boolean isMapType() {
+		return false;
+	}
+
+	public boolean isRawType() {
+		return false;
+	}
+
+	public boolean asBoolean() {
+		throw new MessageTypeException("type error");
+	}
+
+	public byte asByte() {
+		throw new MessageTypeException("type error");
+	}
+
+	public short asShort() {
+		throw new MessageTypeException("type error");
+	}
+
+	public int asInt() {
+		throw new MessageTypeException("type error");
+	}
+
+	public long asLong() {
+		throw new MessageTypeException("type error");
+	}
+
+	public BigInteger asBigInteger() {
+		throw new MessageTypeException("type error");
+	}
+
+	public float asFloat() {
+		throw new MessageTypeException("type error");
+	}
+
+	public double asDouble() {
+		throw new MessageTypeException("type error");
+	}
+
+	public byte[] asByteArray() {
+		throw new MessageTypeException("type error");
+	}
+
+	public String asString() {
+		throw new MessageTypeException("type error");
+	}
+
+	public MessagePackObject[] asArray() {
+		throw new MessageTypeException("type error");
+	}
+
+	public List asList() {
+		throw new MessageTypeException("type error");
+	}
+
+	public Map asMap() {
+		throw new MessageTypeException("type error");
+	}
+
+	public byte byteValue() {
+		throw new MessageTypeException("type error");
+	}
+
+	public short shortValue() {
+		throw new MessageTypeException("type error");
+	}
+
+	public int intValue() {
+		throw new MessageTypeException("type error");
+	}
+
+	public long longValue() {
+		throw new MessageTypeException("type error");
+	}
+
+	public float floatValue() {
+		throw new MessageTypeException("type error");
+	}
+
+	public double doubleValue() {
+		throw new MessageTypeException("type error");
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/object/ArrayType.java b/java/src/main/java/org/msgpack/object/ArrayType.java
new file mode 100644
index 0000000..06e9b16
--- /dev/null
+++ b/java/src/main/java/org/msgpack/object/ArrayType.java
@@ -0,0 +1,48 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.object;
+
+import java.util.List;
+import java.util.Set;
+import java.util.Map;
+import java.util.Arrays;
+import org.msgpack.*;
+
+public class ArrayType extends MessagePackObject {
+	private MessagePackObject[] array;
+
+	public ArrayType(MessagePackObject[] array) {
+		this.array = array;
+	}
+
+	@Override
+	public boolean isArrayType() {
+		return true;
+	}
+
+	@Override
+	public MessagePackObject[] asArray() {
+		return array;
+	}
+
+	@Override
+	public List asList() {
+		return Arrays.asList(array);
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
new file mode 100644
index 0000000..1d638c9
--- /dev/null
+++ b/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
@@ -0,0 +1,92 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.object;
+
+import java.math.BigInteger;
+import org.msgpack.*;
+
+class BigIntegerTypeIMPL extends IntegerType {
+	private BigInteger value;
+
+	BigIntegerTypeIMPL(BigInteger vlaue) {
+		this.value = value;
+	}
+
+	@Override
+	public byte asByte() {
+		if(value.compareTo(BigInteger.valueOf((long)Byte.MAX_VALUE)) > 0) {
+			throw new MessageTypeException("type error");
+		}
+		return value.byteValue();
+	}
+
+	@Override
+	public short asShort() {
+		if(value.compareTo(BigInteger.valueOf((long)Short.MAX_VALUE)) > 0) {
+			throw new MessageTypeException("type error");
+		}
+		return value.shortValue();
+	}
+
+	@Override
+	public int asInt() {
+		if(value.compareTo(BigInteger.valueOf((long)Integer.MAX_VALUE)) > 0) {
+			throw new MessageTypeException("type error");
+		}
+		return value.intValue();
+	}
+
+	@Override
+	public long asLong() {
+		if(value.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
+			throw new MessageTypeException("type error");
+		}
+		return value.longValue();
+	}
+
+	@Override
+	public byte byteValue() {
+		return value.byteValue();
+	}
+
+	@Override
+	public short shortValue() {
+		return value.shortValue();
+	}
+
+	@Override
+	public int intValue() {
+		return value.intValue();
+	}
+
+	@Override
+	public long longValue() {
+		return value.longValue();
+	}
+
+	@Override
+	public float floatValue() {
+		return value.floatValue();
+	}
+
+	@Override
+	public double doubleValue() {
+		return value.doubleValue();
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/object/BooleanType.java b/java/src/main/java/org/msgpack/object/BooleanType.java
new file mode 100644
index 0000000..c9e84b6
--- /dev/null
+++ b/java/src/main/java/org/msgpack/object/BooleanType.java
@@ -0,0 +1,39 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.object;
+
+import org.msgpack.*;
+
+public class BooleanType extends MessagePackObject {
+	private boolean value;
+
+	public BooleanType(boolean value) {
+		this.value = value;
+	}
+
+	@Override
+	public boolean isBooleanType() {
+		return false;
+	}
+
+	@Override
+	public boolean asBoolean() {
+		return value;
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java b/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
new file mode 100644
index 0000000..0e33d5b
--- /dev/null
+++ b/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
@@ -0,0 +1,71 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.object;
+
+import java.math.BigInteger;
+import org.msgpack.*;
+
+class DoubleTypeIMPL extends FloatType {
+	private double value;
+
+	public DoubleTypeIMPL(double vlaue) {
+		this.value = value;
+	}
+
+	@Override
+	public float asFloat() {
+		// FIXME check overflow, underflow?
+		return (float)value;
+	}
+
+	@Override
+	public double asDouble() {
+		return value;
+	}
+
+	@Override
+	public byte byteValue() {
+		return (byte)value;
+	}
+
+	@Override
+	public short shortValue() {
+		return (short)value;
+	}
+
+	@Override
+	public int intValue() {
+		return (int)value;
+	}
+
+	@Override
+	public long longValue() {
+		return (long)value;
+	}
+
+	@Override
+	public float floatValue() {
+		return (float)value;
+	}
+
+	@Override
+	public double doubleValue() {
+		return (double)value;
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/object/FloatType.java b/java/src/main/java/org/msgpack/object/FloatType.java
new file mode 100644
index 0000000..2782dda
--- /dev/null
+++ b/java/src/main/java/org/msgpack/object/FloatType.java
@@ -0,0 +1,28 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.object;
+
+import org.msgpack.*;
+
+public abstract class FloatType extends MessagePackObject {
+	@Override
+	public boolean isFloatType() {
+		return true;
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java b/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java
new file mode 100644
index 0000000..75a5070
--- /dev/null
+++ b/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java
@@ -0,0 +1,70 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.object;
+
+import java.math.BigInteger;
+import org.msgpack.*;
+
+class FloatTypeIMPL extends FloatType {
+	private float value;
+
+	public FloatTypeIMPL(float vlaue) {
+		this.value = value;
+	}
+
+	@Override
+	public float asFloat() {
+		return value;
+	}
+
+	@Override
+	public double asDouble() {
+		return (double)value;
+	}
+
+	@Override
+	public byte byteValue() {
+		return (byte)value;
+	}
+
+	@Override
+	public short shortValue() {
+		return (short)value;
+	}
+
+	@Override
+	public int intValue() {
+		return (int)value;
+	}
+
+	@Override
+	public long longValue() {
+		return (long)value;
+	}
+
+	@Override
+	public float floatValue() {
+		return (float)value;
+	}
+
+	@Override
+	public double doubleValue() {
+		return (double)value;
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/object/IntegerType.java b/java/src/main/java/org/msgpack/object/IntegerType.java
new file mode 100644
index 0000000..d6a9b54
--- /dev/null
+++ b/java/src/main/java/org/msgpack/object/IntegerType.java
@@ -0,0 +1,49 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.object;
+
+import java.math.BigInteger;
+import org.msgpack.*;
+
+public abstract class IntegerType extends MessagePackObject {
+	public static IntegerType create(byte value) {
+		return new ShortIntegerTypeIMPL((int)value);
+	}
+
+	public static IntegerType create(short value) {
+		return new ShortIntegerTypeIMPL((int)value);
+	}
+
+	public static IntegerType create(int value) {
+		return new ShortIntegerTypeIMPL(value);
+	}
+
+	public static IntegerType create(long value) {
+		return new LongIntegerTypeIMPL(value);
+	}
+
+	public static IntegerType create(BigInteger value) {
+		return new BigIntegerTypeIMPL(value);
+	}
+
+	@Override
+	public boolean isIntegerType() {
+		return true;
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
new file mode 100644
index 0000000..c914e91
--- /dev/null
+++ b/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
@@ -0,0 +1,89 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.object;
+
+import java.math.BigInteger;
+import org.msgpack.*;
+
+class LongIntegerTypeIMPL extends IntegerType {
+	private long value;
+
+	LongIntegerTypeIMPL(long value) {
+		this.value = value;
+	}
+
+	@Override
+	public byte asByte() {
+		if(value > (long)Byte.MAX_VALUE) {
+			throw new MessageTypeException("type error");
+		}
+		return (byte)value;
+	}
+
+	@Override
+	public short asShort() {
+		if(value > (long)Short.MAX_VALUE) {
+			throw new MessageTypeException("type error");
+		}
+		return (short)value;
+	}
+
+	@Override
+	public int asInt() {
+		if(value > (long)Integer.MAX_VALUE) {
+			throw new MessageTypeException("type error");
+		}
+		return (int)value;
+	}
+
+	@Override
+	public long asLong() {
+		return value;
+	}
+
+	@Override
+	public byte byteValue() {
+		return (byte)value;
+	}
+
+	@Override
+	public short shortValue() {
+		return (short)value;
+	}
+
+	@Override
+	public int intValue() {
+		return (int)value;
+	}
+
+	@Override
+	public long longValue() {
+		return (long)value;
+	}
+
+	@Override
+	public float floatValue() {
+		return (float)value;
+	}
+
+	@Override
+	public double doubleValue() {
+		return (double)value;
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/object/MapType.java b/java/src/main/java/org/msgpack/object/MapType.java
new file mode 100644
index 0000000..dbd145b
--- /dev/null
+++ b/java/src/main/java/org/msgpack/object/MapType.java
@@ -0,0 +1,48 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.object;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.msgpack.*;
+
+public class MapType extends MessagePackObject {
+	MessagePackObject[] map;
+
+	public MapType(MessagePackObject[] map) {
+		this.map = map;
+	}
+
+	@Override
+	public boolean isMapType() {
+		return false;
+	}
+
+	@Override
+	public Map asMap() {
+		HashMap m = new HashMap(map.length / 2);
+		int i = 0;
+		while(i < map.length) {
+			MessagePackObject k = map[i++];
+			MessagePackObject v = map[i++];
+			m.put(k, v);
+		}
+		return m;
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/object/NilType.java b/java/src/main/java/org/msgpack/object/NilType.java
new file mode 100644
index 0000000..c36ff05
--- /dev/null
+++ b/java/src/main/java/org/msgpack/object/NilType.java
@@ -0,0 +1,28 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.object;
+
+import org.msgpack.*;
+
+public class NilType extends MessagePackObject {
+	@Override
+	public boolean isNull() {
+		return true;
+	}
+}
+
diff --git a/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java
new file mode 100644
index 0000000..a725950
--- /dev/null
+++ b/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java
@@ -0,0 +1,91 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.object;
+
+import java.math.BigInteger;
+import org.msgpack.*;
+
+class ShortIntegerTypeIMPL extends IntegerType {
+	private int value;
+
+	ShortIntegerTypeIMPL(int value) {
+		this.value = value;
+	}
+
+	@Override
+	public byte asByte() {
+		if(value > (int)Byte.MAX_VALUE) {
+			throw new MessageTypeException("type error");
+		}
+		return (byte)value;
+	}
+
+	@Override
+	public short asShort() {
+		if(value > (int)Short.MAX_VALUE) {
+			throw new MessageTypeException("type error");
+		}
+		return (short)value;
+	}
+
+	@Override
+	public int asInt() {
+		return value;
+	}
+
+	@Override
+	public long asLong() {
+		return value;
+	}
+
+	@Override
+	public BigInteger asBigInteger() {
+		return BigInteger.valueOf((long)value);
+	}
+
+	@Override
+	public byte byteValue() {
+		return (byte)value;
+	}
+
+	@Override
+	public short shortValue() {
+		return (short)value;
+	}
+
+	@Override
+	public int intValue() {
+		return (int)value;
+	}
+
+	@Override
+	public long longValue() {
+		return (long)value;
+	}
+
+	@Override
+	public float floatValue() {
+		return (float)value;
+	}
+
+	@Override
+	public double doubleValue() {
+		return (double)value;
+	}
+}
+
-- 
cgit v1.2.1


From 02ae247536ec5570c3a150de8283ef399aaf82eb Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Sat, 24 Jul 2010 18:20:00 +0900
Subject: java: adds MessagePackObject class 2

---
 .../org/msgpack/object/BigIntegerTypeIMPL.java     |  2 +-
 .../main/java/org/msgpack/object/BooleanType.java  |  2 +-
 .../java/org/msgpack/object/DoubleTypeIMPL.java    |  2 +-
 .../main/java/org/msgpack/object/FloatType.java    |  8 ++++
 .../java/org/msgpack/object/FloatTypeIMPL.java     |  2 +-
 .../main/java/org/msgpack/object/IntegerType.java  | 10 ++---
 java/src/main/java/org/msgpack/object/MapType.java |  4 +-
 java/src/main/java/org/msgpack/object/RawType.java | 48 ++++++++++++++++++++++
 8 files changed, 67 insertions(+), 11 deletions(-)
 create mode 100644 java/src/main/java/org/msgpack/object/RawType.java

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
index 1d638c9..1ebb83d 100644
--- a/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
@@ -23,7 +23,7 @@ import org.msgpack.*;
 class BigIntegerTypeIMPL extends IntegerType {
 	private BigInteger value;
 
-	BigIntegerTypeIMPL(BigInteger vlaue) {
+	BigIntegerTypeIMPL(BigInteger value) {
 		this.value = value;
 	}
 
diff --git a/java/src/main/java/org/msgpack/object/BooleanType.java b/java/src/main/java/org/msgpack/object/BooleanType.java
index c9e84b6..d272b6f 100644
--- a/java/src/main/java/org/msgpack/object/BooleanType.java
+++ b/java/src/main/java/org/msgpack/object/BooleanType.java
@@ -28,7 +28,7 @@ public class BooleanType extends MessagePackObject {
 
 	@Override
 	public boolean isBooleanType() {
-		return false;
+		return true;
 	}
 
 	@Override
diff --git a/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java b/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
index 0e33d5b..8bbc52a 100644
--- a/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
@@ -23,7 +23,7 @@ import org.msgpack.*;
 class DoubleTypeIMPL extends FloatType {
 	private double value;
 
-	public DoubleTypeIMPL(double vlaue) {
+	public DoubleTypeIMPL(double value) {
 		this.value = value;
 	}
 
diff --git a/java/src/main/java/org/msgpack/object/FloatType.java b/java/src/main/java/org/msgpack/object/FloatType.java
index 2782dda..514efd5 100644
--- a/java/src/main/java/org/msgpack/object/FloatType.java
+++ b/java/src/main/java/org/msgpack/object/FloatType.java
@@ -24,5 +24,13 @@ public abstract class FloatType extends MessagePackObject {
 	public boolean isFloatType() {
 		return true;
 	}
+
+	public static FloatType create(float value) {
+		return new FloatTypeIMPL(value);
+	}
+
+	public static FloatType create(double value) {
+		return new DoubleTypeIMPL(value);
+	}
 }
 
diff --git a/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java b/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java
index 75a5070..8821640 100644
--- a/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java
@@ -23,7 +23,7 @@ import org.msgpack.*;
 class FloatTypeIMPL extends FloatType {
 	private float value;
 
-	public FloatTypeIMPL(float vlaue) {
+	public FloatTypeIMPL(float value) {
 		this.value = value;
 	}
 
diff --git a/java/src/main/java/org/msgpack/object/IntegerType.java b/java/src/main/java/org/msgpack/object/IntegerType.java
index d6a9b54..43357e8 100644
--- a/java/src/main/java/org/msgpack/object/IntegerType.java
+++ b/java/src/main/java/org/msgpack/object/IntegerType.java
@@ -21,6 +21,11 @@ import java.math.BigInteger;
 import org.msgpack.*;
 
 public abstract class IntegerType extends MessagePackObject {
+	@Override
+	public boolean isIntegerType() {
+		return true;
+	}
+
 	public static IntegerType create(byte value) {
 		return new ShortIntegerTypeIMPL((int)value);
 	}
@@ -40,10 +45,5 @@ public abstract class IntegerType extends MessagePackObject {
 	public static IntegerType create(BigInteger value) {
 		return new BigIntegerTypeIMPL(value);
 	}
-
-	@Override
-	public boolean isIntegerType() {
-		return true;
-	}
 }
 
diff --git a/java/src/main/java/org/msgpack/object/MapType.java b/java/src/main/java/org/msgpack/object/MapType.java
index dbd145b..359ebe6 100644
--- a/java/src/main/java/org/msgpack/object/MapType.java
+++ b/java/src/main/java/org/msgpack/object/MapType.java
@@ -22,7 +22,7 @@ import java.util.Map;
 import org.msgpack.*;
 
 public class MapType extends MessagePackObject {
-	MessagePackObject[] map;
+	private MessagePackObject[] map;
 
 	public MapType(MessagePackObject[] map) {
 		this.map = map;
@@ -30,7 +30,7 @@ public class MapType extends MessagePackObject {
 
 	@Override
 	public boolean isMapType() {
-		return false;
+		return true;
 	}
 
 	@Override
diff --git a/java/src/main/java/org/msgpack/object/RawType.java b/java/src/main/java/org/msgpack/object/RawType.java
new file mode 100644
index 0000000..107ba27
--- /dev/null
+++ b/java/src/main/java/org/msgpack/object/RawType.java
@@ -0,0 +1,48 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+//    Licensed under the Apache License, Version 2.0 (the "License");
+//    you may not use this file except in compliance with the License.
+//    You may obtain a copy of the License at
+//
+//        http://www.apache.org/licenses/LICENSE-2.0
+//
+//    Unless required by applicable law or agreed to in writing, software
+//    distributed under the License is distributed on an "AS IS" BASIS,
+//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//    See the License for the specific language governing permissions and
+//    limitations under the License.
+//
+package org.msgpack.object;
+
+import org.msgpack.*;
+
+class RawType extends MessagePackObject {
+	private byte[] bytes;
+
+	public RawType(byte[] bytes) {
+		this.bytes = bytes;
+	}
+
+	@Override
+	public boolean isRawType() {
+		return true;
+	}
+
+	@Override
+	public byte[] asByteArray() {
+		return bytes;
+	}
+
+	@Override
+	public String asString() {
+		try {
+			return new String(bytes, "UTF-8");
+		} catch (Exception e) {
+			throw new MessageTypeException("type error");
+		}
+	}
+}
+
-- 
cgit v1.2.1


From cd83388f8b035102f260f2ab45a551233dd593da Mon Sep 17 00:00:00 2001
From: Kazuki Ohta 
Date: Tue, 27 Jul 2010 08:59:09 +0900
Subject: java: fixed repository location. msgpack.sourceforge.net =>
 msgpack.org

---
 java/pom.xml | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

(limited to 'java')

diff --git a/java/pom.xml b/java/pom.xml
index 9b74b4c..959d2df 100755
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -7,7 +7,7 @@
   MessagePack for Java
 
   MessagePack for Java
-  http://msgpack.sourceforge.net/
+  http://msgpack.org/
 
   
     
@@ -97,29 +97,26 @@
 
   
     
-      msgpack.sourceforge.net
+      msgpack.org
       MessagePack Maven2 Repository
-      http://msgpack.sourceforge.net/maven2
-    
-    
-      msgpack.sourceforge.net
-      MessagePack Maven2 Snapshot Repository
-      http://msgpack.sourceforge.net/maven2-snapshot
+      http://msgpack.org/maven2
     
   
 
   
     
       false
-      shell.sourceforge.net
-      Repository at sourceforge.net
-      scp://shell.sourceforge.net/home/groups/m/ms/msgpack/htdocs/maven2/
+      msgpack.org
+      Repository at msgpack.org
+       
+      file:///Users/otakazuki/soft/website/maven2/
     
     
        true
-       shell.sourceforge.net
-       Repository Name
-       scp://shell.sourceforge.net/home/groups/m/ms/msgpack/htdocs/maven2-snapshot/
+       msgpack.org
+       Repository at msgpack.org
+       
+       file:///Users/otakazuki/soft/website/maven2/
     
   
 
-- 
cgit v1.2.1


From cba47b635a5a3bab2050fb4e0d099c23f8455867 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Tue, 27 Jul 2010 09:50:57 +0900
Subject: java: changed deploy path to ./target/website/maven2 directory.

---
 java/pom.xml | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

(limited to 'java')

diff --git a/java/pom.xml b/java/pom.xml
index 959d2df..44806d5 100755
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -108,15 +108,13 @@
       false
       msgpack.org
       Repository at msgpack.org
-       
-      file:///Users/otakazuki/soft/website/maven2/
+	  file://${project.build.directory}/website/maven2/
     
     
        true
        msgpack.org
        Repository at msgpack.org
-       
-       file:///Users/otakazuki/soft/website/maven2/
+	   file://${project.build.directory}/website/maven2/
     
   
 
-- 
cgit v1.2.1


From 6c91b862c9da56ce0914d430fea2cb388e32d5d5 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Wed, 28 Jul 2010 01:17:20 +0900
Subject: java: MessagePackObject implements Cloneable and MessagePackable
 interfaces

---
 .../main/java/org/msgpack/MessagePackObject.java   |  4 +++-
 java/src/main/java/org/msgpack/Packer.java         | 22 +++++++++++++++++
 .../main/java/org/msgpack/object/ArrayType.java    | 28 ++++++++++++++++++++--
 .../org/msgpack/object/BigIntegerTypeIMPL.java     | 19 +++++++++++++++
 .../main/java/org/msgpack/object/BooleanType.java  | 19 +++++++++++++++
 .../java/org/msgpack/object/DoubleTypeIMPL.java    | 19 +++++++++++++++
 .../java/org/msgpack/object/FloatTypeIMPL.java     | 19 +++++++++++++++
 .../org/msgpack/object/LongIntegerTypeIMPL.java    | 19 +++++++++++++++
 java/src/main/java/org/msgpack/object/MapType.java | 27 +++++++++++++++++++++
 java/src/main/java/org/msgpack/object/NilType.java | 19 +++++++++++++++
 java/src/main/java/org/msgpack/object/RawType.java | 23 +++++++++++++++++-
 .../org/msgpack/object/ShortIntegerTypeIMPL.java   | 19 +++++++++++++++
 12 files changed, 233 insertions(+), 4 deletions(-)

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/MessagePackObject.java b/java/src/main/java/org/msgpack/MessagePackObject.java
index aba27e4..b1a6fab 100644
--- a/java/src/main/java/org/msgpack/MessagePackObject.java
+++ b/java/src/main/java/org/msgpack/MessagePackObject.java
@@ -22,7 +22,7 @@ import java.util.Set;
 import java.util.Map;
 import java.math.BigInteger;
 
-public abstract class MessagePackObject {
+public abstract class MessagePackObject implements Cloneable, MessagePackable {
 	public boolean isNull() {
 		return false;
 	}
@@ -126,5 +126,7 @@ public abstract class MessagePackObject {
 	public double doubleValue() {
 		throw new MessageTypeException("type error");
 	}
+
+	abstract public Object clone();
 }
 
diff --git a/java/src/main/java/org/msgpack/Packer.java b/java/src/main/java/org/msgpack/Packer.java
index dd510f3..fbf7e35 100644
--- a/java/src/main/java/org/msgpack/Packer.java
+++ b/java/src/main/java/org/msgpack/Packer.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.List;
 import java.util.Map;
+import java.math.BigInteger;
 
 /**
  * Packer enables you to serialize objects into OutputStream.
@@ -194,6 +195,27 @@ public class Packer {
 		return this;
 	}
 
+	public Packer packBigInteger(BigInteger d) throws IOException {
+		if(d.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) <= 0) {
+			return packLong(d.longValue());
+		} else if(d.bitLength() <= 64) {
+			castBytes[0] = (byte)0xcf;
+			byte[] barray = d.toByteArray();
+			castBytes[1] = barray[0];
+			castBytes[2] = barray[1];
+			castBytes[3] = barray[2];
+			castBytes[4] = barray[3];
+			castBytes[5] = barray[4];
+			castBytes[6] = barray[5];
+			castBytes[7] = barray[6];
+			castBytes[8] = barray[7];
+			out.write(castBytes);
+			return this;
+		} else {
+			throw new MessageTypeException("can't BigInteger larger than 0xffffffffffffffff");
+		}
+	}
+
 	public Packer packFloat(float d) throws IOException {
 		castBytes[0] = (byte)0xca;
 		castBuffer.putFloat(1, d);
diff --git a/java/src/main/java/org/msgpack/object/ArrayType.java b/java/src/main/java/org/msgpack/object/ArrayType.java
index 06e9b16..694f53f 100644
--- a/java/src/main/java/org/msgpack/object/ArrayType.java
+++ b/java/src/main/java/org/msgpack/object/ArrayType.java
@@ -18,9 +18,8 @@
 package org.msgpack.object;
 
 import java.util.List;
-import java.util.Set;
-import java.util.Map;
 import java.util.Arrays;
+import java.io.IOException;
 import org.msgpack.*;
 
 public class ArrayType extends MessagePackObject {
@@ -44,5 +43,30 @@ public class ArrayType extends MessagePackObject {
 	public List asList() {
 		return Arrays.asList(array);
 	}
+
+	@Override
+	public void messagePack(Packer pk) throws IOException {
+		pk.packArray(array.length);
+		for(int i=0; i < array.length; i++) {
+			array[i].messagePack(pk);
+		}
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if(obj.getClass() != getClass()) {
+			return false;
+		}
+		return Arrays.equals(((ArrayType)obj).array, array);
+	}
+
+	@Override
+	public Object clone() {
+		MessagePackObject[] copy = new MessagePackObject[array.length];
+		for(int i=0; i < array.length; i++) {
+			copy[i] = (MessagePackObject)array[i].clone();
+		}
+		return copy;
+	}
 }
 
diff --git a/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
index 1ebb83d..f7c73ae 100644
--- a/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
@@ -18,6 +18,7 @@
 package org.msgpack.object;
 
 import java.math.BigInteger;
+import java.io.IOException;
 import org.msgpack.*;
 
 class BigIntegerTypeIMPL extends IntegerType {
@@ -88,5 +89,23 @@ class BigIntegerTypeIMPL extends IntegerType {
 	public double doubleValue() {
 		return value.doubleValue();
 	}
+
+	@Override
+	public void messagePack(Packer pk) throws IOException {
+		pk.packBigInteger(value);
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if(obj.getClass() != getClass()) {
+			return false;
+		}
+		return ((BigIntegerTypeIMPL)obj).value.equals(value);
+	}
+
+	@Override
+	public Object clone() {
+		return new BigIntegerTypeIMPL(value);
+	}
 }
 
diff --git a/java/src/main/java/org/msgpack/object/BooleanType.java b/java/src/main/java/org/msgpack/object/BooleanType.java
index d272b6f..c6e4f30 100644
--- a/java/src/main/java/org/msgpack/object/BooleanType.java
+++ b/java/src/main/java/org/msgpack/object/BooleanType.java
@@ -17,6 +17,7 @@
 //
 package org.msgpack.object;
 
+import java.io.IOException;
 import org.msgpack.*;
 
 public class BooleanType extends MessagePackObject {
@@ -35,5 +36,23 @@ public class BooleanType extends MessagePackObject {
 	public boolean asBoolean() {
 		return value;
 	}
+
+	@Override
+	public void messagePack(Packer pk) throws IOException {
+		pk.packBoolean(value);
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if(obj.getClass() != getClass()) {
+			return false;
+		}
+		return ((BooleanType)obj).value == value;
+	}
+
+	@Override
+	public Object clone() {
+		return new BooleanType(value);
+	}
 }
 
diff --git a/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java b/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
index 8bbc52a..dafe540 100644
--- a/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
@@ -18,6 +18,7 @@
 package org.msgpack.object;
 
 import java.math.BigInteger;
+import java.io.IOException;
 import org.msgpack.*;
 
 class DoubleTypeIMPL extends FloatType {
@@ -67,5 +68,23 @@ class DoubleTypeIMPL extends FloatType {
 	public double doubleValue() {
 		return (double)value;
 	}
+
+	@Override
+	public void messagePack(Packer pk) throws IOException {
+		pk.packDouble(value);
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if(obj.getClass() != getClass()) {
+			return false;
+		}
+		return ((DoubleTypeIMPL)obj).value == value;
+	}
+
+	@Override
+	public Object clone() {
+		return new DoubleTypeIMPL(value);
+	}
 }
 
diff --git a/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java b/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java
index 8821640..234b2ad 100644
--- a/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java
@@ -18,6 +18,7 @@
 package org.msgpack.object;
 
 import java.math.BigInteger;
+import java.io.IOException;
 import org.msgpack.*;
 
 class FloatTypeIMPL extends FloatType {
@@ -66,5 +67,23 @@ class FloatTypeIMPL extends FloatType {
 	public double doubleValue() {
 		return (double)value;
 	}
+
+	@Override
+	public void messagePack(Packer pk) throws IOException {
+		pk.packFloat(value);
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if(obj.getClass() != getClass()) {
+			return false;
+		}
+		return ((FloatTypeIMPL)obj).value == value;
+	}
+
+	@Override
+	public Object clone() {
+		return new FloatTypeIMPL(value);
+	}
 }
 
diff --git a/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
index c914e91..0ce22a2 100644
--- a/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
@@ -18,6 +18,7 @@
 package org.msgpack.object;
 
 import java.math.BigInteger;
+import java.io.IOException;
 import org.msgpack.*;
 
 class LongIntegerTypeIMPL extends IntegerType {
@@ -85,5 +86,23 @@ class LongIntegerTypeIMPL extends IntegerType {
 	public double doubleValue() {
 		return (double)value;
 	}
+
+	@Override
+	public void messagePack(Packer pk) throws IOException {
+		pk.packLong(value);
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if(obj.getClass() != getClass()) {
+			return false;
+		}
+		return ((LongIntegerTypeIMPL)obj).value == value;
+	}
+
+	@Override
+	public Object clone() {
+		return new LongIntegerTypeIMPL(value);
+	}
 }
 
diff --git a/java/src/main/java/org/msgpack/object/MapType.java b/java/src/main/java/org/msgpack/object/MapType.java
index 359ebe6..d456e78 100644
--- a/java/src/main/java/org/msgpack/object/MapType.java
+++ b/java/src/main/java/org/msgpack/object/MapType.java
@@ -19,6 +19,8 @@ package org.msgpack.object;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Arrays;
+import java.io.IOException;
 import org.msgpack.*;
 
 public class MapType extends MessagePackObject {
@@ -44,5 +46,30 @@ public class MapType extends MessagePackObject {
 		}
 		return m;
 	}
+
+	@Override
+	public void messagePack(Packer pk) throws IOException {
+		pk.packMap(map.length / 2);
+		for(int i=0; i < map.length; i++) {
+			map[i].messagePack(pk);
+		}
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if(obj.getClass() != getClass()) {
+			return false;
+		}
+		return Arrays.equals(((MapType)obj).map, map);
+	}
+
+	@Override
+	public Object clone() {
+		MessagePackObject[] copy = new MessagePackObject[map.length];
+		for(int i=0; i < map.length; i++) {
+			copy[i] = (MessagePackObject)map[i].clone();
+		}
+		return copy;
+	}
 }
 
diff --git a/java/src/main/java/org/msgpack/object/NilType.java b/java/src/main/java/org/msgpack/object/NilType.java
index c36ff05..7a46376 100644
--- a/java/src/main/java/org/msgpack/object/NilType.java
+++ b/java/src/main/java/org/msgpack/object/NilType.java
@@ -17,6 +17,7 @@
 //
 package org.msgpack.object;
 
+import java.io.IOException;
 import org.msgpack.*;
 
 public class NilType extends MessagePackObject {
@@ -24,5 +25,23 @@ public class NilType extends MessagePackObject {
 	public boolean isNull() {
 		return true;
 	}
+
+	@Override
+	public void messagePack(Packer pk) throws IOException {
+		pk.packNil();
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if(obj.getClass() != getClass()) {
+			return false;
+		}
+		return true;
+	}
+
+	@Override
+	public Object clone() {
+		return new NilType();
+	}
 }
 
diff --git a/java/src/main/java/org/msgpack/object/RawType.java b/java/src/main/java/org/msgpack/object/RawType.java
index 107ba27..18a419d 100644
--- a/java/src/main/java/org/msgpack/object/RawType.java
+++ b/java/src/main/java/org/msgpack/object/RawType.java
@@ -17,9 +17,11 @@
 //
 package org.msgpack.object;
 
+import java.util.Arrays;
+import java.io.IOException;
 import org.msgpack.*;
 
-class RawType extends MessagePackObject {
+public class RawType extends MessagePackObject {
 	private byte[] bytes;
 
 	public RawType(byte[] bytes) {
@@ -44,5 +46,24 @@ class RawType extends MessagePackObject {
 			throw new MessageTypeException("type error");
 		}
 	}
+
+	@Override
+	public void messagePack(Packer pk) throws IOException {
+		pk.packRaw(bytes.length);
+		pk.packRawBody(bytes);
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if(obj.getClass() != getClass()) {
+			return false;
+		}
+		return ((RawType)obj).bytes.equals(bytes);
+	}
+
+	@Override
+	public Object clone() {
+		return new RawType((byte[])bytes.clone());
+	}
 }
 
diff --git a/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java
index a725950..83a4daf 100644
--- a/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java
@@ -18,6 +18,7 @@
 package org.msgpack.object;
 
 import java.math.BigInteger;
+import java.io.IOException;
 import org.msgpack.*;
 
 class ShortIntegerTypeIMPL extends IntegerType {
@@ -87,5 +88,23 @@ class ShortIntegerTypeIMPL extends IntegerType {
 	public double doubleValue() {
 		return (double)value;
 	}
+
+	@Override
+	public void messagePack(Packer pk) throws IOException {
+		pk.packInt(value);
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if(obj.getClass() != getClass()) {
+			return false;
+		}
+		return ((ShortIntegerTypeIMPL)obj).value == value;
+	}
+
+	@Override
+	public Object clone() {
+		return new ShortIntegerTypeIMPL(value);
+	}
 }
 
-- 
cgit v1.2.1


From d3bb37d113575e8b36f44c06ac9eeb6b406aa298 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Tue, 10 Aug 2010 14:11:25 +0900
Subject: java: fixes MapSchema

---
 java/src/main/java/org/msgpack/schema/MapSchema.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/schema/MapSchema.java b/java/src/main/java/org/msgpack/schema/MapSchema.java
index 339a5c2..2e09af3 100644
--- a/java/src/main/java/org/msgpack/schema/MapSchema.java
+++ b/java/src/main/java/org/msgpack/schema/MapSchema.java
@@ -72,7 +72,7 @@ public class MapSchema extends Schema implements IMapSchema {
 			dest.put((K)keySchema.convert(e.getKey()),
 					(V)valueSchema.convert(e.getValue()));
 		}
-		return (Map)d;
+		return dest;
 	}
 
 	@Override
-- 
cgit v1.2.1


From 057f73a73e0c3ddabe92f1cd2c394fe4afa13514 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Tue, 10 Aug 2010 14:11:44 +0900
Subject: java: implements MessagePackObject::hashCode()

---
 java/src/main/java/org/msgpack/object/ArrayType.java            | 5 +++++
 java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java   | 5 +++++
 java/src/main/java/org/msgpack/object/BooleanType.java          | 9 +++++++++
 java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java       | 6 ++++++
 java/src/main/java/org/msgpack/object/FloatTypeIMPL.java        | 5 +++++
 java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java  | 5 +++++
 java/src/main/java/org/msgpack/object/MapType.java              | 5 +++++
 java/src/main/java/org/msgpack/object/NilType.java              | 5 +++++
 java/src/main/java/org/msgpack/object/RawType.java              | 5 +++++
 java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java | 5 +++++
 10 files changed, 55 insertions(+)

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/object/ArrayType.java b/java/src/main/java/org/msgpack/object/ArrayType.java
index 694f53f..350ce32 100644
--- a/java/src/main/java/org/msgpack/object/ArrayType.java
+++ b/java/src/main/java/org/msgpack/object/ArrayType.java
@@ -60,6 +60,11 @@ public class ArrayType extends MessagePackObject {
 		return Arrays.equals(((ArrayType)obj).array, array);
 	}
 
+	@Override
+	public int hashCode() {
+		return array.hashCode();
+	}
+
 	@Override
 	public Object clone() {
 		MessagePackObject[] copy = new MessagePackObject[array.length];
diff --git a/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
index f7c73ae..fd517e7 100644
--- a/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
@@ -103,6 +103,11 @@ class BigIntegerTypeIMPL extends IntegerType {
 		return ((BigIntegerTypeIMPL)obj).value.equals(value);
 	}
 
+	@Override
+	public int hashCode() {
+		return value.hashCode();
+	}
+
 	@Override
 	public Object clone() {
 		return new BigIntegerTypeIMPL(value);
diff --git a/java/src/main/java/org/msgpack/object/BooleanType.java b/java/src/main/java/org/msgpack/object/BooleanType.java
index c6e4f30..1d12c1c 100644
--- a/java/src/main/java/org/msgpack/object/BooleanType.java
+++ b/java/src/main/java/org/msgpack/object/BooleanType.java
@@ -50,6 +50,15 @@ public class BooleanType extends MessagePackObject {
 		return ((BooleanType)obj).value == value;
 	}
 
+	@Override
+	public int hashCode() {
+		if(value) {
+			return 1231;
+		} else {
+			return 1237;
+		}
+	}
+
 	@Override
 	public Object clone() {
 		return new BooleanType(value);
diff --git a/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java b/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
index dafe540..b47a709 100644
--- a/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
@@ -82,6 +82,12 @@ class DoubleTypeIMPL extends FloatType {
 		return ((DoubleTypeIMPL)obj).value == value;
 	}
 
+	@Override
+	public int hashCode() {
+		long v = Double.doubleToLongBits(value);
+		return (int)(v^(v>>>32));
+	}
+
 	@Override
 	public Object clone() {
 		return new DoubleTypeIMPL(value);
diff --git a/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java b/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java
index 234b2ad..1d79961 100644
--- a/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/FloatTypeIMPL.java
@@ -81,6 +81,11 @@ class FloatTypeIMPL extends FloatType {
 		return ((FloatTypeIMPL)obj).value == value;
 	}
 
+	@Override
+	public int hashCode() {
+		return Float.floatToIntBits(value);
+	}
+
 	@Override
 	public Object clone() {
 		return new FloatTypeIMPL(value);
diff --git a/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
index 0ce22a2..940ab6f 100644
--- a/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
@@ -100,6 +100,11 @@ class LongIntegerTypeIMPL extends IntegerType {
 		return ((LongIntegerTypeIMPL)obj).value == value;
 	}
 
+	@Override
+	public int hashCode() {
+		return (int)(value^(value>>>32));
+	}
+
 	@Override
 	public Object clone() {
 		return new LongIntegerTypeIMPL(value);
diff --git a/java/src/main/java/org/msgpack/object/MapType.java b/java/src/main/java/org/msgpack/object/MapType.java
index d456e78..619d388 100644
--- a/java/src/main/java/org/msgpack/object/MapType.java
+++ b/java/src/main/java/org/msgpack/object/MapType.java
@@ -63,6 +63,11 @@ public class MapType extends MessagePackObject {
 		return Arrays.equals(((MapType)obj).map, map);
 	}
 
+	@Override
+	public int hashCode() {
+		return map.hashCode();
+	}
+
 	@Override
 	public Object clone() {
 		MessagePackObject[] copy = new MessagePackObject[map.length];
diff --git a/java/src/main/java/org/msgpack/object/NilType.java b/java/src/main/java/org/msgpack/object/NilType.java
index 7a46376..ece62f0 100644
--- a/java/src/main/java/org/msgpack/object/NilType.java
+++ b/java/src/main/java/org/msgpack/object/NilType.java
@@ -39,6 +39,11 @@ public class NilType extends MessagePackObject {
 		return true;
 	}
 
+	@Override
+	public int hashCode() {
+		return 0;
+	}
+
 	@Override
 	public Object clone() {
 		return new NilType();
diff --git a/java/src/main/java/org/msgpack/object/RawType.java b/java/src/main/java/org/msgpack/object/RawType.java
index 18a419d..3a39486 100644
--- a/java/src/main/java/org/msgpack/object/RawType.java
+++ b/java/src/main/java/org/msgpack/object/RawType.java
@@ -61,6 +61,11 @@ public class RawType extends MessagePackObject {
 		return ((RawType)obj).bytes.equals(bytes);
 	}
 
+	@Override
+	public int hashCode() {
+		return bytes.hashCode();
+	}
+
 	@Override
 	public Object clone() {
 		return new RawType((byte[])bytes.clone());
diff --git a/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java
index 83a4daf..60e92b8 100644
--- a/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java
@@ -102,6 +102,11 @@ class ShortIntegerTypeIMPL extends IntegerType {
 		return ((ShortIntegerTypeIMPL)obj).value == value;
 	}
 
+	@Override
+	public int hashCode() {
+		return value;
+	}
+
 	@Override
 	public Object clone() {
 		return new ShortIntegerTypeIMPL(value);
-- 
cgit v1.2.1


From 8c67087a154da0e7cdc32c0b676d2956ce1d0f47 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Wed, 18 Aug 2010 16:32:42 +0900
Subject: java: adds MessagePackObject.bigIntegerValue(), asBigInteger() and
 equals()

---
 java/src/main/java/org/msgpack/MessagePackObject.java     |  4 ++++
 .../main/java/org/msgpack/object/BigIntegerTypeIMPL.java  | 15 +++++++++++++++
 java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java |  5 +++++
 .../main/java/org/msgpack/object/LongIntegerTypeIMPL.java | 15 +++++++++++++++
 .../java/org/msgpack/object/ShortIntegerTypeIMPL.java     | 10 ++++++++++
 5 files changed, 49 insertions(+)

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/MessagePackObject.java b/java/src/main/java/org/msgpack/MessagePackObject.java
index b1a6fab..6181f7a 100644
--- a/java/src/main/java/org/msgpack/MessagePackObject.java
+++ b/java/src/main/java/org/msgpack/MessagePackObject.java
@@ -119,6 +119,10 @@ public abstract class MessagePackObject implements Cloneable, MessagePackable {
 		throw new MessageTypeException("type error");
 	}
 
+	public BigInteger bigIntegerValue() {
+		throw new MessageTypeException("type error");
+	}
+
 	public float floatValue() {
 		throw new MessageTypeException("type error");
 	}
diff --git a/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
index fd517e7..7b060ee 100644
--- a/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
@@ -60,6 +60,11 @@ class BigIntegerTypeIMPL extends IntegerType {
 		return value.longValue();
 	}
 
+	@Override
+	public BigInteger asBigInteger() {
+		return value;
+	}
+
 	@Override
 	public byte byteValue() {
 		return value.byteValue();
@@ -80,6 +85,11 @@ class BigIntegerTypeIMPL extends IntegerType {
 		return value.longValue();
 	}
 
+	@Override
+	public BigInteger bigIntegerValue() {
+		return value;
+	}
+
 	@Override
 	public float floatValue() {
 		return value.floatValue();
@@ -98,6 +108,11 @@ class BigIntegerTypeIMPL extends IntegerType {
 	@Override
 	public boolean equals(Object obj) {
 		if(obj.getClass() != getClass()) {
+			if(obj.getClass() == ShortIntegerTypeIMPL.class) {
+				return BigInteger.valueOf((long)((ShortIntegerTypeIMPL)obj).shortValue()).equals(value);
+			} else if(obj.getClass() == LongIntegerTypeIMPL.class) {
+				return BigInteger.valueOf(((LongIntegerTypeIMPL)obj).longValue()).equals(value);
+			}
 			return false;
 		}
 		return ((BigIntegerTypeIMPL)obj).value.equals(value);
diff --git a/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java b/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
index b47a709..fd38089 100644
--- a/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/DoubleTypeIMPL.java
@@ -59,6 +59,11 @@ class DoubleTypeIMPL extends FloatType {
 		return (long)value;
 	}
 
+	@Override
+	public BigInteger bigIntegerValue() {
+		return BigInteger.valueOf((long)value);
+	}
+
 	@Override
 	public float floatValue() {
 		return (float)value;
diff --git a/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
index 940ab6f..3928a29 100644
--- a/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
@@ -57,6 +57,11 @@ class LongIntegerTypeIMPL extends IntegerType {
 		return value;
 	}
 
+	@Override
+	public BigInteger asBigInteger() {
+		return BigInteger.valueOf(value);
+	}
+
 	@Override
 	public byte byteValue() {
 		return (byte)value;
@@ -77,6 +82,11 @@ class LongIntegerTypeIMPL extends IntegerType {
 		return (long)value;
 	}
 
+	@Override
+	public BigInteger bigIntegerValue() {
+		return BigInteger.valueOf(value);
+	}
+
 	@Override
 	public float floatValue() {
 		return (float)value;
@@ -95,6 +105,11 @@ class LongIntegerTypeIMPL extends IntegerType {
 	@Override
 	public boolean equals(Object obj) {
 		if(obj.getClass() != getClass()) {
+			if(obj.getClass() == ShortIntegerTypeIMPL.class) {
+				return value == ((ShortIntegerTypeIMPL)obj).longValue();
+			} else if(obj.getClass() == BigIntegerTypeIMPL.class) {
+				return (long)value == ((BigIntegerTypeIMPL)obj).longValue();
+			}
 			return false;
 		}
 		return ((LongIntegerTypeIMPL)obj).value == value;
diff --git a/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java
index 60e92b8..dbed426 100644
--- a/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/ShortIntegerTypeIMPL.java
@@ -79,6 +79,11 @@ class ShortIntegerTypeIMPL extends IntegerType {
 		return (long)value;
 	}
 
+	@Override
+	public BigInteger bigIntegerValue() {
+		return BigInteger.valueOf((long)value);
+	}
+
 	@Override
 	public float floatValue() {
 		return (float)value;
@@ -97,6 +102,11 @@ class ShortIntegerTypeIMPL extends IntegerType {
 	@Override
 	public boolean equals(Object obj) {
 		if(obj.getClass() != getClass()) {
+			if(obj.getClass() == LongIntegerTypeIMPL.class) {
+				return (long)value == ((LongIntegerTypeIMPL)obj).longValue();
+			} else if(obj.getClass() == BigIntegerTypeIMPL.class) {
+				return ((BigIntegerTypeIMPL)obj).bigIntegerValue().equals(BigInteger.valueOf((long)value));
+			}
 			return false;
 		}
 		return ((ShortIntegerTypeIMPL)obj).value == value;
-- 
cgit v1.2.1


From 8b79e6d3c72a02f4dc039799e3cd370c06e966b0 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Wed, 18 Aug 2010 18:10:30 +0900
Subject: java: uses MessagePackObject instead of Object for type of
 deserialized objects

---
 .../java/org/msgpack/BufferedUnpackerImpl.java     |   8 +-
 .../java/org/msgpack/MessageTypeException.java     |  10 -
 java/src/main/java/org/msgpack/Packer.java         |   6 -
 java/src/main/java/org/msgpack/Schema.java         |  78 ----
 java/src/main/java/org/msgpack/UnpackIterator.java |   4 +-
 java/src/main/java/org/msgpack/UnpackResult.java   |   6 +-
 java/src/main/java/org/msgpack/Unpacker.java       |  30 +-
 java/src/main/java/org/msgpack/UnpackerImpl.java   | 132 ++----
 .../java/org/msgpack/schema/BooleanSchema.java     |  64 ---
 .../java/org/msgpack/schema/ByteArraySchema.java   |  97 -----
 .../main/java/org/msgpack/schema/ByteSchema.java   |  96 -----
 .../java/org/msgpack/schema/ClassGenerator.java    | 244 -----------
 .../main/java/org/msgpack/schema/ClassSchema.java  |  91 -----
 .../main/java/org/msgpack/schema/DoubleSchema.java |  74 ----
 .../main/java/org/msgpack/schema/FieldSchema.java  |  43 --
 .../main/java/org/msgpack/schema/FloatSchema.java  |  74 ----
 .../org/msgpack/schema/GenericClassSchema.java     |  87 ----
 .../java/org/msgpack/schema/GenericSchema.java     | 129 ------
 .../main/java/org/msgpack/schema/IArraySchema.java |  26 --
 .../main/java/org/msgpack/schema/IMapSchema.java   |  27 --
 .../main/java/org/msgpack/schema/IntSchema.java    |  96 -----
 .../main/java/org/msgpack/schema/ListSchema.java   | 111 -----
 .../main/java/org/msgpack/schema/LongSchema.java   |  80 ----
 .../main/java/org/msgpack/schema/MapSchema.java    | 106 -----
 .../org/msgpack/schema/ReflectionClassSchema.java  |  64 ---
 .../java/org/msgpack/schema/SSchemaParser.java     | 264 ------------
 .../main/java/org/msgpack/schema/SetSchema.java    | 115 ------
 .../main/java/org/msgpack/schema/ShortSchema.java  |  93 -----
 .../org/msgpack/schema/SpecificClassSchema.java    | 122 ------
 .../main/java/org/msgpack/schema/StringSchema.java | 102 -----
 java/src/test/java/org/msgpack/TestPackUnpack.java | 455 ++++++++++-----------
 31 files changed, 280 insertions(+), 2654 deletions(-)
 delete mode 100644 java/src/main/java/org/msgpack/Schema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/BooleanSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/ByteArraySchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/ByteSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/ClassGenerator.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/ClassSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/DoubleSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/FieldSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/FloatSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/GenericClassSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/GenericSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/IArraySchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/IMapSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/IntSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/ListSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/LongSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/MapSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/ReflectionClassSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/SSchemaParser.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/SetSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/ShortSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/SpecificClassSchema.java
 delete mode 100644 java/src/main/java/org/msgpack/schema/StringSchema.java

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
index f4ed35b..9496238 100644
--- a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
+++ b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
@@ -47,7 +47,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
 			offset = noffset;
 		} while(!super.isFinished());
 
-		Object obj = super.getData();
+		MessagePackObject obj = super.getData();
 		super.reset();
 		result.done(obj);
 
@@ -198,7 +198,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
 			{
 				long o = castBuffer.getLong(0);
 				if(o < 0) {
-					// FIXME
+					// FIXME unpackBigInteger
 					throw new MessageTypeException("uint 64 bigger than 0x7fffffff is not supported");
 				}
 				advance(9);
@@ -231,6 +231,8 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
 		}
 	}
 
+	// FIXME unpackBigInteger
+
 	final float unpackFloat() throws IOException, MessageTypeException {
 		more(1);
 		int b = buffer[offset];
@@ -414,7 +416,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
 		return s;
 	}
 
-	final Object unpackObject() throws IOException {
+	final MessagePackObject unpackObject() throws IOException {
 		UnpackResult result = new UnpackResult();
 		if(!next(result)) {
 			super.reset();
diff --git a/java/src/main/java/org/msgpack/MessageTypeException.java b/java/src/main/java/org/msgpack/MessageTypeException.java
index 0fa37b7..698ef6d 100644
--- a/java/src/main/java/org/msgpack/MessageTypeException.java
+++ b/java/src/main/java/org/msgpack/MessageTypeException.java
@@ -23,15 +23,5 @@ public class MessageTypeException extends RuntimeException {
 	public MessageTypeException(String s) {
 		super(s);
 	}
-
-	public static MessageTypeException invalidConvert(Object from, Schema to) {
-		return new MessageTypeException(from.getClass().getName()+" cannot be convert to "+to.getExpression());
-	}
-
-	/* FIXME
-	public static MessageTypeException schemaMismatch(Schema to) {
-		return new MessageTypeException("schema mismatch "+to.getExpression());
-	}
-	*/
 }
 
diff --git a/java/src/main/java/org/msgpack/Packer.java b/java/src/main/java/org/msgpack/Packer.java
index fbf7e35..98af3d6 100644
--- a/java/src/main/java/org/msgpack/Packer.java
+++ b/java/src/main/java/org/msgpack/Packer.java
@@ -308,12 +308,6 @@ public class Packer {
 	}
 
 
-	public Packer packWithSchema(Object o, Schema s) throws IOException {
-		s.pack(this, o);
-		return this;
-	}
-
-
 	public Packer packString(String s) throws IOException {
 		byte[] b = ((String)s).getBytes("UTF-8");
 		packRaw(b.length);
diff --git a/java/src/main/java/org/msgpack/Schema.java b/java/src/main/java/org/msgpack/Schema.java
deleted file mode 100644
index 25e10f9..0000000
--- a/java/src/main/java/org/msgpack/Schema.java
+++ /dev/null
@@ -1,78 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack;
-
-import java.io.Writer;
-import java.io.IOException;
-import org.msgpack.schema.SSchemaParser;
-//import org.msgpack.schema.ClassGenerator;
-
-public abstract class Schema {
-	public Schema() { }
-
-	public abstract String getClassName();
-	public abstract String getExpression();
-
-	public static Schema parse(String source) {
-		return SSchemaParser.parse(source);
-	}
-
-	public static Schema load(String source) {
-		return SSchemaParser.load(source);
-	}
-
-	public abstract void pack(Packer pk, Object obj) throws IOException;
-	public abstract Object convert(Object obj) throws MessageTypeException;
-
-	public Object createFromNil() {
-		return null;
-	}
-
-	public Object createFromBoolean(boolean v) {
-		throw new MessageTypeException("type error");
-	}
-
-	public Object createFromByte(byte v) {
-		throw new MessageTypeException("type error");
-	}
-
-	public Object createFromShort(short v) {
-		throw new MessageTypeException("type error");
-	}
-
-	public Object createFromInt(int v) {
-		throw new MessageTypeException("type error");
-	}
-
-	public Object createFromLong(long v) {
-		throw new MessageTypeException("type error");
-	}
-
-	public Object createFromFloat(float v) {
-		throw new MessageTypeException("type error");
-	}
-
-	public Object createFromDouble(double v) {
-		throw new MessageTypeException("type error");
-	}
-
-	public Object createFromRaw(byte[] b, int offset, int length) {
-		throw new MessageTypeException("type error");
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/UnpackIterator.java b/java/src/main/java/org/msgpack/UnpackIterator.java
index f17e229..8c778b6 100644
--- a/java/src/main/java/org/msgpack/UnpackIterator.java
+++ b/java/src/main/java/org/msgpack/UnpackIterator.java
@@ -21,7 +21,7 @@ import java.io.IOException;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
-public class UnpackIterator extends UnpackResult implements Iterator {
+public class UnpackIterator extends UnpackResult implements Iterator {
 	private Unpacker pac;
 
 	UnpackIterator(Unpacker pac) {
@@ -38,7 +38,7 @@ public class UnpackIterator extends UnpackResult implements Iterator {
 		}
 	}
 
-	public Object next() {
+	public MessagePackObject next() {
 		if(!finished && !hasNext()) {
 			throw new NoSuchElementException();
 		}
diff --git a/java/src/main/java/org/msgpack/UnpackResult.java b/java/src/main/java/org/msgpack/UnpackResult.java
index cec18a1..bb981c1 100644
--- a/java/src/main/java/org/msgpack/UnpackResult.java
+++ b/java/src/main/java/org/msgpack/UnpackResult.java
@@ -19,13 +19,13 @@ package org.msgpack;
 
 public class UnpackResult {
 	protected boolean finished = false;
-	protected Object data = null;
+	protected MessagePackObject data = null;
 
 	public boolean isFinished() {
 		return finished;
 	}
 
-	public Object getData() {
+	public MessagePackObject getData() {
 		return data;
 	}
 
@@ -34,7 +34,7 @@ public class UnpackResult {
 		data = null;
 	}
 
-	void done(Object obj) {
+	void done(MessagePackObject obj) {
 		finished = true;
 		data = obj;
 	}
diff --git a/java/src/main/java/org/msgpack/Unpacker.java b/java/src/main/java/org/msgpack/Unpacker.java
index 32bab64..3a95243 100644
--- a/java/src/main/java/org/msgpack/Unpacker.java
+++ b/java/src/main/java/org/msgpack/Unpacker.java
@@ -26,8 +26,8 @@ import java.nio.ByteBuffer;
 /**
  * Unpacker enables you to deserialize objects from stream.
  *
- * Unpacker provides Buffered API, Unbuffered API, Schema API
- * and Direct Conversion API.
+ * Unpacker provides Buffered API, Unbuffered API and
+ * Direct Conversion API.
  *
  * Buffered API uses the internal buffer of the Unpacker.
  * Following code uses Buffered API with an InputStream:
@@ -39,7 +39,7 @@ import java.nio.ByteBuffer;
  * UnpackResult result = pac.next();
  *
  * // use an iterator.
- * for(Object obj : pac) {
+ * for(MessagePackObject obj : pac) {
  *   // use MessageConvertable interface to convert the
  *   // the generic object to the specific type.
  * }
@@ -56,7 +56,7 @@ import java.nio.ByteBuffer;
  * pac.feed(input_bytes);
  *
  * // use next() method or iterators.
- * for(Object obj : pac) {
+ * for(MessagePackObject obj : pac) {
  *   // ...
  * }
  * 
@@ -75,7 +75,7 @@ import java.nio.ByteBuffer;
  * System.in.read(pac.getBuffer(), pac.getBufferOffset(), pac.getBufferCapacity());
  *
  * // use next() method or iterators.
- * for(Object obj : pac) {
+ * for(MessagePackObject obj : pac) {
  *     // ...
  * }
  * 
@@ -96,12 +96,12 @@ import java.nio.ByteBuffer;
  *
  * // take out object if deserialized object is ready.
  * if(pac.isFinished()) {
- *     Object obj = pac.getData();
+ *     MessagePackObject obj = pac.getData();
  *     // ...
  * }
  * 
  */
-public class Unpacker implements Iterable {
+public class Unpacker implements Iterable {
 
 	// buffer:
 	// +---------------------------------------------+
@@ -170,16 +170,6 @@ public class Unpacker implements Iterable {
 		this.stream = stream;
 	}
 
-	/**
-	 * Sets schema to convert deserialized object into specific type.
-	 * Default schema is {@link GenericSchema} that leaves objects for generic type. Use {@link MessageConvertable#messageConvert(Object)} method to convert the generic object.
-	 * @param s schem to use
-	 */
-	public Unpacker useSchema(Schema s) {
-		impl.setSchema(s);
-		return this;
-	}
-
 
 	/**
 	 * Gets the input stream.
@@ -255,7 +245,7 @@ public class Unpacker implements Iterable {
 	/**
 	 * Returns the iterator that calls {@link next()} method repeatedly.
 	 */
-	public Iterator iterator() {
+	public Iterator iterator() {
 		return new UnpackIterator(this);
 	}
 
@@ -387,7 +377,7 @@ public class Unpacker implements Iterable {
 	/**
 	 * Gets the object deserialized by {@link execute(byte[])} method.
 	 */
-	public Object getData() {
+	public MessagePackObject getData() {
 		return impl.getData();
 	}
 
@@ -557,7 +547,7 @@ public class Unpacker implements Iterable {
 	 * Gets one {@code Object} value from the buffer.
 	 * This method calls {@link fill()} method if needed.
 	 */
-	final public Object unpackObject() throws IOException {
+	final public MessagePackObject unpackObject() throws IOException {
 		return impl.unpackObject();
 	}
 
diff --git a/java/src/main/java/org/msgpack/UnpackerImpl.java b/java/src/main/java/org/msgpack/UnpackerImpl.java
index 10cf5f0..f004e6c 100644
--- a/java/src/main/java/org/msgpack/UnpackerImpl.java
+++ b/java/src/main/java/org/msgpack/UnpackerImpl.java
@@ -18,11 +18,7 @@
 package org.msgpack;
 
 import java.nio.ByteBuffer;
-//import java.math.BigInteger;
-import org.msgpack.*;
-import org.msgpack.schema.GenericSchema;
-import org.msgpack.schema.IMapSchema;
-import org.msgpack.schema.IArraySchema;
+import org.msgpack.object.*;
 
 public class UnpackerImpl {
 	static final int CS_HEADER      = 0x00;
@@ -55,30 +51,19 @@ public class UnpackerImpl {
 	private int[]    stack_ct       = new int[MAX_STACK_SIZE];
 	private int[]    stack_count    = new int[MAX_STACK_SIZE];
 	private Object[] stack_obj      = new Object[MAX_STACK_SIZE];
-	private Schema[] stack_schema   = new Schema[MAX_STACK_SIZE];
 	private int top_ct;
 	private int top_count;
 	private Object top_obj;
-	private Schema top_schema;
 	private ByteBuffer castBuffer   = ByteBuffer.allocate(8);
 	private boolean finished = false;
-	private Object data = null;
-
-	private static final Schema GENERIC_SCHEMA = new GenericSchema();
-	private Schema rootSchema;
+	private MessagePackObject data = null;
 
 	public UnpackerImpl()
 	{
-		setSchema(GENERIC_SCHEMA);
-	}
-
-	public void setSchema(Schema schema)
-	{
-		this.rootSchema = schema;
 		reset();
 	}
 
-	public final Object getData()
+	public final MessagePackObject getData()
 	{
 		return data;
 	}
@@ -94,7 +79,6 @@ public class UnpackerImpl {
 		top_ct = 0;
 		top_count = 0;
 		top_obj = null;
-		top_schema = rootSchema;
 	}
 
 	public final void reset()
@@ -127,20 +111,20 @@ public class UnpackerImpl {
 	
 					if((b & 0x80) == 0) {  // Positive Fixnum
 						//System.out.println("positive fixnum "+b);
-						obj = top_schema.createFromByte((byte)b);
+						obj = IntegerType.create((byte)b);
 						break _push;
 					}
 	
 					if((b & 0xe0) == 0xe0) {  // Negative Fixnum
 						//System.out.println("negative fixnum "+b);
-						obj = top_schema.createFromByte((byte)b);
+						obj = IntegerType.create((byte)b);
 						break _push;
 					}
 	
 					if((b & 0xe0) == 0xa0) {  // FixRaw
 						trail = b & 0x1f;
 						if(trail == 0) {
-							obj = top_schema.createFromRaw(new byte[0], 0, 0);
+							obj = new RawType(new byte[0]);
 							break _push;
 						}
 						cs = ACS_RAW_VALUE;
@@ -151,25 +135,20 @@ public class UnpackerImpl {
 						if(top >= MAX_STACK_SIZE) {
 							throw new UnpackException("parse error");
 						}
-						if(!(top_schema instanceof IArraySchema)) {
-							throw new RuntimeException("type error");
-						}
 						count = b & 0x0f;
 						//System.out.println("fixarray count:"+count);
-						obj = new Object[count];
+						obj = new MessagePackObject[count];
 						if(count == 0) {
-							obj = ((IArraySchema)top_schema).createFromArray((Object[])obj);
+							obj = new ArrayType((MessagePackObject[])obj);
 							break _push;
 						}
 						++top;
 						stack_obj[top]    = top_obj;
 						stack_ct[top]     = top_ct;
 						stack_count[top]  = top_count;
-						stack_schema[top] = top_schema;
 						top_obj    = obj;
 						top_ct     = CT_ARRAY_ITEM;
 						top_count  = count;
-						top_schema = ((IArraySchema)top_schema).getElementSchema(0);
 						break _header_again;
 					}
 	
@@ -177,13 +156,10 @@ public class UnpackerImpl {
 						if(top >= MAX_STACK_SIZE) {
 							throw new UnpackException("parse error");
 						}
-						if(!(top_schema instanceof IMapSchema)) {
-							throw new RuntimeException("type error");
-						}
 						count = b & 0x0f;
-						obj = new Object[count*2];
+						obj = new MessagePackObject[count*2];
 						if(count == 0) {
-							obj = ((IMapSchema)top_schema).createFromMap((Object[])obj);
+							obj = new MapType((MessagePackObject[])obj);
 							break _push;
 						}
 						//System.out.println("fixmap count:"+count);
@@ -191,23 +167,21 @@ public class UnpackerImpl {
 						stack_obj[top]    = top_obj;
 						stack_ct[top]     = top_ct;
 						stack_count[top]  = top_count;
-						stack_schema[top] = top_schema;
 						top_obj    = obj;
 						top_ct     = CT_MAP_KEY;
 						top_count  = count;
-						top_schema = ((IMapSchema)top_schema).getKeySchema();
 						break _header_again;
 					}
 	
 					switch(b & 0xff) {    // FIXME
 					case 0xc0:  // nil
-						obj = top_schema.createFromNil();
+						obj = new NilType();
 						break _push;
 					case 0xc2:  // false
-						obj = top_schema.createFromBoolean(false);
+						obj = new BooleanType(false);
 						break _push;
 					case 0xc3:  // true
-						obj = top_schema.createFromBoolean(true);
+						obj = new BooleanType(true);
 						break _push;
 					case 0xca:  // float
 					case 0xcb:  // double
@@ -251,13 +225,13 @@ public class UnpackerImpl {
 					case CS_FLOAT:
 						castBuffer.rewind();
 						castBuffer.put(src, n, 4);
-						obj = top_schema.createFromFloat( castBuffer.getFloat(0) );
+						obj = FloatType.create( castBuffer.getFloat(0) );
 						//System.out.println("float "+obj);
 						break _push;
 					case CS_DOUBLE:
 						castBuffer.rewind();
 						castBuffer.put(src, n, 8);
-						obj = top_schema.createFromDouble( castBuffer.getDouble(0) );
+						obj = FloatType.create( castBuffer.getDouble(0) );
 						//System.out.println("double "+obj);
 						break _push;
 					case CS_UINT_8:
@@ -265,7 +239,7 @@ public class UnpackerImpl {
 						//System.out.println(src[n]);
 						//System.out.println(src[n+1]);
 						//System.out.println(src[n-1]);
-						obj = top_schema.createFromShort( (short)((src[n]) & 0xff) );
+						obj = IntegerType.create( (short)((src[n]) & 0xff) );
 						//System.out.println("uint8 "+obj);
 						break _push;
 					case CS_UINT_16:
@@ -273,13 +247,13 @@ public class UnpackerImpl {
 						//System.out.println(src[n+1]);
 						castBuffer.rewind();
 						castBuffer.put(src, n, 2);
-						obj = top_schema.createFromInt( ((int)castBuffer.getShort(0)) & 0xffff );
+						obj = IntegerType.create( ((int)castBuffer.getShort(0)) & 0xffff );
 						//System.out.println("uint 16 "+obj);
 						break _push;
 					case CS_UINT_32:
 						castBuffer.rewind();
 						castBuffer.put(src, n, 4);
-						obj = top_schema.createFromLong( ((long)castBuffer.getInt(0)) & 0xffffffffL );
+						obj = IntegerType.create( ((long)castBuffer.getInt(0)) & 0xffffffffL );
 						//System.out.println("uint 32 "+obj);
 						break _push;
 					case CS_UINT_64:
@@ -292,34 +266,34 @@ public class UnpackerImpl {
 								//obj = GenericBigInteger.valueOf(o & 0x7fffffffL).setBit(31);
 								throw new UnpackException("uint 64 bigger than 0x7fffffff is not supported");
 							} else {
-								obj = top_schema.createFromLong( o );
+								obj = IntegerType.create(o);
 							}
 						}
 						break _push;
 					case CS_INT_8:
-						obj = top_schema.createFromByte(  src[n] );
+						obj = IntegerType.create( src[n] );
 						break _push;
 					case CS_INT_16:
 						castBuffer.rewind();
 						castBuffer.put(src, n, 2);
-						obj = top_schema.createFromShort( castBuffer.getShort(0) );
+						obj = IntegerType.create( castBuffer.getShort(0) );
 						break _push;
 					case CS_INT_32:
 						castBuffer.rewind();
 						castBuffer.put(src, n, 4);
-						obj = top_schema.createFromInt( castBuffer.getInt(0) );
+						obj = IntegerType.create( castBuffer.getInt(0) );
 						break _push;
 					case CS_INT_64:
 						castBuffer.rewind();
 						castBuffer.put(src, n, 8);
-						obj = top_schema.createFromLong( castBuffer.getLong(0) );
+						obj = IntegerType.create( castBuffer.getLong(0) );
 						break _push;
 					case CS_RAW_16:
 						castBuffer.rewind();
 						castBuffer.put(src, n, 2);
 						trail = ((int)castBuffer.getShort(0)) & 0xffff;
 						if(trail == 0) {
-							obj = top_schema.createFromRaw(new byte[0], 0, 0);
+							obj = new RawType(new byte[0]);
 							break _push;
 						}
 						cs = ACS_RAW_VALUE;
@@ -330,77 +304,67 @@ public class UnpackerImpl {
 						// FIXME overflow check
 						trail = castBuffer.getInt(0) & 0x7fffffff;
 						if(trail == 0) {
-							obj = top_schema.createFromRaw(new byte[0], 0, 0);
+							obj = new RawType(new byte[0]);
 							break _push;
 						}
 						cs = ACS_RAW_VALUE;
-					case ACS_RAW_VALUE:
-						obj = top_schema.createFromRaw(src, n, trail);
+					case ACS_RAW_VALUE: {
+							byte[] raw = new byte[trail];
+							System.arraycopy(src, n, raw, 0, trail);
+							obj = new RawType(raw);
+						}
 						break _push;
 					case CS_ARRAY_16:
 						if(top >= MAX_STACK_SIZE) {
 							throw new UnpackException("parse error");
 						}
-						if(!(top_schema instanceof IArraySchema)) {
-							throw new RuntimeException("type error");
-						}
 						castBuffer.rewind();
 						castBuffer.put(src, n, 2);
 						count = ((int)castBuffer.getShort(0)) & 0xffff;
-						obj = new Object[count];
+						obj = new MessagePackObject[count];
 						if(count == 0) {
-							obj = ((IArraySchema)top_schema).createFromArray((Object[])obj);
+							obj = new ArrayType((MessagePackObject[])obj);
 							break _push;
 						}
 						++top;
 						stack_obj[top]    = top_obj;
 						stack_ct[top]     = top_ct;
 						stack_count[top]  = top_count;
-						stack_schema[top] = top_schema;
 						top_obj    = obj;
 						top_ct     = CT_ARRAY_ITEM;
 						top_count  = count;
-						top_schema = ((IArraySchema)top_schema).getElementSchema(0);
 						break _header_again;
 					case CS_ARRAY_32:
 						if(top >= MAX_STACK_SIZE) {
 							throw new UnpackException("parse error");
 						}
-						if(!(top_schema instanceof IArraySchema)) {
-							throw new RuntimeException("type error");
-						}
 						castBuffer.rewind();
 						castBuffer.put(src, n, 4);
 						// FIXME overflow check
 						count = castBuffer.getInt(0) & 0x7fffffff;
-						obj = new Object[count];
+						obj = new MessagePackObject[count];
 						if(count == 0) {
-							obj = ((IArraySchema)top_schema).createFromArray((Object[])obj);
+							obj = new ArrayType((MessagePackObject[])obj);
 							break _push;
 						}
 						++top;
 						stack_obj[top]    = top_obj;
 						stack_ct[top]     = top_ct;
 						stack_count[top]  = top_count;
-						stack_schema[top] = top_schema;
 						top_obj    = obj;
 						top_ct     = CT_ARRAY_ITEM;
 						top_count  = count;
-						top_schema = ((IArraySchema)top_schema).getElementSchema(0);
 						break _header_again;
 					case CS_MAP_16:
 						if(top >= MAX_STACK_SIZE) {
 							throw new UnpackException("parse error");
 						}
-						if(!(top_schema instanceof IMapSchema)) {
-							throw new RuntimeException("type error");
-						}
 						castBuffer.rewind();
 						castBuffer.put(src, n, 2);
 						count = ((int)castBuffer.getShort(0)) & 0xffff;
-						obj = new Object[count*2];
+						obj = new MessagePackObject[count*2];
 						if(count == 0) {
-							obj = ((IMapSchema)top_schema).createFromMap((Object[])obj);
+							obj = new MapType((MessagePackObject[])obj);
 							break _push;
 						}
 						//System.out.println("fixmap count:"+count);
@@ -408,26 +372,21 @@ public class UnpackerImpl {
 						stack_obj[top]    = top_obj;
 						stack_ct[top]     = top_ct;
 						stack_count[top]  = top_count;
-						stack_schema[top] = top_schema;
 						top_obj    = obj;
 						top_ct     = CT_MAP_KEY;
 						top_count  = count;
-						top_schema = ((IMapSchema)top_schema).getKeySchema();
 						break _header_again;
 					case CS_MAP_32:
 						if(top >= MAX_STACK_SIZE) {
 							throw new UnpackException("parse error");
 						}
-						if(!(top_schema instanceof IMapSchema)) {
-							throw new RuntimeException("type error");
-						}
 						castBuffer.rewind();
 						castBuffer.put(src, n, 4);
 						// FIXME overflow check
 						count = castBuffer.getInt(0) & 0x7fffffff;
-						obj = new Object[count*2];
+						obj = new MessagePackObject[count*2];
 						if(count == 0) {
-							obj = ((IMapSchema)top_schema).createFromMap((Object[])obj);
+							obj = new MapType((MessagePackObject[])obj);
 							break _push;
 						}
 						//System.out.println("fixmap count:"+count);
@@ -435,11 +394,9 @@ public class UnpackerImpl {
 						stack_obj[top]    = top_obj;
 						stack_ct[top]     = top_ct;
 						stack_count[top]  = top_count;
-						stack_schema[top] = top_schema;
 						top_obj    = obj;
 						top_ct     = CT_MAP_KEY;
 						top_count  = count;
-						top_schema = ((IMapSchema)top_schema).getKeySchema();
 						break _header_again;
 					default:
 						throw new UnpackException("parse error");
@@ -454,7 +411,7 @@ public class UnpackerImpl {
 				//System.out.println("push top:"+top);
 				if(top == -1) {
 					++i;
-					data = obj;
+					data = (MessagePackObject)obj;
 					finished = true;
 					break _out;
 				}
@@ -468,14 +425,10 @@ public class UnpackerImpl {
 							top_obj    = stack_obj[top];
 							top_ct     = stack_ct[top];
 							top_count  = stack_count[top];
-							top_schema = stack_schema[top];
-							obj = ((IArraySchema)top_schema).createFromArray(ar);
+							obj = new ArrayType((MessagePackObject[])ar);
 							stack_obj[top] = null;
-							stack_schema[top] = null;
 							--top;
 							break _push;
-						} else {
-							top_schema = ((IArraySchema)stack_schema[top]).getElementSchema(ar.length - top_count);
 						}
 						break _header_again;
 					}
@@ -484,7 +437,6 @@ public class UnpackerImpl {
 						Object[] mp = (Object[])top_obj;
 						mp[mp.length - top_count*2] = obj;
 						top_ct = CT_MAP_VALUE;
-						top_schema = ((IMapSchema)stack_schema[top]).getValueSchema();
 						break _header_again;
 					}
 				case CT_MAP_VALUE: {
@@ -495,10 +447,8 @@ public class UnpackerImpl {
 							top_obj    = stack_obj[top];
 							top_ct     = stack_ct[top];
 							top_count  = stack_count[top];
-							top_schema = stack_schema[top];
-							obj = ((IMapSchema)top_schema).createFromMap(mp);
+							obj = new MapType((MessagePackObject[])mp);
 							stack_obj[top] = null;
-							stack_schema[top] = null;
 							--top;
 							break _push;
 						}
diff --git a/java/src/main/java/org/msgpack/schema/BooleanSchema.java b/java/src/main/java/org/msgpack/schema/BooleanSchema.java
deleted file mode 100644
index 2c325f1..0000000
--- a/java/src/main/java/org/msgpack/schema/BooleanSchema.java
+++ /dev/null
@@ -1,64 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.io.IOException;
-import org.msgpack.*;
-
-public class BooleanSchema extends Schema {
-	public BooleanSchema() { }
-
-	@Override
-	public String getClassName() {
-		return "Boolean";
-	}
-
-	@Override
-	public String getExpression() {
-		return "boolean";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof Boolean) {
-			pk.packBoolean((Boolean)obj);
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	public static final boolean convertBoolean(Object obj) throws MessageTypeException {
-		if(obj instanceof Boolean) {
-			return (Boolean)obj;
-		}
-		throw new MessageTypeException();
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return convertBoolean(obj);
-	}
-
-	@Override
-	public Object createFromBoolean(boolean v) {
-		return v;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/ByteArraySchema.java b/java/src/main/java/org/msgpack/schema/ByteArraySchema.java
deleted file mode 100644
index af9c0ed..0000000
--- a/java/src/main/java/org/msgpack/schema/ByteArraySchema.java
+++ /dev/null
@@ -1,97 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.nio.ByteBuffer;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import org.msgpack.*;
-
-public class ByteArraySchema extends Schema {
-	public ByteArraySchema() { }
-
-	@Override
-	public String getClassName() {
-		return "byte[]";
-	}
-
-	@Override
-	public String getExpression() {
-		return "raw";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof byte[]) {
-			byte[] b = (byte[])obj;
-			pk.packRaw(b.length);
-			pk.packRawBody(b);
-		} else if(obj instanceof String) {
-			try {
-				byte[] b = ((String)obj).getBytes("UTF-8");
-				pk.packRaw(b.length);
-				pk.packRawBody(b);
-			} catch (UnsupportedEncodingException e) {
-				throw new MessageTypeException();
-			}
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	public static final byte[] convertByteArray(Object obj) throws MessageTypeException {
-		if(obj instanceof byte[]) {
-			// FIXME copy?
-			//byte[] d = (byte[])obj;
-			//byte[] v = new byte[d.length];
-			//System.arraycopy(d, 0, v, 0, d.length);
-			//return v;
-			return (byte[])obj;
-		} else if(obj instanceof ByteBuffer) {
-			ByteBuffer d = (ByteBuffer)obj;
-			byte[] v = new byte[d.capacity()];
-			int pos = d.position();
-			d.get(v);
-			d.position(pos);
-			return v;
-		} else if(obj instanceof String) {
-			try {
-				return ((String)obj).getBytes("UTF-8");
-			} catch (UnsupportedEncodingException e) {
-				throw new MessageTypeException();
-			}
-		} else {
-			throw new MessageTypeException();
-		}
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return convertByteArray(obj);
-	}
-
-	@Override
-	public Object createFromRaw(byte[] b, int offset, int length) {
-		byte[] d = new byte[length];
-		System.arraycopy(b, offset, d, 0, length);
-		return d;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/ByteSchema.java b/java/src/main/java/org/msgpack/schema/ByteSchema.java
deleted file mode 100644
index 6003a0f..0000000
--- a/java/src/main/java/org/msgpack/schema/ByteSchema.java
+++ /dev/null
@@ -1,96 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.io.IOException;
-import org.msgpack.*;
-
-public class ByteSchema extends Schema {
-	public ByteSchema() { }
-
-	@Override
-	public String getClassName() {
-		return "Byte";
-	}
-
-	@Override
-	public String getExpression() {
-		return "byte";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof Number) {
-			short value = ((Number)obj).shortValue();
-			if(value > Byte.MAX_VALUE) {
-				throw new MessageTypeException();
-			}
-			pk.packByte((byte)value);
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	public static final byte convertByte(Object obj) throws MessageTypeException {
-		if(obj instanceof Number) {
-			short value = ((Number)obj).shortValue();
-			if(value > Byte.MAX_VALUE) {
-				throw new MessageTypeException();
-			}
-			return (byte)value;
-		}
-		throw new MessageTypeException();
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return convertByte(obj);
-	}
-
-	@Override
-	public Object createFromByte(byte v) {
-		return (byte)v;
-	}
-
-	@Override
-	public Object createFromShort(short v) {
-		if(v > Byte.MAX_VALUE) {
-			throw new MessageTypeException();
-		}
-		return (byte)v;
-	}
-
-	@Override
-	public Object createFromInt(int v) {
-		if(v > Byte.MAX_VALUE) {
-			throw new MessageTypeException();
-		}
-		return (byte)v;
-	}
-
-	@Override
-	public Object createFromLong(long v) {
-		if(v > Byte.MAX_VALUE) {
-			throw new MessageTypeException();
-		}
-		return (byte)v;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/ClassGenerator.java b/java/src/main/java/org/msgpack/schema/ClassGenerator.java
deleted file mode 100644
index a515996..0000000
--- a/java/src/main/java/org/msgpack/schema/ClassGenerator.java
+++ /dev/null
@@ -1,244 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.io.IOException;
-import java.io.File;
-import java.io.Writer;
-import org.msgpack.*;
-
-public class ClassGenerator {
-	private ClassSchema schema;
-	private Writer writer;
-	private int indent;
-
-	private ClassGenerator(Writer writer) {
-		this.writer = writer;
-		this.indent = 0;
-	}
-
-	public static void write(Schema schema, Writer dest) throws IOException {
-		if(!(schema instanceof ClassSchema)) {
-			throw new RuntimeException("schema is not class schema");
-		}
-		ClassSchema cs = (ClassSchema)schema;
-		new ClassGenerator(dest).run(cs);
-	}
-
-	private void run(ClassSchema cs) throws IOException {
-		List subclasses = new ArrayList();
-		for(FieldSchema f : cs.getFields()) {
-			findSubclassSchema(subclasses, f.getSchema());
-		}
-
-		for(ClassSchema sub : subclasses) {
-			sub.setNamespace(cs.getNamespace());
-			sub.setImports(cs.getImports());
-		}
-
-		this.schema = cs;
-
-		writeHeader();
-
-		writeClass();
-
-		for(ClassSchema sub : subclasses) {
-			this.schema = sub;
-			writeSubclass();
-		}
-
-		writeFooter();
-
-		this.schema = null;
-		writer.flush();
-	}
-
-	private void findSubclassSchema(List dst, Schema s) {
-		if(s instanceof ClassSchema) {
-			ClassSchema cs = (ClassSchema)s;
-			if(!dst.contains(cs)) { dst.add(cs); }
-			for(FieldSchema f : cs.getFields()) {
-				findSubclassSchema(dst, f.getSchema());
-			}
-		} else if(s instanceof ListSchema) {
-			ListSchema as = (ListSchema)s;
-			findSubclassSchema(dst, as.getElementSchema(0));
-		} else if(s instanceof SetSchema) {
-			SetSchema as = (SetSchema)s;
-			findSubclassSchema(dst, as.getElementSchema(0));
-		} else if(s instanceof MapSchema) {
-			MapSchema as = (MapSchema)s;
-			findSubclassSchema(dst, as.getKeySchema());
-			findSubclassSchema(dst, as.getValueSchema());
-		}
-	}
-
-	private void writeHeader() throws IOException {
-		if(schema.getNamespace() != null) {
-			line("package "+schema.getNamespace()+";");
-			line();
-		}
-		line("import java.util.*;");
-		line("import java.io.*;");
-		line("import org.msgpack.*;");
-		line("import org.msgpack.schema.ClassSchema;");
-		line("import org.msgpack.schema.FieldSchema;");
-	}
-
-	private void writeFooter() throws IOException {
-		line();
-	}
-
-	private void writeClass() throws IOException {
-		line();
-		line("public final class "+schema.getClassName()+" implements MessagePackable, MessageConvertable");
-		line("{");
-		pushIndent();
-			writeSchema();
-			writeMemberVariables();
-			writeMemberFunctions();
-		popIndent();
-		line("}");
-	}
-
-	private void writeSubclass() throws IOException {
-		line();
-		line("final class "+schema.getClassName()+" implements MessagePackable, MessageConvertable");
-		line("{");
-		pushIndent();
-			writeSchema();
-			writeMemberVariables();
-			writeMemberFunctions();
-		popIndent();
-		line("}");
-	}
-
-	private void writeSchema() throws IOException {
-		line("private static final ClassSchema _SCHEMA = (ClassSchema)Schema.load(\""+schema.getExpression()+"\");");
-		line("public static ClassSchema getSchema() { return _SCHEMA; }");
-	}
-
-	private void writeMemberVariables() throws IOException {
-		line();
-		for(FieldSchema f : schema.getFields()) {
-			line("public "+f.getSchema().getClassName()+" "+f.getName()+";");
-		}
-	}
-
-	private void writeMemberFunctions() throws IOException {
-		// void messagePack(Packer pk)
-		// boolean equals(Object obj)
-		// int hashCode()
-		// void set(int _index, Object _value)
-		// Object get(int _index);
-		// getXxx()
-		// setXxx(Xxx xxx)
-		writeConstructors();
-		writeAccessors();
-		writePackFunction();
-		writeConvertFunction();
-		writeFactoryFunction();
-	}
-
-	private void writeConstructors() throws IOException {
-		line();
-		line("public "+schema.getClassName()+"() { }");
-	}
-
-	private void writeAccessors() throws IOException {
-		// FIXME
-		//line();
-		//for(FieldSchema f : schema.getFields()) {
-		//	line("");
-		//}
-	}
-
-	private void writePackFunction() throws IOException {
-		line();
-		line("@Override");
-		line("public void messagePack(Packer _pk) throws IOException");
-		line("{");
-		pushIndent();
-			line("_pk.packArray("+schema.getFields().length+");");
-			line("FieldSchema[] _fields = _SCHEMA.getFields();");
-			int i = 0;
-			for(FieldSchema f : schema.getFields()) {
-				line("_fields["+i+"].getSchema().pack(_pk, "+f.getName()+");");
-				++i;
-			}
-		popIndent();
-		line("}");
-	}
-
-	private void writeConvertFunction() throws IOException {
-		line();
-		line("@Override");
-		line("@SuppressWarnings(\"unchecked\")");
-		line("public void messageConvert(Object obj) throws MessageTypeException");
-		line("{");
-		pushIndent();
-			line("Object[] _source = ((List)obj).toArray();");
-			line("FieldSchema[] _fields = _SCHEMA.getFields();");
-			int i = 0;
-			for(FieldSchema f : schema.getFields()) {
-				line("if(_source.length <= "+i+") { return; } this."+f.getName()+" = ("+f.getSchema().getClassName()+")_fields["+i+"].getSchema().convert(_source["+i+"]);");
-				++i;
-			}
-		popIndent();
-		line("}");
-	}
-
-	private void writeFactoryFunction() throws IOException {
-		line();
-		line("@SuppressWarnings(\"unchecked\")");
-		line("public static "+schema.getClassName()+" createFromMessage(Object[] _message)");
-		line("{");
-		pushIndent();
-			line(schema.getClassName()+" _self = new "+schema.getClassName()+"();");
-			int i = 0;
-			for(FieldSchema f : schema.getFields()) {
-				line("if(_message.length <= "+i+") { return _self; } _self."+f.getName()+" = ("+f.getSchema().getClassName()+")_message["+i+"];");
-				++i;
-			}
-			line("return _self;");
-		popIndent();
-		line("}");
-	}
-
-	private void line(String str) throws IOException {
-		for(int i=0; i < indent; ++i) {
-			writer.write("\t");
-		}
-		writer.write(str+"\n");
-	}
-
-	private void line() throws IOException {
-		writer.write("\n");
-	}
-
-	private void pushIndent() {
-		indent += 1;
-	}
-
-	private void popIndent() {
-		indent -= 1;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/ClassSchema.java b/java/src/main/java/org/msgpack/schema/ClassSchema.java
deleted file mode 100644
index cd59755..0000000
--- a/java/src/main/java/org/msgpack/schema/ClassSchema.java
+++ /dev/null
@@ -1,91 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.util.Arrays;
-import java.util.List;
-import org.msgpack.*;
-
-public abstract class ClassSchema extends Schema implements IArraySchema {
-	protected String name;
-	protected FieldSchema[] fields;
-	protected List imports;
-	protected String namespace;
-	protected String fqdn;
-
-	public ClassSchema(
-			String name, String namespace,
-			List imports, List fields) {
-		this.name = name;
-		this.namespace = namespace;
-		this.imports = imports;  // FIXME clone?
-		this.fields = new FieldSchema[fields.size()];
-		System.arraycopy(fields.toArray(), 0, this.fields, 0, fields.size());
-		if(namespace == null) {
-			this.fqdn = name;
-		} else {
-			this.fqdn = namespace+"."+name;
-		}
-	}
-
-	@Override
-	public String getClassName() {
-		return name;
-	}
-
-	@Override
-	public String getExpression() {
-		StringBuffer b = new StringBuffer();
-		b.append("(class ");
-		b.append(name);
-		if(namespace != null) {
-			b.append(" (package "+namespace+")");
-		}
-		for(FieldSchema f : fields) {
-			b.append(" "+f.getExpression());
-		}
-		b.append(")");
-		return b.toString();
-	}
-
-	public boolean equals(ClassSchema o) {
-		return (namespace != null ? namespace.equals(o.getNamespace()) : o.getNamespace() == null) &&
-			name.equals(o.name);
-	}
-
-	public final FieldSchema[] getFields() {
-		return fields;
-	}
-
-	String getNamespace() {
-		return namespace;
-	}
-
-	List getImports() {
-		return imports;
-	}
-
-	void setNamespace(String namespace) {
-		this.namespace = namespace;
-	}
-
-	void setImports(List imports) {
-		this.imports = imports;  // FIXME clone?
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/DoubleSchema.java b/java/src/main/java/org/msgpack/schema/DoubleSchema.java
deleted file mode 100644
index cb857c3..0000000
--- a/java/src/main/java/org/msgpack/schema/DoubleSchema.java
+++ /dev/null
@@ -1,74 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.io.IOException;
-import org.msgpack.*;
-
-public class DoubleSchema extends Schema {
-	public DoubleSchema() { }
-
-	@Override
-	public String getClassName() {
-		return "Double";
-	}
-
-	@Override
-	public String getExpression() {
-		return "double";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof Double) {
-			pk.packDouble((Double)obj);
-		} else if(obj instanceof Float) {
-			pk.packFloat((Float)obj);
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	public static final double convertDouble(Object obj) throws MessageTypeException {
-		if(obj instanceof Double) {
-			return (Double)obj;
-		} else if(obj instanceof Float) {
-			return ((Float)obj).doubleValue();
-		} else {
-			throw new MessageTypeException();
-		}
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return convertDouble(obj);
-	}
-
-	@Override
-	public Object createFromFloat(float v) {
-		return (double)v;
-	}
-
-	@Override
-	public Object createFromDouble(double v) {
-		return (double)v;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/FieldSchema.java b/java/src/main/java/org/msgpack/schema/FieldSchema.java
deleted file mode 100644
index 66c2ff2..0000000
--- a/java/src/main/java/org/msgpack/schema/FieldSchema.java
+++ /dev/null
@@ -1,43 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import org.msgpack.Schema;
-
-public class FieldSchema {
-	private String name;
-	private Schema schema;
-
-	public FieldSchema(String name, Schema schema) {
-		this.name = name;
-		this.schema = schema;
-	}
-
-	public final String getName() {
-		return name;
-	}
-
-	public final Schema getSchema() {
-		return schema;
-	}
-
-	public String getExpression() {
-		return "(field "+name+" "+schema.getExpression()+")";
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/FloatSchema.java b/java/src/main/java/org/msgpack/schema/FloatSchema.java
deleted file mode 100644
index cd73201..0000000
--- a/java/src/main/java/org/msgpack/schema/FloatSchema.java
+++ /dev/null
@@ -1,74 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.io.IOException;
-import org.msgpack.*;
-
-public class FloatSchema extends Schema {
-	public FloatSchema() { }
-
-	@Override
-	public String getClassName() {
-		return "Float";
-	}
-
-	@Override
-	public String getExpression() {
-		return "float";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof Double) {
-			pk.packDouble((Double)obj);
-		} else if(obj instanceof Float) {
-			pk.packFloat((Float)obj);
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	public static final float convertFloat(Object obj) throws MessageTypeException {
-		if(obj instanceof Double) {
-			return ((Double)obj).floatValue();
-		} else if(obj instanceof Float) {
-			return (Float)obj;
-		} else {
-			throw new MessageTypeException();
-		}
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return convertFloat(obj);
-	}
-
-	@Override
-	public Object createFromFloat(float v) {
-		return (float)v;
-	}
-
-	@Override
-	public Object createFromDouble(double v) {
-		return (float)v;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/GenericClassSchema.java b/java/src/main/java/org/msgpack/schema/GenericClassSchema.java
deleted file mode 100644
index 1ab4c33..0000000
--- a/java/src/main/java/org/msgpack/schema/GenericClassSchema.java
+++ /dev/null
@@ -1,87 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
-import java.io.IOException;
-import org.msgpack.*;
-
-public class GenericClassSchema extends ClassSchema {
-	public GenericClassSchema(
-			String name, String namespace,
-			List imports, List fields) {
-		super(name, namespace, imports, fields);
-	}
-
-	@Override
-	@SuppressWarnings("unchecked")
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof Map) {
-			Map d = (Map)obj;
-			pk.packArray(fields.length);
-			for(int i=0; i < fields.length; ++i) {
-				FieldSchema f = fields[i];
-				f.getSchema().pack(pk, d.get(f.getName()));
-			}
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		if(obj instanceof Collection) {
-			// FIXME optimize
-			return createFromArray( ((Collection)obj).toArray() );
-		} else if(obj instanceof Map) {
-			HashMap m = new HashMap(fields.length);
-			Map d = (Map)obj;
-			for(int i=0; i < fields.length; ++i) {
-				FieldSchema f = fields[i];
-				String fieldName = f.getName();
-				m.put(fieldName, f.getSchema().convert(d.get(fieldName)));
-			}
-			return m;
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	public Schema getElementSchema(int index) {
-		// FIXME check index < fields.length
-		return fields[index].getSchema();
-	}
-
-	public Object createFromArray(Object[] obj) {
-		HashMap m = new HashMap(fields.length);
-		int i=0;
-		for(; i < obj.length; ++i) {
-			m.put(fields[i].getName(), obj[i]);
-		}
-		for(; i < fields.length; ++i) {
-			m.put(fields[i].getName(), null);
-		}
-		return m;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/GenericSchema.java b/java/src/main/java/org/msgpack/schema/GenericSchema.java
deleted file mode 100644
index f9098ed..0000000
--- a/java/src/main/java/org/msgpack/schema/GenericSchema.java
+++ /dev/null
@@ -1,129 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.HashMap;
-import java.io.IOException;
-import org.msgpack.*;
-
-public class GenericSchema extends Schema implements IArraySchema, IMapSchema {
-	public GenericSchema() { }
-
-	@Override
-	public String getClassName() {
-		return "Object";
-	}
-
-	@Override
-	public String getExpression() {
-		return "object";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		pk.pack(obj);
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return obj;
-	}
-
-	@Override
-	public Schema getElementSchema(int index) {
-		return this;
-	}
-
-	@Override
-	public Schema getKeySchema() {
-		return this;
-	}
-
-	@Override
-	public Schema getValueSchema() {
-		return this;
-	}
-
-	@Override
-	public Object createFromNil() {
-		return null;
-	}
-
-	@Override
-	public Object createFromBoolean(boolean v) {
-		return v;
-	}
-
-	@Override
-	public Object createFromByte(byte v) {
-		return v;
-	}
-
-	@Override
-	public Object createFromShort(short v) {
-		return v;
-	}
-
-	@Override
-	public Object createFromInt(int v) {
-		return v;
-	}
-
-	@Override
-	public Object createFromLong(long v) {
-		return v;
-	}
-
-	@Override
-	public Object createFromFloat(float v) {
-		return v;
-	}
-
-	@Override
-	public Object createFromDouble(double v) {
-		return v;
-	}
-
-	@Override
-	public Object createFromRaw(byte[] b, int offset, int length) {
-		byte[] bytes = new byte[length];
-		System.arraycopy(b, offset, bytes, 0, length);
-		return bytes;
-	}
-
-	@Override
-	public Object createFromArray(Object[] obj) {
-		return Arrays.asList(obj);
-	}
-
-	@Override
-	@SuppressWarnings("unchecked")
-	public Object createFromMap(Object[] obj) {
-		HashMap m = new HashMap(obj.length / 2);
-		int i = 0;
-		while(i < obj.length) {
-			Object k = obj[i++];
-			Object v = obj[i++];
-			m.put(k, v);
-		}
-		return m;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/IArraySchema.java b/java/src/main/java/org/msgpack/schema/IArraySchema.java
deleted file mode 100644
index 67e9f55..0000000
--- a/java/src/main/java/org/msgpack/schema/IArraySchema.java
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import org.msgpack.Schema;
-
-public interface IArraySchema {
-	public Schema getElementSchema(int index);
-	public Object createFromArray(Object[] obj);
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/IMapSchema.java b/java/src/main/java/org/msgpack/schema/IMapSchema.java
deleted file mode 100644
index 3a2f556..0000000
--- a/java/src/main/java/org/msgpack/schema/IMapSchema.java
+++ /dev/null
@@ -1,27 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import org.msgpack.Schema;
-
-public interface IMapSchema {
-	public Schema getKeySchema();
-	public Schema getValueSchema();
-	public Object createFromMap(Object[] obj);
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/IntSchema.java b/java/src/main/java/org/msgpack/schema/IntSchema.java
deleted file mode 100644
index 269f4fb..0000000
--- a/java/src/main/java/org/msgpack/schema/IntSchema.java
+++ /dev/null
@@ -1,96 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.io.IOException;
-import org.msgpack.*;
-
-public class IntSchema extends Schema {
-	public IntSchema() { }
-
-	@Override
-	public String getClassName() {
-		return "Integer";
-	}
-
-	@Override
-	public String getExpression() {
-		return "int";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof Number) {
-			int value = ((Number)obj).intValue();
-			if(value >= Short.MAX_VALUE) {
-				long lvalue = ((Number)obj).longValue();
-				if(lvalue > Integer.MAX_VALUE) {
-					throw new MessageTypeException();
-				}
-			}
-			pk.packInt(value);
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	public static final int convertInt(Object obj) throws MessageTypeException {
-		if(obj instanceof Number) {
-			int value = ((Number)obj).intValue();
-			if(value >= Integer.MAX_VALUE) {
-				long lvalue = ((Number)obj).longValue();
-				if(lvalue > Integer.MAX_VALUE) {
-					throw new MessageTypeException();
-				}
-			}
-			return value;
-		}
-		throw new MessageTypeException();
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return convertInt(obj);
-	}
-
-	@Override
-	public Object createFromByte(byte v) {
-		return (int)v;
-	}
-
-	@Override
-	public Object createFromShort(short v) {
-		return (int)v;
-	}
-
-	@Override
-	public Object createFromInt(int v) {
-		return (int)v;
-	}
-
-	@Override
-	public Object createFromLong(long v) {
-		if(v > Integer.MAX_VALUE) {
-			throw new MessageTypeException();
-		}
-		return (int)v;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/ListSchema.java b/java/src/main/java/org/msgpack/schema/ListSchema.java
deleted file mode 100644
index bef8cc4..0000000
--- a/java/src/main/java/org/msgpack/schema/ListSchema.java
+++ /dev/null
@@ -1,111 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.RandomAccess;
-import java.io.IOException;
-import org.msgpack.*;
-
-public class ListSchema extends Schema implements IArraySchema {
-	private Schema elementSchema;
-
-	public ListSchema(Schema elementSchema) {
-		this.elementSchema = elementSchema;
-	}
-
-	@Override
-	public String getClassName() {
-		return "List<"+elementSchema.getClassName()+">";
-	}
-
-	@Override
-	public String getExpression() {
-		return "(array "+elementSchema.getExpression()+")";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof List) {
-			List d = (List)obj;
-			pk.packArray(d.size());
-			if(obj instanceof RandomAccess) {
-				for(int i=0; i < d.size(); ++i) {
-					elementSchema.pack(pk, d.get(i));
-				}
-			} else {
-				for(Object e : d) {
-					elementSchema.pack(pk, e);
-				}
-			}
-		} else if(obj instanceof Set) {
-			Set d = (Set)obj;
-			pk.packArray(d.size());
-			for(Object e : d) {
-				elementSchema.pack(pk, e);
-			}
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	@SuppressWarnings("unchecked")
-	public static final  List convertList(Object obj,
-			Schema elementSchema, List dest) throws MessageTypeException {
-		if(!(obj instanceof List)) {
-			throw new MessageTypeException();
-		}
-		List d = (List)obj;
-		if(dest == null) {
-			dest = new ArrayList(d.size());
-		}
-		if(obj instanceof RandomAccess) {
-			for(int i=0; i < d.size(); ++i) {
-				dest.add( (T)elementSchema.convert(d.get(i)) );
-			}
-		} else {
-			for(Object e : d) {
-				dest.add( (T)elementSchema.convert(e) );
-			}
-		}
-		return dest;
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return convertList(obj, elementSchema, null);
-	}
-
-	@Override
-	public Schema getElementSchema(int index) {
-		return elementSchema;
-	}
-
-	@Override
-	public Object createFromArray(Object[] obj) {
-		return Arrays.asList(obj);
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/LongSchema.java b/java/src/main/java/org/msgpack/schema/LongSchema.java
deleted file mode 100644
index 728fa21..0000000
--- a/java/src/main/java/org/msgpack/schema/LongSchema.java
+++ /dev/null
@@ -1,80 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.io.IOException;
-import org.msgpack.*;
-
-public class LongSchema extends Schema {
-	public LongSchema() { }
-
-	@Override
-	public String getClassName() {
-		return "Long";
-	}
-
-	@Override
-	public String getExpression() {
-		return "long";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof Number) {
-			long value = ((Number)obj).longValue();
-			pk.packLong(value);
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	public static final long convertLong(Object obj) throws MessageTypeException {
-		if(obj instanceof Number) {
-			return ((Number)obj).longValue();
-		}
-		throw new MessageTypeException();
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return convertLong(obj);
-	}
-
-	@Override
-	public Object createFromByte(byte v) {
-		return (long)v;
-	}
-
-	@Override
-	public Object createFromShort(short v) {
-		return (long)v;
-	}
-
-	@Override
-	public Object createFromInt(int v) {
-		return (long)v;
-	}
-
-	@Override
-	public Object createFromLong(long v) {
-		return (long)v;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/MapSchema.java b/java/src/main/java/org/msgpack/schema/MapSchema.java
deleted file mode 100644
index 2e09af3..0000000
--- a/java/src/main/java/org/msgpack/schema/MapSchema.java
+++ /dev/null
@@ -1,106 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.io.IOException;
-import org.msgpack.*;
-
-public class MapSchema extends Schema implements IMapSchema {
-	private Schema keySchema;
-	private Schema valueSchema;
-
-	public MapSchema(Schema keySchema, Schema valueSchema) {
-		this.keySchema = keySchema;
-		this.valueSchema = valueSchema;
-	}
-
-	@Override
-	public String getClassName() {
-		return "Map<"+keySchema.getClassName()+", "+valueSchema.getClassName()+">";
-	}
-
-	@Override
-	public String getExpression() {
-		return "(map "+keySchema.getExpression()+" "+valueSchema.getExpression()+")";
-	}
-
-	@Override
-	@SuppressWarnings("unchecked")
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof Map) {
-			Map d = (Map)obj;
-			pk.packMap(d.size());
-			for(Map.Entry e : d.entrySet()) {
-				keySchema.pack(pk, e.getKey());
-				valueSchema.pack(pk, e.getValue());
-			}
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	@SuppressWarnings("unchecked")
-	public static final  Map convertMap(Object obj,
-			Schema keySchema, Schema valueSchema, Map dest) throws MessageTypeException {
-		if(!(obj instanceof Map)) {
-			throw new MessageTypeException();
-		}
-		Map d = (Map)obj;
-		if(dest == null) {
-			dest = new HashMap(d.size());
-		}
-		for(Map.Entry e : d.entrySet()) {
-			dest.put((K)keySchema.convert(e.getKey()),
-					(V)valueSchema.convert(e.getValue()));
-		}
-		return dest;
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return convertMap(obj, keySchema, valueSchema, null);
-	}
-
-	@Override
-	public Schema getKeySchema() {
-		return keySchema;
-	}
-
-	@Override
-	public Schema getValueSchema() {
-		return valueSchema;
-	}
-
-	@Override
-	@SuppressWarnings("unchecked")
-	public Object createFromMap(Object[] obj) {
-		HashMap dest = new HashMap(obj.length / 2);
-		int i = 0;
-		while(i < obj.length) {
-			Object k = obj[i++];
-			Object v = obj[i++];
-			dest.put(k, v);
-		}
-		return dest;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/ReflectionClassSchema.java b/java/src/main/java/org/msgpack/schema/ReflectionClassSchema.java
deleted file mode 100644
index fb94adf..0000000
--- a/java/src/main/java/org/msgpack/schema/ReflectionClassSchema.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.msgpack.schema;
-
-import java.util.Arrays;
-import java.util.List;
-import java.lang.reflect.*;
-import org.msgpack.*;
-
-// FIXME
-public abstract class ReflectionClassSchema extends ClassSchema {
-	private Constructor constructorCache;
-
-	public ReflectionClassSchema(String name, List fields, String namespace, List imports) {
-		super(name, namespace, imports, fields);
-	}
-
-	/*
-	Schema getElementSchema(int index)
-	{
-		// FIXME check index < fields.length
-		fields[index].getSchema();
-	}
-
-	Object createFromArray(Object[] obj)
-	{
-		Object o = newInstance();
-		((MessageConvertable)o).messageConvert(obj);
-		return o;
-	}
-
-	Object newInstance()
-	{
-		if(constructorCache == null) {
-			cacheConstructor();
-		}
-		try {
-			return constructorCache.newInstance((Object[])null);
-		} catch (InvocationTargetException e) {
-			throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
-		} catch (InstantiationException e) {
-			throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
-		} catch (IllegalAccessException e) {
-			throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
-		}
-	}
-
-	private void cacheConstructor()
-	{
-		try {
-			Class c = Class.forName(fqdn);
-			int index = 0;
-			for(SpecificFieldSchema f : fields) {
-				f.cacheField(c, index++);
-			}
-			constructorCache = c.getDeclaredConstructor((Class[])null);
-			constructorCache.setAccessible(true);
-		} catch(ClassNotFoundException e) {
-			throw new RuntimeException("class not found: "+fqdn);
-		} catch (NoSuchMethodException e) {
-			throw new RuntimeException("class not found: "+fqdn+": "+e.getMessage());
-		}
-	}
-	*/
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/SSchemaParser.java b/java/src/main/java/org/msgpack/schema/SSchemaParser.java
deleted file mode 100644
index 4345e92..0000000
--- a/java/src/main/java/org/msgpack/schema/SSchemaParser.java
+++ /dev/null
@@ -1,264 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Stack;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-import org.msgpack.*;
-
-// FIXME exception class
-
-public class SSchemaParser {
-	public static Schema parse(String source) {
-		return new SSchemaParser(false).run(source);
-	}
-
-	public static Schema load(String source) {
-		return new SSchemaParser(true).run(source);
-	}
-
-	private static abstract class SExp {
-		boolean isAtom() { return false; }
-		public String getAtom() { return null; }
-
-		boolean isTuple() { return false; }
-		public SExp getTuple(int i) { return null; }
-		public int size() { return 0; }
-		public boolean empty() { return size() == 0; }
-		Iterator iterator(int offset) { return null; }
-	}
-
-	private static class SAtom extends SExp {
-		private String atom;
-
-		SAtom(String atom) { this.atom = atom; }
-
-		boolean isAtom() { return true; }
-		public String getAtom() { return atom; }
-
-		public String toString() { return atom; }
-	}
-
-	private static class STuple extends SExp {
-		private List tuple;
-
-		STuple() { this.tuple = new ArrayList(); }
-
-		public void add(SExp e) { tuple.add(e); }
-
-		boolean isTuple() { return true; }
-		public SExp getTuple(int i) { return tuple.get(i); }
-		public int size() { return tuple.size(); }
-
-		Iterator iterator(int skip) {
-			Iterator i = tuple.iterator();
-			for(int s=0; s < skip; ++s) { i.next(); }
-			return i;
-		}
-
-		public String toString() {
-			if(tuple.isEmpty()) { return "()"; }
-			Iterator i = tuple.iterator();
-			StringBuffer o = new StringBuffer();
-			o.append("(").append(i.next());
-			while(i.hasNext()) { o.append(" ").append(i.next()); }
-			o.append(")");
-			return o.toString();
-		}
-	}
-
-	boolean specificClass;
-
-	private SSchemaParser(boolean specificClass) {
-		this.specificClass = specificClass;
-	}
-
-	private static Pattern pattern = Pattern.compile(
-			"(?:\\s+)|([\\(\\)]|[\\d\\w\\.]+)");
-
-	private Schema run(String source) {
-		Matcher m = pattern.matcher(source);
-
-		Stack stack = new Stack();
-		String token;
-
-		while(true) {
-			while(true) {
-				if(!m.find()) { throw new RuntimeException("unexpected end of file"); }
-				token = m.group(1);
-				if(token != null) { break; }
-			}
-
-			if(token.equals("(")) {
-				stack.push(new STuple());
-			} else if(token.equals(")")) {
-				STuple top = stack.pop();
-				if(stack.empty()) {
-					stack.push(top);
-					break;
-				}
-				stack.peek().add(top);
-			} else {
-				if(stack.empty()) {
-					throw new RuntimeException("unexpected token '"+token+"'");
-				}
-				stack.peek().add(new SAtom(token));
-			}
-		}
-
-		while(true) {
-			if(!m.find()) { break; }
-			token = m.group(1);
-			if(token != null) { throw new RuntimeException("unexpected token '"+token+"'"); }
-		}
-
-		return readType( stack.pop() );
-	}
-
-	private Schema readType(SExp exp) {
-		if(exp.isAtom()) {
-			String type = exp.getAtom();
-			if(type.equals("string")) {
-				return new StringSchema();
-			} else if(type.equals("raw")) {
-				return new ByteArraySchema();
-			} else if(type.equals("byte")) {
-				return new ByteSchema();
-			} else if(type.equals("short")) {
-				return new ShortSchema();
-			} else if(type.equals("int")) {
-				return new IntSchema();
-			} else if(type.equals("long")) {
-				return new LongSchema();
-			} else if(type.equals("float")) {
-				return new FloatSchema();
-			} else if(type.equals("double")) {
-				return new DoubleSchema();
-			} else if(type.equals("object")) {
-				return new GenericSchema();
-			} else {
-				throw new RuntimeException("byte, short, int, long, float, double, raw, string or object is expected but got '"+type+"': "+exp);
-			}
-		} else {
-			String type = exp.getTuple(0).getAtom();
-			if(type.equals("class")) {
-				return parseClass(exp);
-			} else if(type.equals("array")) {
-				return parseList(exp);
-			} else if(type.equals("set")) {
-				return parseSet(exp);
-			} else if(type.equals("map")) {
-				return parseMap(exp);
-			} else {
-				throw new RuntimeException("class, list, set or map is expected but got '"+type+"': "+exp);
-			}
-		}
-	}
-
-	private ClassSchema parseClass(SExp exp) {
-		if(exp.size() < 3 || !exp.getTuple(1).isAtom()) {
-			throw new RuntimeException("class is (class NAME CLASS_BODY): "+exp);
-		}
-
-		String namespace = null;
-		List imports = new ArrayList();
-		String name = exp.getTuple(1).getAtom();
-		List fields = new ArrayList();
-
-		for(Iterator i=exp.iterator(2); i.hasNext();) {
-			SExp subexp = i.next();
-			if(!subexp.isTuple() || subexp.empty() || !subexp.getTuple(0).isAtom()) {
-				throw new RuntimeException("field, package or import is expected: "+subexp);
-			}
-			String type = subexp.getTuple(0).getAtom();
-			if(type.equals("field")) {
-				fields.add( parseField(subexp) );
-			} else if(type.equals("package")) {
-				if(namespace != null) {
-					throw new RuntimeException("duplicated package definition: "+subexp);
-				}
-				namespace = parseNamespace(subexp);
-			} else if(type.equals("import")) {
-				imports.add( parseImport(subexp) );
-			} else {
-				throw new RuntimeException("field, package or import is expected but got '"+type+"': "+subexp);
-			}
-		}
-
-		if(specificClass) {
-			return new SpecificClassSchema(name, namespace, imports, fields);
-		} else {
-			return new GenericClassSchema(name, namespace, imports, fields);
-		}
-	}
-
-	private ListSchema parseList(SExp exp) {
-		if(exp.size() != 2) {
-			throw new RuntimeException("list is (list ELEMENT_TYPE): "+exp);
-		}
-		Schema elementType = readType(exp.getTuple(1));
-		return new ListSchema(elementType);
-	}
-
-	private SetSchema parseSet(SExp exp) {
-		if(exp.size() != 2) {
-			throw new RuntimeException("list is (list ELEMENT_TYPE): "+exp);
-		}
-		Schema elementType = readType(exp.getTuple(1));
-		return new SetSchema(elementType);
-	}
-
-	private MapSchema parseMap(SExp exp) {
-		if(exp.size() != 3 || !exp.getTuple(1).isAtom()) {
-			throw new RuntimeException("map is (map KEY_TYPE VALUE_TYPE): "+exp);
-		}
-		Schema keyType   = readType(exp.getTuple(1));
-		Schema valueType = readType(exp.getTuple(2));
-		return new MapSchema(keyType, valueType);
-	}
-
-	private String parseNamespace(SExp exp) {
-		if(exp.size() != 2 || !exp.getTuple(1).isAtom()) {
-			throw new RuntimeException("package is (package NAME): "+exp);
-		}
-		String name = exp.getTuple(1).getAtom();
-		return name;
-	}
-
-	private String parseImport(SExp exp) {
-		if(exp.size() != 2 || !exp.getTuple(1).isAtom()) {
-			throw new RuntimeException("import is (import NAME): "+exp);
-		}
-		String name = exp.getTuple(1).getAtom();
-		return name;
-	}
-
-	private FieldSchema parseField(SExp exp) {
-		if(exp.size() != 3 || !exp.getTuple(1).isAtom()) {
-			throw new RuntimeException("field is (field NAME TYPE): "+exp);
-		}
-		String name = exp.getTuple(1).getAtom();
-		Schema type = readType(exp.getTuple(2));
-		return new FieldSchema(name, type);
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/SetSchema.java b/java/src/main/java/org/msgpack/schema/SetSchema.java
deleted file mode 100644
index a3e1974..0000000
--- a/java/src/main/java/org/msgpack/schema/SetSchema.java
+++ /dev/null
@@ -1,115 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.RandomAccess;
-import java.io.IOException;
-import org.msgpack.*;
-
-public class SetSchema extends Schema implements IArraySchema {
-	private Schema elementSchema;
-
-	public SetSchema(Schema elementSchema) {
-		this.elementSchema = elementSchema;
-	}
-
-	@Override
-	public String getClassName() {
-		return "Set<"+elementSchema.getClassName()+">";
-	}
-
-	@Override
-	public String getExpression() {
-		return "(set "+elementSchema.getExpression()+")";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof List) {
-			List d = (List)obj;
-			pk.packArray(d.size());
-			if(obj instanceof RandomAccess) {
-				for(int i=0; i < d.size(); ++i) {
-					elementSchema.pack(pk, d.get(i));
-				}
-			} else {
-				for(Object e : d) {
-					elementSchema.pack(pk, e);
-				}
-			}
-		} else if(obj instanceof Set) {
-			Set d = (Set)obj;
-			pk.packArray(d.size());
-			for(Object e : d) {
-				elementSchema.pack(pk, e);
-			}
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	@SuppressWarnings("unchecked")
-	public static final  Set convertSet(Object obj,
-			Schema elementSchema, Set dest) throws MessageTypeException {
-		if(!(obj instanceof List)) {
-			throw new MessageTypeException();
-		}
-		List d = (List)obj;
-		if(dest == null) {
-			dest = new HashSet(d.size());
-		}
-		if(obj instanceof RandomAccess) {
-			for(int i=0; i < d.size(); ++i) {
-				dest.add( (T)elementSchema.convert(d.get(i)) );
-			}
-		} else {
-			for(Object e : d) {
-				dest.add( (T)elementSchema.convert(e) );
-			}
-		}
-		return dest;
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return convertSet(obj, elementSchema, null);
-	}
-
-	@Override
-	public Schema getElementSchema(int index) {
-		return elementSchema;
-	}
-
-	@Override
-	public Object createFromArray(Object[] obj) {
-		Set m = new HashSet(obj.length);
-		for(int i=0; i < obj.length; i++) {
-			m.add(obj[i]);
-		}
-		return m;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/ShortSchema.java b/java/src/main/java/org/msgpack/schema/ShortSchema.java
deleted file mode 100644
index 21b9327..0000000
--- a/java/src/main/java/org/msgpack/schema/ShortSchema.java
+++ /dev/null
@@ -1,93 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.io.IOException;
-import org.msgpack.*;
-
-public class ShortSchema extends Schema {
-	public ShortSchema() { }
-
-	@Override
-	public String getClassName() {
-		return "Short";
-	}
-
-	@Override
-	public String getExpression() {
-		return "short";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof Number) {
-			int value = ((Number)obj).intValue();
-			if(value > Short.MAX_VALUE) {
-				throw new MessageTypeException();
-			}
-			pk.packShort((short)value);
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	public static final short convertShort(Object obj) throws MessageTypeException {
-		if(obj instanceof Number) {
-			int value = ((Number)obj).intValue();
-			if(value > Short.MAX_VALUE) {
-				throw new MessageTypeException();
-			}
-			return (short)value;
-		}
-		throw new MessageTypeException();
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return convertShort(obj);
-	}
-
-	@Override
-	public Object createFromByte(byte v) {
-		return (short)v;
-	}
-
-	@Override
-	public Object createFromShort(short v) {
-		return (short)v;
-	}
-
-	@Override
-	public Object createFromInt(int v) {
-		if(v > Short.MAX_VALUE) {
-			throw new MessageTypeException();
-		}
-		return (short)v;
-	}
-
-	@Override
-	public Object createFromLong(long v) {
-		if(v > Short.MAX_VALUE) {
-			throw new MessageTypeException();
-		}
-		return (short)v;
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/SpecificClassSchema.java b/java/src/main/java/org/msgpack/schema/SpecificClassSchema.java
deleted file mode 100644
index 850f621..0000000
--- a/java/src/main/java/org/msgpack/schema/SpecificClassSchema.java
+++ /dev/null
@@ -1,122 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.util.Collection;
-import java.util.List;
-import java.lang.reflect.*;
-import java.io.IOException;
-import org.msgpack.*;
-
-public class SpecificClassSchema extends ClassSchema {
-	private Class classCache;
-	private Method factoryCache;
-	private Constructor constructorCache;
-
-	public SpecificClassSchema(
-			String name, String namespace,
-			List imports, List fields) {
-		super(name, namespace, imports, fields);
-	}
-
-	@Override
-	@SuppressWarnings("unchecked")
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj == null) {
-			pk.packNil();
-			return;
-		}
-		if(classCache == null) {
-			cacheFactory();
-		}
-		if(classCache.isInstance(obj)) {
-			((MessagePackable)obj).messagePack(pk);
-		} else {
-			// FIXME Map
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		if(obj instanceof Collection) {
-			if(constructorCache == null) {
-				cacheConstructor();
-			}
-			try {
-				MessageConvertable o = (MessageConvertable)constructorCache.newInstance((Object[])null);
-				o.messageConvert(obj);
-				return o;
-			} catch (InvocationTargetException e) {
-				throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
-			} catch (InstantiationException e) {
-				throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
-			} catch (IllegalAccessException e) {
-				throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
-			}
-
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	public Schema getElementSchema(int index) {
-		// FIXME check index < fields.length
-		return fields[index].getSchema();
-	}
-
-	public Object createFromArray(Object[] obj) {
-		if(factoryCache == null) {
-			cacheFactory();
-		}
-		try {
-			return factoryCache.invoke(null, new Object[]{obj});
-		} catch (InvocationTargetException e) {
-			throw new RuntimeException("can't instantiate "+fqdn+": "+e.getCause());
-		} catch (IllegalAccessException e) {
-			throw new RuntimeException("can't instantiate "+fqdn+": "+e.getMessage());
-		}
-	}
-
-	@SuppressWarnings("unchecked")
-	private void cacheFactory() {
-		try {
-			classCache = Class.forName(fqdn);
-			factoryCache = classCache.getDeclaredMethod("createFromMessage", new Class[]{Object[].class});
-			factoryCache.setAccessible(true);
-		} catch(ClassNotFoundException e) {
-			throw new RuntimeException("class not found: "+fqdn);
-		} catch (NoSuchMethodException e) {
-			throw new RuntimeException("class not found: "+fqdn+": "+e.getMessage());
-		}
-	}
-
-	@SuppressWarnings("unchecked")
-	private void cacheConstructor() {
-		try {
-			classCache = Class.forName(fqdn);
-			constructorCache = classCache.getDeclaredConstructor((Class[])null);
-			constructorCache.setAccessible(true);
-		} catch(ClassNotFoundException e) {
-			throw new RuntimeException("class not found: "+fqdn);
-		} catch (NoSuchMethodException e) {
-			throw new RuntimeException("class not found: "+fqdn+": "+e.getMessage());
-		}
-	}
-}
-
diff --git a/java/src/main/java/org/msgpack/schema/StringSchema.java b/java/src/main/java/org/msgpack/schema/StringSchema.java
deleted file mode 100644
index 23e4e64..0000000
--- a/java/src/main/java/org/msgpack/schema/StringSchema.java
+++ /dev/null
@@ -1,102 +0,0 @@
-//
-// MessagePack for Java
-//
-// Copyright (C) 2009-2010 FURUHASHI Sadayuki
-//
-//    Licensed under the Apache License, Version 2.0 (the "License");
-//    you may not use this file except in compliance with the License.
-//    You may obtain a copy of the License at
-//
-//        http://www.apache.org/licenses/LICENSE-2.0
-//
-//    Unless required by applicable law or agreed to in writing, software
-//    distributed under the License is distributed on an "AS IS" BASIS,
-//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//    See the License for the specific language governing permissions and
-//    limitations under the License.
-//
-package org.msgpack.schema;
-
-import java.nio.ByteBuffer;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import org.msgpack.*;
-
-public class StringSchema extends Schema {
-	public StringSchema() { }
-
-	@Override
-	public String getClassName() {
-		return "String";
-	}
-
-	@Override
-	public String getExpression() {
-		return "string";
-	}
-
-	@Override
-	public void pack(Packer pk, Object obj) throws IOException {
-		if(obj instanceof byte[]) {
-			byte[] b = (byte[])obj;
-			pk.packRaw(b.length);
-			pk.packRawBody(b);
-		} else if(obj instanceof String) {
-			try {
-				byte[] b = ((String)obj).getBytes("UTF-8");
-				pk.packRaw(b.length);
-				pk.packRawBody(b);
-			} catch (UnsupportedEncodingException e) {
-				throw new MessageTypeException();
-			}
-		} else if(obj == null) {
-			pk.packNil();
-		} else {
-			throw MessageTypeException.invalidConvert(obj, this);
-		}
-	}
-
-	public static final String convertString(Object obj) throws MessageTypeException {
-		if(obj instanceof byte[]) {
-			try {
-				return new String((byte[])obj, "UTF-8");
-			} catch (UnsupportedEncodingException e) {
-				throw new MessageTypeException();
-			}
-		} else if(obj instanceof String) {
-			return (String)obj;
-		} else if(obj instanceof ByteBuffer) {
-			ByteBuffer d = (ByteBuffer)obj;
-			try {
-				if(d.hasArray()) {
-					return new String(d.array(), d.position(), d.capacity(), "UTF-8");
-				} else {
-					byte[] v = new byte[d.capacity()];
-					int pos = d.position();
-					d.get(v);
-					d.position(pos);
-					return new String(v, "UTF-8");
-				}
-			} catch (UnsupportedEncodingException e) {
-				throw new MessageTypeException();
-			}
-		} else {
-			throw new MessageTypeException();
-		}
-	}
-
-	@Override
-	public Object convert(Object obj) throws MessageTypeException {
-		return convertString(obj);
-	}
-
-	@Override
-	public Object createFromRaw(byte[] b, int offset, int length) {
-		try {
-			return new String(b, offset, length, "UTF-8");
-		} catch (Exception e) {
-			throw new RuntimeException(e.getMessage());
-		}
-	}
-}
-
diff --git a/java/src/test/java/org/msgpack/TestPackUnpack.java b/java/src/test/java/org/msgpack/TestPackUnpack.java
index b02bbb4..ca3d235 100644
--- a/java/src/test/java/org/msgpack/TestPackUnpack.java
+++ b/java/src/test/java/org/msgpack/TestPackUnpack.java
@@ -8,240 +8,223 @@ import org.junit.Test;
 import static org.junit.Assert.*;
 
 public class TestPackUnpack {
-    protected Object unpackOne(ByteArrayOutputStream out) {
-        return unpackOne(out, null);
-    }
-    protected Object unpackOne(ByteArrayOutputStream out, Schema schema) {
-        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-        Unpacker upk = new Unpacker(in);
-        if (schema != null)
-            upk = upk.useSchema(schema);
-        Iterator it = upk.iterator();
-        assertEquals(true, it.hasNext());
-        Object obj = it.next();
-        assertEquals(false, it.hasNext());
-        return obj;
-    }
-
-    @Test
-    public void testInt() throws Exception {
-        testInt(0);
-        testInt(-1);
-        testInt(1);
-        testInt(Integer.MIN_VALUE);
-        testInt(Integer.MAX_VALUE);
-        Random rand = new Random();
-        for (int i = 0; i < 1000; i++)
-            testInt(rand.nextInt());
-    }
-    public void testInt(int val) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).pack(val);
-        Object obj = unpackOne(out);
-        if (obj instanceof Byte)
-            assertEquals(val, ((Byte)obj).intValue());
-        else if (obj instanceof Integer)
-            assertEquals(val, ((Integer)obj).intValue());
-        else if (obj instanceof Short)
-            assertEquals(val, ((Short)obj).intValue());
-        else if (obj instanceof Long)
-            assertEquals(val, ((Long)obj).intValue());
-        else {
-            System.out.println("Got unexpected class: " + obj.getClass());
-            assertTrue(false);
-        }
-    }
-
-    @Test
-    public void testFloat() throws Exception {
-        testFloat((float)0.0);
-        testFloat((float)-0.0);
-        testFloat((float)1.0);
-        testFloat((float)-1.0);
-        testFloat((float)Float.MAX_VALUE);
-        testFloat((float)Float.MIN_VALUE);
-        testFloat((float)Float.NaN);
-        testFloat((float)Float.NEGATIVE_INFINITY);
-        testFloat((float)Float.POSITIVE_INFINITY);
-        Random rand = new Random();
-        for (int i = 0; i < 1000; i++)
-            testFloat(rand.nextFloat());
-    }
-    public void testFloat(float val) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).pack(val);
-        Object obj = unpackOne(out);
-        if (obj instanceof Float)
-            assertEquals(val, ((Float)obj).floatValue(), 10e-10);
-        else {
-            System.out.println("Got unexpected class: " + obj.getClass());
-            assertTrue(false);
-        }
-    }
-
-    @Test
-    public void testDouble() throws Exception {
-        testDouble((double)0.0);
-        testDouble((double)-0.0);
-        testDouble((double)1.0);
-        testDouble((double)-1.0);
-        testDouble((double)Double.MAX_VALUE);
-        testDouble((double)Double.MIN_VALUE);
-        testDouble((double)Double.NaN);
-        testDouble((double)Double.NEGATIVE_INFINITY);
-        testDouble((double)Double.POSITIVE_INFINITY);
-        Random rand = new Random();
-        for (int i = 0; i < 1000; i++)
-            testDouble(rand.nextDouble());
-    }
-    public void testDouble(double val) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).pack(val);
-        Object obj = unpackOne(out);
-        if (obj instanceof Double)
-            assertEquals(val, ((Double)obj).doubleValue(), 10e-10);
-        else {
-            System.out.println("Got unexpected class: " + obj.getClass());
-            assertTrue(false);
-        }
-    }
-
-    @Test
-    public void testNil() throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).packNil();
-        Object obj = unpackOne(out);
-        assertEquals(null, obj);
-    }
-
-    @Test
-    public void testBoolean() throws Exception {
-        testBoolean(false);
-        testBoolean(true);
-    }
-    public void testBoolean(boolean val) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).pack(val);
-        Object obj = unpackOne(out);
-        if (obj instanceof Boolean)
-            assertEquals(val, ((Boolean)obj).booleanValue());
-        else {
-            System.out.println("Got unexpected class: " + obj.getClass());
-            assertTrue(false);
-        }
-    }
-
-    @Test
-    public void testString() throws Exception {
-        testString("");
-        testString("a");
-        testString("ab");
-        testString("abc");
-        // small size string
-        for (int i = 0; i < 100; i++) {
-            StringBuilder sb = new StringBuilder();
-            int len = (int)Math.random() % 31 + 1;
-            for (int j = 0; j < len; j++)
-                sb.append('a' + ((int)Math.random()) & 26);
-            testString(sb.toString());
-        }
-        // medium size string
-        for (int i = 0; i < 100; i++) {
-            StringBuilder sb = new StringBuilder();
-            int len = (int)Math.random() % 100 + (1 << 15);
-            for (int j = 0; j < len; j++)
-                sb.append('a' + ((int)Math.random()) & 26);
-            testString(sb.toString());
-        }
-        // large size string
-        for (int i = 0; i < 10; i++) {
-            StringBuilder sb = new StringBuilder();
-            int len = (int)Math.random() % 100 + (1 << 31);
-            for (int j = 0; j < len; j++)
-                sb.append('a' + ((int)Math.random()) & 26);
-            testString(sb.toString());
-        }
-    }
-    public void testString(String val) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).pack(val);
-        Object obj = unpackOne(out);
-        if (obj instanceof byte[])
-            assertEquals(val, new String((byte[])obj));
-        else {
-            System.out.println("obj=" + obj);
-            System.out.println("Got unexpected class: " + obj.getClass());
-            assertTrue(false);
-        }
-    }
-
-    @Test
-    public void testArray() throws Exception {
-        List emptyList = new ArrayList();
-        testArray(emptyList, Schema.parse("(array int)"));
-
-        for (int i = 0; i < 1000; i++) {
-            Schema schema = Schema.parse("(array int)");
-            List l = new ArrayList();
-            int len = (int)Math.random() % 1000 + 1;
-            for (int j = 0; j < len; j++)
-                l.add(j);
-            testArray(l, schema);
-        }
-        for (int i = 0; i < 1000; i++) {
-            Schema schema = Schema.parse("(array string)");
-            List l = new ArrayList();
-            int len = (int)Math.random() % 1000 + 1;
-            for (int j = 0; j < len; j++)
-                l.add(Integer.toString(j));
-            testArray(l, schema);
-        }
-    }
-    public void testArray(List val, Schema schema) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).pack(val);
-        Object obj = unpackOne(out, schema);
-        if (obj instanceof List)
-            assertTrue(val.equals(obj));
-        else {
-            System.out.println("obj=" + obj);
-            System.out.println("Got unexpected class: " + obj.getClass());
-            assertTrue(false);
-        }
-    }
-
-    @Test
-    public void testMap() throws Exception {
-        Map emptyMap = new HashMap();
-        testMap(emptyMap, Schema.parse("(map int int)"));
-
-        for (int i = 0; i < 1000; i++) {
-            Schema schema = Schema.parse("(map int int)");
-            Map m = new HashMap();
-            int len = (int)Math.random() % 1000 + 1;
-            for (int j = 0; j < len; j++)
-                m.put(j, j);
-            testMap(m, schema);
-        }
-        for (int i = 0; i < 1000; i++) {
-            Schema schema = Schema.parse("(map string int)");
-            Map m = new HashMap();
-            int len = (int)Math.random() % 1000 + 1;
-            for (int j = 0; j < len; j++)
-                m.put(Integer.toString(j), j);
-            testMap(m, schema);
-        }
-    }
-    public void testMap(Map val, Schema schema) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).pack(val);
-        Object obj = unpackOne(out, schema);
-        if (obj instanceof Map)
-            assertTrue(val.equals(obj));
-        else {
-            System.out.println("obj=" + obj);
-            System.out.println("Got unexpected class: " + obj.getClass());
-            assertTrue(false);
-        }
-    }
+	public MessagePackObject unpackOne(ByteArrayOutputStream out) {
+		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+		Unpacker upk = new Unpacker(in);
+		Iterator it = upk.iterator();
+		assertEquals(true, it.hasNext());
+		MessagePackObject obj = it.next();
+		assertEquals(false, it.hasNext());
+		return obj;
+	}
+
+	public void testInt(int val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		MessagePackObject obj = unpackOne(out);
+		assertEquals(val, obj.asInt());
+	}
+	@Test
+	public void testInt() throws Exception {
+		testInt(0);
+		testInt(-1);
+		testInt(1);
+		testInt(Integer.MIN_VALUE);
+		testInt(Integer.MAX_VALUE);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testInt(rand.nextInt());
+	}
+
+	public void testFloat(float val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		MessagePackObject obj = unpackOne(out);
+		assertEquals(val, obj.asFloat(), 10e-10);
+	}
+	@Test
+	public void testFloat() throws Exception {
+		testFloat((float)0.0);
+		testFloat((float)-0.0);
+		testFloat((float)1.0);
+		testFloat((float)-1.0);
+		testFloat((float)Float.MAX_VALUE);
+		testFloat((float)Float.MIN_VALUE);
+		testFloat((float)Float.NaN);
+		testFloat((float)Float.NEGATIVE_INFINITY);
+		testFloat((float)Float.POSITIVE_INFINITY);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testFloat(rand.nextFloat());
+	}
+
+	public void testDouble(double val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		MessagePackObject obj = unpackOne(out);
+		assertEquals(val, obj.asDouble(), 10e-10);
+	}
+	@Test
+	public void testDouble() throws Exception {
+		testDouble((double)0.0);
+		testDouble((double)-0.0);
+		testDouble((double)1.0);
+		testDouble((double)-1.0);
+		testDouble((double)Double.MAX_VALUE);
+		testDouble((double)Double.MIN_VALUE);
+		testDouble((double)Double.NaN);
+		testDouble((double)Double.NEGATIVE_INFINITY);
+		testDouble((double)Double.POSITIVE_INFINITY);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testDouble(rand.nextDouble());
+	}
+
+	@Test
+	public void testNil() throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).packNil();
+		MessagePackObject obj = unpackOne(out);
+		assertTrue(obj.isNull());
+	}
+
+	@Test
+	public void testBoolean() throws Exception {
+		testBoolean(false);
+		testBoolean(true);
+	}
+	public void testBoolean(boolean val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		MessagePackObject obj = unpackOne(out);
+		assertEquals(val, obj.asBoolean());
+	}
+
+	public void testString(String val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		MessagePackObject obj = unpackOne(out);
+		assertEquals(val, obj.asString());
+	}
+	@Test
+	public void testString() throws Exception {
+		testString("");
+		testString("a");
+		testString("ab");
+		testString("abc");
+
+		// small size string
+		for (int i = 0; i < 100; i++) {
+			StringBuilder sb = new StringBuilder();
+			int len = (int)Math.random() % 31 + 1;
+			for (int j = 0; j < len; j++)
+				sb.append('a' + ((int)Math.random()) & 26);
+			testString(sb.toString());
+		}
+
+		// medium size string
+		for (int i = 0; i < 100; i++) {
+			StringBuilder sb = new StringBuilder();
+			int len = (int)Math.random() % 100 + (1 << 15);
+			for (int j = 0; j < len; j++)
+				sb.append('a' + ((int)Math.random()) & 26);
+			testString(sb.toString());
+		}
+
+		// large size string
+		for (int i = 0; i < 10; i++) {
+			StringBuilder sb = new StringBuilder();
+			int len = (int)Math.random() % 100 + (1 << 31);
+			for (int j = 0; j < len; j++)
+				sb.append('a' + ((int)Math.random()) & 26);
+			testString(sb.toString());
+		}
+	}
+
+	@Test
+	public void testArray() throws Exception {
+		List emptyList = new ArrayList();
+		{
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			new Packer(out).pack(emptyList);
+			MessagePackObject obj = unpackOne(out);
+			assertEquals(emptyList, obj.asList());
+		}
+
+		for (int i = 0; i < 1000; i++) {
+			List l = new ArrayList();
+			int len = (int)Math.random() % 1000 + 1;
+			for (int j = 0; j < len; j++)
+				l.add(j);
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			new Packer(out).pack(l);
+			MessagePackObject obj = unpackOne(out);
+			List list = obj.asList();
+			assertEquals(l.size(), list.size());
+			for (int j = 0; j < len; j++) {
+				assertEquals(l.get(j).intValue(), list.get(j).asInt());
+			}
+		}
+
+		for (int i = 0; i < 1000; i++) {
+			List l = new ArrayList();
+			int len = (int)Math.random() % 1000 + 1;
+			for (int j = 0; j < len; j++)
+				l.add(Integer.toString(j));
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			new Packer(out).pack(l);
+			MessagePackObject obj = unpackOne(out);
+			List list = obj.asList();
+			assertEquals(l.size(), list.size());
+			for (int j = 0; j < len; j++) {
+				assertEquals(l.get(j), list.get(j).asString());
+			}
+		}
+	}
+
+	@Test
+	public void testMap() throws Exception {
+		Map emptyMap = new HashMap();
+		{
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			new Packer(out).pack(emptyMap);
+			MessagePackObject obj = unpackOne(out);
+			assertEquals(emptyMap, obj.asMap());
+		}
+
+		for (int i = 0; i < 1000; i++) {
+			Map m = new HashMap();
+			int len = (int)Math.random() % 1000 + 1;
+			for (int j = 0; j < len; j++)
+				m.put(j, j);
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			new Packer(out).pack(m);
+			MessagePackObject obj = unpackOne(out);
+			Map map = obj.asMap();
+			assertEquals(m.size(), map.size());
+			for (Map.Entry pair : map.entrySet()) {
+				Integer val = m.get(pair.getKey().asInt());
+				assertNotNull(val);
+				assertEquals(val.intValue(), pair.getValue().asInt());
+			}
+		}
+
+		for (int i = 0; i < 1000; i++) {
+			Map m = new HashMap();
+			int len = (int)Math.random() % 1000 + 1;
+			for (int j = 0; j < len; j++)
+				m.put(Integer.toString(j), j);
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			new Packer(out).pack(m);
+			MessagePackObject obj = unpackOne(out);
+			Map map = obj.asMap();
+			assertEquals(m.size(), map.size());
+			for (Map.Entry pair : map.entrySet()) {
+				Integer val = m.get(pair.getKey().asString());
+				assertNotNull(val);
+				assertEquals(val.intValue(), pair.getValue().asInt());
+			}
+		}
+	}
 };
+
-- 
cgit v1.2.1


From 5658ca5b903b294dcccad0dfa6fa6a7bcd9acc12 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Wed, 18 Aug 2010 22:24:51 +0900
Subject: java: adds ObjectEquals test

---
 java/src/main/java/org/msgpack/UnpackerImpl.java   | 30 +++----
 .../main/java/org/msgpack/object/ArrayType.java    |  6 +-
 .../org/msgpack/object/BigIntegerTypeIMPL.java     |  2 +-
 .../main/java/org/msgpack/object/BooleanType.java  |  6 +-
 .../org/msgpack/object/LongIntegerTypeIMPL.java    |  2 +-
 java/src/main/java/org/msgpack/object/MapType.java |  6 +-
 java/src/main/java/org/msgpack/object/NilType.java |  6 ++
 java/src/main/java/org/msgpack/object/RawType.java | 20 ++++-
 .../test/java/org/msgpack/TestObjectEquals.java    | 96 ++++++++++++++++++++++
 9 files changed, 152 insertions(+), 22 deletions(-)
 create mode 100644 java/src/test/java/org/msgpack/TestObjectEquals.java

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/UnpackerImpl.java b/java/src/main/java/org/msgpack/UnpackerImpl.java
index f004e6c..cfd3d22 100644
--- a/java/src/main/java/org/msgpack/UnpackerImpl.java
+++ b/java/src/main/java/org/msgpack/UnpackerImpl.java
@@ -124,7 +124,7 @@ public class UnpackerImpl {
 					if((b & 0xe0) == 0xa0) {  // FixRaw
 						trail = b & 0x1f;
 						if(trail == 0) {
-							obj = new RawType(new byte[0]);
+							obj = RawType.create(new byte[0]);
 							break _push;
 						}
 						cs = ACS_RAW_VALUE;
@@ -139,7 +139,7 @@ public class UnpackerImpl {
 						//System.out.println("fixarray count:"+count);
 						obj = new MessagePackObject[count];
 						if(count == 0) {
-							obj = new ArrayType((MessagePackObject[])obj);
+							obj = ArrayType.create((MessagePackObject[])obj);
 							break _push;
 						}
 						++top;
@@ -159,7 +159,7 @@ public class UnpackerImpl {
 						count = b & 0x0f;
 						obj = new MessagePackObject[count*2];
 						if(count == 0) {
-							obj = new MapType((MessagePackObject[])obj);
+							obj = MapType.create((MessagePackObject[])obj);
 							break _push;
 						}
 						//System.out.println("fixmap count:"+count);
@@ -175,13 +175,13 @@ public class UnpackerImpl {
 	
 					switch(b & 0xff) {    // FIXME
 					case 0xc0:  // nil
-						obj = new NilType();
+						obj = NilType.create();
 						break _push;
 					case 0xc2:  // false
-						obj = new BooleanType(false);
+						obj = BooleanType.create(false);
 						break _push;
 					case 0xc3:  // true
-						obj = new BooleanType(true);
+						obj = BooleanType.create(true);
 						break _push;
 					case 0xca:  // float
 					case 0xcb:  // double
@@ -293,7 +293,7 @@ public class UnpackerImpl {
 						castBuffer.put(src, n, 2);
 						trail = ((int)castBuffer.getShort(0)) & 0xffff;
 						if(trail == 0) {
-							obj = new RawType(new byte[0]);
+							obj = RawType.create(new byte[0]);
 							break _push;
 						}
 						cs = ACS_RAW_VALUE;
@@ -304,14 +304,14 @@ public class UnpackerImpl {
 						// FIXME overflow check
 						trail = castBuffer.getInt(0) & 0x7fffffff;
 						if(trail == 0) {
-							obj = new RawType(new byte[0]);
+							obj = RawType.create(new byte[0]);
 							break _push;
 						}
 						cs = ACS_RAW_VALUE;
 					case ACS_RAW_VALUE: {
 							byte[] raw = new byte[trail];
 							System.arraycopy(src, n, raw, 0, trail);
-							obj = new RawType(raw);
+							obj = RawType.create(raw);
 						}
 						break _push;
 					case CS_ARRAY_16:
@@ -323,7 +323,7 @@ public class UnpackerImpl {
 						count = ((int)castBuffer.getShort(0)) & 0xffff;
 						obj = new MessagePackObject[count];
 						if(count == 0) {
-							obj = new ArrayType((MessagePackObject[])obj);
+							obj = ArrayType.create((MessagePackObject[])obj);
 							break _push;
 						}
 						++top;
@@ -344,7 +344,7 @@ public class UnpackerImpl {
 						count = castBuffer.getInt(0) & 0x7fffffff;
 						obj = new MessagePackObject[count];
 						if(count == 0) {
-							obj = new ArrayType((MessagePackObject[])obj);
+							obj = ArrayType.create((MessagePackObject[])obj);
 							break _push;
 						}
 						++top;
@@ -364,7 +364,7 @@ public class UnpackerImpl {
 						count = ((int)castBuffer.getShort(0)) & 0xffff;
 						obj = new MessagePackObject[count*2];
 						if(count == 0) {
-							obj = new MapType((MessagePackObject[])obj);
+							obj = MapType.create((MessagePackObject[])obj);
 							break _push;
 						}
 						//System.out.println("fixmap count:"+count);
@@ -386,7 +386,7 @@ public class UnpackerImpl {
 						count = castBuffer.getInt(0) & 0x7fffffff;
 						obj = new MessagePackObject[count*2];
 						if(count == 0) {
-							obj = new MapType((MessagePackObject[])obj);
+							obj = MapType.create((MessagePackObject[])obj);
 							break _push;
 						}
 						//System.out.println("fixmap count:"+count);
@@ -425,7 +425,7 @@ public class UnpackerImpl {
 							top_obj    = stack_obj[top];
 							top_ct     = stack_ct[top];
 							top_count  = stack_count[top];
-							obj = new ArrayType((MessagePackObject[])ar);
+							obj = ArrayType.create((MessagePackObject[])ar);
 							stack_obj[top] = null;
 							--top;
 							break _push;
@@ -447,7 +447,7 @@ public class UnpackerImpl {
 							top_obj    = stack_obj[top];
 							top_ct     = stack_ct[top];
 							top_count  = stack_count[top];
-							obj = new MapType((MessagePackObject[])mp);
+							obj = MapType.create((MessagePackObject[])mp);
 							stack_obj[top] = null;
 							--top;
 							break _push;
diff --git a/java/src/main/java/org/msgpack/object/ArrayType.java b/java/src/main/java/org/msgpack/object/ArrayType.java
index 350ce32..36134dc 100644
--- a/java/src/main/java/org/msgpack/object/ArrayType.java
+++ b/java/src/main/java/org/msgpack/object/ArrayType.java
@@ -25,10 +25,14 @@ import org.msgpack.*;
 public class ArrayType extends MessagePackObject {
 	private MessagePackObject[] array;
 
-	public ArrayType(MessagePackObject[] array) {
+	ArrayType(MessagePackObject[] array) {
 		this.array = array;
 	}
 
+	public static ArrayType create(MessagePackObject[] array) {
+		return new ArrayType(array);
+	}
+
 	@Override
 	public boolean isArrayType() {
 		return true;
diff --git a/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
index 7b060ee..b29879f 100644
--- a/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/BigIntegerTypeIMPL.java
@@ -109,7 +109,7 @@ class BigIntegerTypeIMPL extends IntegerType {
 	public boolean equals(Object obj) {
 		if(obj.getClass() != getClass()) {
 			if(obj.getClass() == ShortIntegerTypeIMPL.class) {
-				return BigInteger.valueOf((long)((ShortIntegerTypeIMPL)obj).shortValue()).equals(value);
+				return BigInteger.valueOf(((ShortIntegerTypeIMPL)obj).longValue()).equals(value);
 			} else if(obj.getClass() == LongIntegerTypeIMPL.class) {
 				return BigInteger.valueOf(((LongIntegerTypeIMPL)obj).longValue()).equals(value);
 			}
diff --git a/java/src/main/java/org/msgpack/object/BooleanType.java b/java/src/main/java/org/msgpack/object/BooleanType.java
index 1d12c1c..65bd42b 100644
--- a/java/src/main/java/org/msgpack/object/BooleanType.java
+++ b/java/src/main/java/org/msgpack/object/BooleanType.java
@@ -23,10 +23,14 @@ import org.msgpack.*;
 public class BooleanType extends MessagePackObject {
 	private boolean value;
 
-	public BooleanType(boolean value) {
+	BooleanType(boolean value) {
 		this.value = value;
 	}
 
+	public static BooleanType create(boolean value) {
+		return new BooleanType(value);
+	}
+
 	@Override
 	public boolean isBooleanType() {
 		return true;
diff --git a/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java b/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
index 3928a29..d052e77 100644
--- a/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
+++ b/java/src/main/java/org/msgpack/object/LongIntegerTypeIMPL.java
@@ -108,7 +108,7 @@ class LongIntegerTypeIMPL extends IntegerType {
 			if(obj.getClass() == ShortIntegerTypeIMPL.class) {
 				return value == ((ShortIntegerTypeIMPL)obj).longValue();
 			} else if(obj.getClass() == BigIntegerTypeIMPL.class) {
-				return (long)value == ((BigIntegerTypeIMPL)obj).longValue();
+				return BigInteger.valueOf(value).equals(((BigIntegerTypeIMPL)obj).bigIntegerValue());
 			}
 			return false;
 		}
diff --git a/java/src/main/java/org/msgpack/object/MapType.java b/java/src/main/java/org/msgpack/object/MapType.java
index 619d388..148c0bf 100644
--- a/java/src/main/java/org/msgpack/object/MapType.java
+++ b/java/src/main/java/org/msgpack/object/MapType.java
@@ -26,10 +26,14 @@ import org.msgpack.*;
 public class MapType extends MessagePackObject {
 	private MessagePackObject[] map;
 
-	public MapType(MessagePackObject[] map) {
+	MapType(MessagePackObject[] map) {
 		this.map = map;
 	}
 
+	public static MapType create(MessagePackObject[] map) {
+		return new MapType(map);
+	}
+
 	@Override
 	public boolean isMapType() {
 		return true;
diff --git a/java/src/main/java/org/msgpack/object/NilType.java b/java/src/main/java/org/msgpack/object/NilType.java
index ece62f0..d0572f1 100644
--- a/java/src/main/java/org/msgpack/object/NilType.java
+++ b/java/src/main/java/org/msgpack/object/NilType.java
@@ -21,6 +21,12 @@ import java.io.IOException;
 import org.msgpack.*;
 
 public class NilType extends MessagePackObject {
+	private static NilType instance = new NilType();
+
+	public static NilType create() {
+		return instance;
+	}
+
 	@Override
 	public boolean isNull() {
 		return true;
diff --git a/java/src/main/java/org/msgpack/object/RawType.java b/java/src/main/java/org/msgpack/object/RawType.java
index 3a39486..26f6e0d 100644
--- a/java/src/main/java/org/msgpack/object/RawType.java
+++ b/java/src/main/java/org/msgpack/object/RawType.java
@@ -24,10 +24,26 @@ import org.msgpack.*;
 public class RawType extends MessagePackObject {
 	private byte[] bytes;
 
-	public RawType(byte[] bytes) {
+	RawType(byte[] bytes) {
 		this.bytes = bytes;
 	}
 
+	RawType(String str) {
+		try {
+			this.bytes = str.getBytes("UTF-8");
+		} catch (Exception e) {
+			throw new MessageTypeException("type error");
+		}
+	}
+
+	public static RawType create(byte[] bytes) {
+		return new RawType(bytes);
+	}
+
+	public static RawType create(String str) {
+		return new RawType(str);
+	}
+
 	@Override
 	public boolean isRawType() {
 		return true;
@@ -58,7 +74,7 @@ public class RawType extends MessagePackObject {
 		if(obj.getClass() != getClass()) {
 			return false;
 		}
-		return ((RawType)obj).bytes.equals(bytes);
+		return Arrays.equals(((RawType)obj).bytes, bytes);
 	}
 
 	@Override
diff --git a/java/src/test/java/org/msgpack/TestObjectEquals.java b/java/src/test/java/org/msgpack/TestObjectEquals.java
new file mode 100644
index 0000000..b2b018d
--- /dev/null
+++ b/java/src/test/java/org/msgpack/TestObjectEquals.java
@@ -0,0 +1,96 @@
+package org.msgpack;
+
+import org.msgpack.*;
+import org.msgpack.object.*;
+import java.math.BigInteger;
+import java.util.*;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TestObjectEquals {
+	public void testInt(int val) throws Exception {
+		MessagePackObject objInt = IntegerType.create(val);
+		MessagePackObject objLong = IntegerType.create((long)val);
+		MessagePackObject objBigInt = IntegerType.create(BigInteger.valueOf((long)val));
+		assertTrue(objInt.equals(objInt));
+		assertTrue(objInt.equals(objLong));
+		assertTrue(objInt.equals(objBigInt));
+		assertTrue(objLong.equals(objInt));
+		assertTrue(objLong.equals(objLong));
+		assertTrue(objLong.equals(objBigInt));
+		assertTrue(objBigInt.equals(objInt));
+		assertTrue(objBigInt.equals(objLong));
+		assertTrue(objBigInt.equals(objBigInt));
+	}
+	@Test
+	public void testInt() throws Exception {
+		testInt(0);
+		testInt(-1);
+		testInt(1);
+		testInt(Integer.MIN_VALUE);
+		testInt(Integer.MAX_VALUE);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testInt(rand.nextInt());
+	}
+
+	public void testLong(long val) throws Exception {
+		MessagePackObject objInt = IntegerType.create((int)val);
+		MessagePackObject objLong = IntegerType.create(val);
+		MessagePackObject objBigInt = IntegerType.create(BigInteger.valueOf(val));
+		if(val > (long)Integer.MAX_VALUE || val < (long)Integer.MIN_VALUE) {
+			assertTrue(objInt.equals(objInt));
+			assertFalse(objInt.equals(objLong));
+			assertFalse(objInt.equals(objBigInt));
+			assertFalse(objLong.equals(objInt));
+			assertTrue(objLong.equals(objLong));
+			assertTrue(objLong.equals(objBigInt));
+			assertFalse(objBigInt.equals(objInt));
+			assertTrue(objBigInt.equals(objLong));
+			assertTrue(objBigInt.equals(objBigInt));
+		} else {
+			assertTrue(objInt.equals(objInt));
+			assertTrue(objInt.equals(objLong));
+			assertTrue(objInt.equals(objBigInt));
+			assertTrue(objLong.equals(objInt));
+			assertTrue(objLong.equals(objLong));
+			assertTrue(objLong.equals(objBigInt));
+			assertTrue(objBigInt.equals(objInt));
+			assertTrue(objBigInt.equals(objLong));
+			assertTrue(objBigInt.equals(objBigInt));
+		}
+	}
+	@Test
+	public void testLong() throws Exception {
+		testLong(0);
+		testLong(-1);
+		testLong(1);
+		testLong(Integer.MIN_VALUE);
+		testLong(Integer.MAX_VALUE);
+		testLong(Long.MIN_VALUE);
+		testLong(Long.MAX_VALUE);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testLong(rand.nextLong());
+	}
+
+	@Test
+	public void testNil() throws Exception {
+		assertTrue(NilType.create().equals(NilType.create()));
+		assertFalse(NilType.create().equals(IntegerType.create(0)));
+		assertFalse(NilType.create().equals(BooleanType.create(false)));
+	}
+
+	public void testString(String str) throws Exception {
+		assertTrue(RawType.create(str).equals(RawType.create(str)));
+	}
+	@Test
+	public void testString() throws Exception {
+		testString("");
+		testString("a");
+		testString("ab");
+		testString("abc");
+	}
+}
+
-- 
cgit v1.2.1


From fdfabc9f8862da5982830017e21b0628a00356eb Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Wed, 18 Aug 2010 22:51:23 +0900
Subject: java: adds cross-language test case

---
 java/src/main/java/org/msgpack/UnpackerImpl.java |   1 +
 java/src/test/java/org/msgpack/TestCases.java    |  46 +++++++++++++++++++++++
 java/src/test/resources/cases.json               |   1 +
 java/src/test/resources/cases.mpac               | Bin 0 -> 213 bytes
 java/src/test/resources/cases_compact.mpac       | Bin 0 -> 116 bytes
 5 files changed, 48 insertions(+)
 create mode 100644 java/src/test/java/org/msgpack/TestCases.java
 create mode 100644 java/src/test/resources/cases.json
 create mode 100644 java/src/test/resources/cases.mpac
 create mode 100644 java/src/test/resources/cases_compact.mpac

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/UnpackerImpl.java b/java/src/main/java/org/msgpack/UnpackerImpl.java
index cfd3d22..d4f99e3 100644
--- a/java/src/main/java/org/msgpack/UnpackerImpl.java
+++ b/java/src/main/java/org/msgpack/UnpackerImpl.java
@@ -308,6 +308,7 @@ public class UnpackerImpl {
 							break _push;
 						}
 						cs = ACS_RAW_VALUE;
+						break _fixed_trail_again;
 					case ACS_RAW_VALUE: {
 							byte[] raw = new byte[trail];
 							System.arraycopy(src, n, raw, 0, trail);
diff --git a/java/src/test/java/org/msgpack/TestCases.java b/java/src/test/java/org/msgpack/TestCases.java
new file mode 100644
index 0000000..632645f
--- /dev/null
+++ b/java/src/test/java/org/msgpack/TestCases.java
@@ -0,0 +1,46 @@
+package org.msgpack;
+
+import java.io.*;
+import java.util.*;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TestCases {
+	public void feedFile(Unpacker pac, String path) throws Exception {
+		FileInputStream input = new FileInputStream(path);
+		byte[] buffer = new byte[32*1024];
+		while(true) {
+			int count = input.read(buffer);
+			if(count < 0) {
+				break;
+			}
+			pac.feed(buffer, 0, count);
+		}
+	}
+
+	@Test
+	public void testCases() throws Exception {
+		System.out.println( new File(".").getAbsoluteFile().getParent() );
+
+
+		Unpacker pac = new Unpacker();
+		Unpacker pac_compact = new Unpacker();
+
+		feedFile(pac, "src/test/resources/cases.mpac");
+		feedFile(pac_compact, "src/test/resources/cases_compact.mpac");
+
+		UnpackResult result = new UnpackResult();
+		while(pac.next(result)) {
+			UnpackResult result_compact = new UnpackResult();
+			assertTrue( pac_compact.next(result_compact) );
+			System.out.println("obj: "+result_compact.getData());
+			if(!result.getData().equals(result_compact.getData())) {
+				System.out.println("compact: "+result_compact.getData().asString());
+				System.out.println("data   : "+result.getData().asString());
+			}
+			assertTrue( result.getData().equals(result_compact.getData()) );
+		}
+	}
+};
+
diff --git a/java/src/test/resources/cases.json b/java/src/test/resources/cases.json
new file mode 100644
index 0000000..fd390d4
--- /dev/null
+++ b/java/src/test/resources/cases.json
@@ -0,0 +1 @@
+[false,true,null,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,127,127,255,65535,4294967295,-32,-32,-128,-32768,-2147483648,0.0,-0.0,1.0,-1.0,"a","a","a","","","",[0],[0],[0],[],[],[],{},{},{},{"a":97},{"a":97},{"a":97},[[]],[["a"]]]
\ No newline at end of file
diff --git a/java/src/test/resources/cases.mpac b/java/src/test/resources/cases.mpac
new file mode 100644
index 0000000..5ec08c6
Binary files /dev/null and b/java/src/test/resources/cases.mpac differ
diff --git a/java/src/test/resources/cases_compact.mpac b/java/src/test/resources/cases_compact.mpac
new file mode 100644
index 0000000..8812442
Binary files /dev/null and b/java/src/test/resources/cases_compact.mpac differ
-- 
cgit v1.2.1


From d7469e469490b00f83b61d04e02cef856c805b93 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Wed, 18 Aug 2010 22:55:50 +0900
Subject: java: fixes cross-language test case

---
 java/src/test/java/org/msgpack/TestCases.java | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

(limited to 'java')

diff --git a/java/src/test/java/org/msgpack/TestCases.java b/java/src/test/java/org/msgpack/TestCases.java
index 632645f..c368972 100644
--- a/java/src/test/java/org/msgpack/TestCases.java
+++ b/java/src/test/java/org/msgpack/TestCases.java
@@ -21,9 +21,6 @@ public class TestCases {
 
 	@Test
 	public void testCases() throws Exception {
-		System.out.println( new File(".").getAbsoluteFile().getParent() );
-
-
 		Unpacker pac = new Unpacker();
 		Unpacker pac_compact = new Unpacker();
 
@@ -34,13 +31,10 @@ public class TestCases {
 		while(pac.next(result)) {
 			UnpackResult result_compact = new UnpackResult();
 			assertTrue( pac_compact.next(result_compact) );
-			System.out.println("obj: "+result_compact.getData());
-			if(!result.getData().equals(result_compact.getData())) {
-				System.out.println("compact: "+result_compact.getData().asString());
-				System.out.println("data   : "+result.getData().asString());
-			}
 			assertTrue( result.getData().equals(result_compact.getData()) );
 		}
+
+		assertFalse( pac_compact.next(result) );
 	}
 };
 
-- 
cgit v1.2.1


From 40dc9de6c9bc90a95e55d5d2999f7e45d34cabc8 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Wed, 18 Aug 2010 23:37:47 +0900
Subject: java: supports packing/unpacking of BigInteger less than
 0xffffffffffffffff

---
 .../main/java/org/msgpack/MessageConvertable.java  |  2 +-
 java/src/main/java/org/msgpack/Packer.java         | 22 ++++++++++--------
 java/src/main/java/org/msgpack/UnpackerImpl.java   |  5 ++--
 java/src/test/java/org/msgpack/TestPackUnpack.java | 27 ++++++++++++++++++++++
 4 files changed, 42 insertions(+), 14 deletions(-)

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/MessageConvertable.java b/java/src/main/java/org/msgpack/MessageConvertable.java
index da251dc..8acf1f2 100644
--- a/java/src/main/java/org/msgpack/MessageConvertable.java
+++ b/java/src/main/java/org/msgpack/MessageConvertable.java
@@ -18,6 +18,6 @@
 package org.msgpack;
 
 public interface MessageConvertable {
-	public void messageConvert(Object obj) throws MessageTypeException;
+	public void messageConvert(MessagePackObject obj) throws MessageTypeException;
 }
 
diff --git a/java/src/main/java/org/msgpack/Packer.java b/java/src/main/java/org/msgpack/Packer.java
index 98af3d6..60e04bf 100644
--- a/java/src/main/java/org/msgpack/Packer.java
+++ b/java/src/main/java/org/msgpack/Packer.java
@@ -196,19 +196,19 @@ public class Packer {
 	}
 
 	public Packer packBigInteger(BigInteger d) throws IOException {
-		if(d.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) <= 0) {
+		if(d.bitLength() <= 63) {
 			return packLong(d.longValue());
-		} else if(d.bitLength() <= 64) {
+		} else if(d.bitLength() <= 64 && d.signum() >= 0) {
 			castBytes[0] = (byte)0xcf;
 			byte[] barray = d.toByteArray();
-			castBytes[1] = barray[0];
-			castBytes[2] = barray[1];
-			castBytes[3] = barray[2];
-			castBytes[4] = barray[3];
-			castBytes[5] = barray[4];
-			castBytes[6] = barray[5];
-			castBytes[7] = barray[6];
-			castBytes[8] = barray[7];
+			castBytes[1] = barray[barray.length-8];
+			castBytes[2] = barray[barray.length-7];
+			castBytes[3] = barray[barray.length-6];
+			castBytes[4] = barray[barray.length-5];
+			castBytes[5] = barray[barray.length-4];
+			castBytes[6] = barray[barray.length-3];
+			castBytes[7] = barray[barray.length-2];
+			castBytes[8] = barray[barray.length-1];
 			out.write(castBytes);
 			return this;
 		} else {
@@ -436,6 +436,8 @@ public class Packer {
 			return packFloat((Float)o);
 		} else if(o instanceof Double) {
 			return packDouble((Double)o);
+		} else if(o instanceof BigInteger) {
+			return packBigInteger((BigInteger)o);
 		} else {
 			throw new MessageTypeException("unknown object "+o+" ("+o.getClass()+")");
 		}
diff --git a/java/src/main/java/org/msgpack/UnpackerImpl.java b/java/src/main/java/org/msgpack/UnpackerImpl.java
index d4f99e3..6a7085f 100644
--- a/java/src/main/java/org/msgpack/UnpackerImpl.java
+++ b/java/src/main/java/org/msgpack/UnpackerImpl.java
@@ -18,6 +18,7 @@
 package org.msgpack;
 
 import java.nio.ByteBuffer;
+import java.math.BigInteger;
 import org.msgpack.object.*;
 
 public class UnpackerImpl {
@@ -262,9 +263,7 @@ public class UnpackerImpl {
 						{
 							long o = castBuffer.getLong(0);
 							if(o < 0) {
-								// FIXME
-								//obj = GenericBigInteger.valueOf(o & 0x7fffffffL).setBit(31);
-								throw new UnpackException("uint 64 bigger than 0x7fffffff is not supported");
+								obj = IntegerType.create(new BigInteger(1, castBuffer.array()));
 							} else {
 								obj = IntegerType.create(o);
 							}
diff --git a/java/src/test/java/org/msgpack/TestPackUnpack.java b/java/src/test/java/org/msgpack/TestPackUnpack.java
index ca3d235..75c5fe7 100644
--- a/java/src/test/java/org/msgpack/TestPackUnpack.java
+++ b/java/src/test/java/org/msgpack/TestPackUnpack.java
@@ -3,6 +3,7 @@ package org.msgpack;
 import org.msgpack.*;
 import java.io.*;
 import java.util.*;
+import java.math.BigInteger;
 
 import org.junit.Test;
 import static org.junit.Assert.*;
@@ -36,6 +37,32 @@ public class TestPackUnpack {
 			testInt(rand.nextInt());
 	}
 
+	public void testBigInteger(BigInteger val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		MessagePackObject obj = unpackOne(out);
+		if(!val.equals(obj.asBigInteger())) {
+			System.out.println("expect: "+val);
+			System.out.println("but   : "+obj.asBigInteger());
+		}
+		assertEquals(val, obj.asBigInteger());
+	}
+	@Test
+	public void testBigInteger() throws Exception {
+		testBigInteger(BigInteger.valueOf(0));
+		testBigInteger(BigInteger.valueOf(-1));
+		testBigInteger(BigInteger.valueOf(1));
+		testBigInteger(BigInteger.valueOf(Integer.MIN_VALUE));
+		testBigInteger(BigInteger.valueOf(Integer.MAX_VALUE));
+		testBigInteger(BigInteger.valueOf(Long.MIN_VALUE));
+		testBigInteger(BigInteger.valueOf(Long.MAX_VALUE));
+		BigInteger max = BigInteger.valueOf(Long.MAX_VALUE).setBit(63);
+		testBigInteger(max);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testBigInteger( max.subtract(BigInteger.valueOf( Math.abs(rand.nextLong()) )) );
+	}
+
 	public void testFloat(float val) throws Exception {
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
 		new Packer(out).pack(val);
-- 
cgit v1.2.1


From 48da2b8353a640de6bdc4e59c7fe91b640321b27 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Wed, 18 Aug 2010 23:47:31 +0900
Subject: java: adds Packer.pack()

---
 java/src/main/java/org/msgpack/Packer.java         | 89 +++++++++++++++-------
 java/src/test/java/org/msgpack/TestPackUnpack.java | 24 +++++-
 2 files changed, 82 insertions(+), 31 deletions(-)

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/Packer.java b/java/src/main/java/org/msgpack/Packer.java
index 60e04bf..0ac8d89 100644
--- a/java/src/main/java/org/msgpack/Packer.java
+++ b/java/src/main/java/org/msgpack/Packer.java
@@ -315,39 +315,36 @@ public class Packer {
 	}
 
 
-	public Packer pack(String o) throws IOException {
-		if(o == null) { return packNil(); }
-		return packString(o);
+	public Packer pack(boolean o) throws IOException {
+		if(o) {
+			return packTrue();
+		} else {
+			return packFalse();
+		}
 	}
 
-	public Packer pack(MessagePackable o) throws IOException {
-		if(o == null) { return packNil(); }
-		o.messagePack(this);
-		return this;
+	public Packer pack(byte o) throws IOException {
+		return packByte(o);
 	}
 
-	public Packer pack(byte[] o) throws IOException {
-		if(o == null) { return packNil(); }
-		packRaw(o.length);
-		return packRawBody(o);
+	public Packer pack(short o) throws IOException {
+		return packShort(o);
 	}
 
-	public Packer pack(List o) throws IOException {
-		if(o == null) { return packNil(); }
-		packArray(o.size());
-		for(Object i : o) { pack(i); }
-		return this;
+	public Packer pack(int o) throws IOException {
+		return packInt(o);
 	}
 
-	@SuppressWarnings("unchecked")
-	public Packer pack(Map o) throws IOException {
-		if(o == null) { return packNil(); }
-		packMap(o.size());
-		for(Map.Entry e : ((Map)o).entrySet()) {
-			pack(e.getKey());
-			pack(e.getValue());
-		}
-		return this;
+	public Packer pack(long o) throws IOException {
+		return packLong(o);
+	}
+
+	public Packer pack(float o) throws IOException {
+		return packFloat(o);
+	}
+
+	public Packer pack(double o) throws IOException {
+		return packDouble(o);
 	}
 
 	public Packer pack(Boolean o) throws IOException {
@@ -379,6 +376,11 @@ public class Packer {
 		return packLong(o);
 	}
 
+	public Packer pack(BigInteger o) throws IOException {
+		if(o == null) { return packNil(); }
+		return packBigInteger(o);
+	}
+
 	public Packer pack(Float o) throws IOException {
 		if(o == null) { return packNil(); }
 		return packFloat(o);
@@ -389,8 +391,41 @@ public class Packer {
 		return packDouble(o);
 	}
 
+	public Packer pack(String o) throws IOException {
+		if(o == null) { return packNil(); }
+		return packString(o);
+	}
+
+	public Packer pack(MessagePackable o) throws IOException {
+		if(o == null) { return packNil(); }
+		o.messagePack(this);
+		return this;
+	}
+
+	public Packer pack(byte[] o) throws IOException {
+		if(o == null) { return packNil(); }
+		packRaw(o.length);
+		return packRawBody(o);
+	}
+
+	public Packer pack(List o) throws IOException {
+		if(o == null) { return packNil(); }
+		packArray(o.size());
+		for(Object i : o) { pack(i); }
+		return this;
+	}
+
+	public Packer pack(Map o) throws IOException {
+		if(o == null) { return packNil(); }
+		packMap(o.size());
+		for(Map.Entry e : ((Map)o).entrySet()) {
+			pack(e.getKey());
+			pack(e.getValue());
+		}
+		return this;
+	}
+
 
-	@SuppressWarnings("unchecked")
 	public Packer pack(Object o) throws IOException {
 		if(o == null) {
 			return packNil();
@@ -413,7 +448,7 @@ public class Packer {
 		} else if(o instanceof Map) {
 			Map m = (Map)o;
 			packMap(m.size());
-			for(Map.Entry e : m.entrySet()) {
+			for(Map.Entry e : m.entrySet()) {
 				pack(e.getKey());
 				pack(e.getValue());
 			}
diff --git a/java/src/test/java/org/msgpack/TestPackUnpack.java b/java/src/test/java/org/msgpack/TestPackUnpack.java
index 75c5fe7..8163678 100644
--- a/java/src/test/java/org/msgpack/TestPackUnpack.java
+++ b/java/src/test/java/org/msgpack/TestPackUnpack.java
@@ -37,14 +37,30 @@ public class TestPackUnpack {
 			testInt(rand.nextInt());
 	}
 
+	public void testLong(long val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		MessagePackObject obj = unpackOne(out);
+		assertEquals(val, obj.asLong());
+	}
+	@Test
+	public void testLong() throws Exception {
+		testLong(0);
+		testLong(-1);
+		testLong(1);
+		testLong(Integer.MIN_VALUE);
+		testLong(Integer.MAX_VALUE);
+		testLong(Long.MIN_VALUE);
+		testLong(Long.MAX_VALUE);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testLong(rand.nextLong());
+	}
+
 	public void testBigInteger(BigInteger val) throws Exception {
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
 		new Packer(out).pack(val);
 		MessagePackObject obj = unpackOne(out);
-		if(!val.equals(obj.asBigInteger())) {
-			System.out.println("expect: "+val);
-			System.out.println("but   : "+obj.asBigInteger());
-		}
 		assertEquals(val, obj.asBigInteger());
 	}
 	@Test
-- 
cgit v1.2.1


From 193a739749687e45a71a6821e625815587c4c4bf Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Thu, 19 Aug 2010 00:05:48 +0900
Subject: java: updates TestDirectConversion

---
 .../java/org/msgpack/TestDirectConversion.java     | 381 +++++++++++++--------
 .../test/java/org/msgpack/TestObjectEquals.java    |  48 +--
 java/src/test/java/org/msgpack/TestPackUnpack.java |  54 +--
 3 files changed, 296 insertions(+), 187 deletions(-)

(limited to 'java')

diff --git a/java/src/test/java/org/msgpack/TestDirectConversion.java b/java/src/test/java/org/msgpack/TestDirectConversion.java
index 77bbc58..dbacf01 100644
--- a/java/src/test/java/org/msgpack/TestDirectConversion.java
+++ b/java/src/test/java/org/msgpack/TestDirectConversion.java
@@ -8,141 +8,248 @@ import org.junit.Test;
 import static org.junit.Assert.*;
 
 public class TestDirectConversion {
-    @Test
-    public void testInt() throws Exception {
-        testInt(0);
-        testInt(-1);
-        testInt(1);
-        testInt(Integer.MIN_VALUE);
-        testInt(Integer.MAX_VALUE);
-        Random rand = new Random();
-        for (int i = 0; i < 1000; i++)
-            testInt(rand.nextInt());
-    }
-    public void testInt(int val) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).pack(val);
-        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-        Unpacker upk = new Unpacker(in);
-        assertEquals(val, upk.unpackInt());
-    }
-
-    @Test
-    public void testFloat() throws Exception {
-        testFloat((float)0.0);
-        testFloat((float)-0.0);
-        testFloat((float)1.0);
-        testFloat((float)-1.0);
-        testFloat((float)Float.MAX_VALUE);
-        testFloat((float)Float.MIN_VALUE);
-        testFloat((float)Float.NaN);
-        testFloat((float)Float.NEGATIVE_INFINITY);
-        testFloat((float)Float.POSITIVE_INFINITY);
-        Random rand = new Random();
-        for (int i = 0; i < 1000; i++)
-            testFloat(rand.nextFloat());
-    }
-    public void testFloat(float val) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).pack(val);
-        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-        Unpacker upk = new Unpacker(in);
-        float f = upk.unpackFloat();
-        if(Float.isNaN(val)) {
-            assertTrue(Float.isNaN(f));
-        } else {
-            assertEquals(val, f, 10e-10);
-        }
-    }
-
-    @Test
-    public void testDouble() throws Exception {
-        testDouble((double)0.0);
-        testDouble((double)-0.0);
-        testDouble((double)1.0);
-        testDouble((double)-1.0);
-        testDouble((double)Double.MAX_VALUE);
-        testDouble((double)Double.MIN_VALUE);
-        testDouble((double)Double.NaN);
-        testDouble((double)Double.NEGATIVE_INFINITY);
-        testDouble((double)Double.POSITIVE_INFINITY);
-        Random rand = new Random();
-        for (int i = 0; i < 1000; i++)
-            testDouble(rand.nextDouble());
-    }
-    public void testDouble(double val) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).pack(val);
-        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-        Unpacker upk = new Unpacker(in);
-        double f = upk.unpackDouble();
-        if(Double.isNaN(val)) {
-            assertTrue(Double.isNaN(f));
-        } else {
-            assertEquals(val, f, 10e-10);
-        }
-    }
-
-    @Test
-    public void testNil() throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).packNil();
-        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-        Unpacker upk = new Unpacker(in);
-        assertEquals(null, upk.unpackNull());
-    }
-
-    @Test
-    public void testBoolean() throws Exception {
-        testBoolean(false);
-        testBoolean(true);
-    }
-    public void testBoolean(boolean val) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).pack(val);
-        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-        Unpacker upk = new Unpacker(in);
-        assertEquals(val, upk.unpackBoolean());
-    }
-
-    @Test
-    public void testString() throws Exception {
-        testString("");
-        testString("a");
-        testString("ab");
-        testString("abc");
-        // small size string
-        for (int i = 0; i < 100; i++) {
-            StringBuilder sb = new StringBuilder();
-            int len = (int)Math.random() % 31 + 1;
-            for (int j = 0; j < len; j++)
-                sb.append('a' + ((int)Math.random()) & 26);
-            testString(sb.toString());
-        }
-        // medium size string
-        for (int i = 0; i < 100; i++) {
-            StringBuilder sb = new StringBuilder();
-            int len = (int)Math.random() % 100 + (1 << 15);
-            for (int j = 0; j < len; j++)
-                sb.append('a' + ((int)Math.random()) & 26);
-            testString(sb.toString());
-        }
-        // large size string
-        for (int i = 0; i < 10; i++) {
-            StringBuilder sb = new StringBuilder();
-            int len = (int)Math.random() % 100 + (1 << 31);
-            for (int j = 0; j < len; j++)
-                sb.append('a' + ((int)Math.random()) & 26);
-            testString(sb.toString());
-        }
-    }
-    public void testString(String val) throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        new Packer(out).pack(val);
-        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-        Unpacker upk = new Unpacker(in);
-        assertEquals(val, upk.unpackString());
-    }
-
-    // FIXME container types
+	@Test
+	public void testInt() throws Exception {
+		testInt(0);
+		testInt(-1);
+		testInt(1);
+		testInt(Integer.MIN_VALUE);
+		testInt(Integer.MAX_VALUE);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testInt(rand.nextInt());
+	}
+	public void testInt(int val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+		Unpacker pac = new Unpacker(in);
+		assertEquals(val, pac.unpackInt());
+	}
+
+	@Test
+	public void testLong() throws Exception {
+		testLong(0);
+		testLong(-1);
+		testLong(1);
+		testLong(Integer.MIN_VALUE);
+		testLong(Integer.MAX_VALUE);
+		testLong(Long.MIN_VALUE);
+		testLong(Long.MAX_VALUE);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testLong(rand.nextLong());
+	}
+	public void testLong(long val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+		Unpacker pac = new Unpacker(in);
+		assertEquals(val, pac.unpackLong());
+	}
+
+	@Test
+	public void testFloat() throws Exception {
+		testFloat((float)0.0);
+		testFloat((float)-0.0);
+		testFloat((float)1.0);
+		testFloat((float)-1.0);
+		testFloat((float)Float.MAX_VALUE);
+		testFloat((float)Float.MIN_VALUE);
+		testFloat((float)Float.NaN);
+		testFloat((float)Float.NEGATIVE_INFINITY);
+		testFloat((float)Float.POSITIVE_INFINITY);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testFloat(rand.nextFloat());
+	}
+	public void testFloat(float val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+		Unpacker pac = new Unpacker(in);
+		assertEquals(val, pac.unpackFloat(), 10e-10);
+	}
+
+	@Test
+	public void testDouble() throws Exception {
+		testDouble((double)0.0);
+		testDouble((double)-0.0);
+		testDouble((double)1.0);
+		testDouble((double)-1.0);
+		testDouble((double)Double.MAX_VALUE);
+		testDouble((double)Double.MIN_VALUE);
+		testDouble((double)Double.NaN);
+		testDouble((double)Double.NEGATIVE_INFINITY);
+		testDouble((double)Double.POSITIVE_INFINITY);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testDouble(rand.nextDouble());
+	}
+	public void testDouble(double val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+		Unpacker pac = new Unpacker(in);
+		assertEquals(val, pac.unpackDouble(), 10e-10);
+	}
+
+	@Test
+	public void testNil() throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).packNil();
+		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+		Unpacker pac = new Unpacker(in);
+		assertEquals(null, pac.unpackNull());
+	}
+
+	@Test
+	public void testBoolean() throws Exception {
+		testBoolean(false);
+		testBoolean(true);
+	}
+	public void testBoolean(boolean val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+		Unpacker pac = new Unpacker(in);
+		assertEquals(val, pac.unpackBoolean());
+	}
+
+	@Test
+	public void testString() throws Exception {
+		testString("");
+		testString("a");
+		testString("ab");
+		testString("abc");
+
+		// small size string
+		for (int i = 0; i < 100; i++) {
+			StringBuilder sb = new StringBuilder();
+			int len = (int)Math.random() % 31 + 1;
+			for (int j = 0; j < len; j++)
+				sb.append('a' + ((int)Math.random()) & 26);
+			testString(sb.toString());
+		}
+
+		// medium size string
+		for (int i = 0; i < 100; i++) {
+			StringBuilder sb = new StringBuilder();
+			int len = (int)Math.random() % 100 + (1 << 15);
+			for (int j = 0; j < len; j++)
+				sb.append('a' + ((int)Math.random()) & 26);
+			testString(sb.toString());
+		}
+
+		// large size string
+		for (int i = 0; i < 10; i++) {
+			StringBuilder sb = new StringBuilder();
+			int len = (int)Math.random() % 100 + (1 << 31);
+			for (int j = 0; j < len; j++)
+				sb.append('a' + ((int)Math.random()) & 26);
+			testString(sb.toString());
+		}
+	}
+	public void testString(String val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+		Unpacker pac = new Unpacker(in);
+		assertEquals(val, pac.unpackString());
+	}
+
+	@Test
+	public void testArray() throws Exception {
+		List emptyList = new ArrayList();
+		{
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			new Packer(out).pack(emptyList);
+			ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+			Unpacker pac = new Unpacker(in);
+			int ulen = pac.unpackArray();
+			assertEquals(0, ulen);
+		}
+
+		for (int i = 0; i < 1000; i++) {
+			List l = new ArrayList();
+			int len = (int)Math.random() % 1000 + 1;
+			for (int j = 0; j < len; j++)
+				l.add(j);
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			new Packer(out).pack(l);
+			ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+			Unpacker pac = new Unpacker(in);
+			int ulen = pac.unpackArray();
+			assertEquals(len, ulen);
+			for (int j = 0; j < len; j++) {
+				assertEquals(l.get(j).intValue(), pac.unpackInt());
+			}
+		}
+
+		for (int i = 0; i < 1000; i++) {
+			List l = new ArrayList();
+			int len = (int)Math.random() % 1000 + 1;
+			for (int j = 0; j < len; j++)
+				l.add(Integer.toString(j));
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			new Packer(out).pack(l);
+			ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+			Unpacker pac = new Unpacker(in);
+			int ulen = pac.unpackArray();
+			assertEquals(len, ulen);
+			for (int j = 0; j < len; j++) {
+				assertEquals(l.get(j), pac.unpackString());
+			}
+		}
+	}
+
+	@Test
+	public void testMap() throws Exception {
+		Map emptyMap = new HashMap();
+		{
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			new Packer(out).pack(emptyMap);
+			ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+			Unpacker pac = new Unpacker(in);
+			int ulen = pac.unpackMap();
+			assertEquals(0, ulen);
+		}
+
+		for (int i = 0; i < 1000; i++) {
+			Map m = new HashMap();
+			int len = (int)Math.random() % 1000 + 1;
+			for (int j = 0; j < len; j++)
+				m.put(j, j);
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			new Packer(out).pack(m);
+			ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+			Unpacker pac = new Unpacker(in);
+			int ulen = pac.unpackMap();
+			assertEquals(len, ulen);
+			for (int j = 0; j < len; j++) {
+				Integer val = m.get(pac.unpackInt());
+				assertNotNull(val);
+				assertEquals(val.intValue(), pac.unpackInt());
+			}
+		}
+
+		for (int i = 0; i < 1000; i++) {
+			Map m = new HashMap();
+			int len = (int)Math.random() % 1000 + 1;
+			for (int j = 0; j < len; j++)
+				m.put(Integer.toString(j), j);
+			ByteArrayOutputStream out = new ByteArrayOutputStream();
+			new Packer(out).pack(m);
+			ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+			Unpacker pac = new Unpacker(in);
+			int ulen = pac.unpackMap();
+			assertEquals(len, ulen);
+			for (int j = 0; j < len; j++) {
+				Integer val = m.get(pac.unpackString());
+				assertNotNull(val);
+				assertEquals(val.intValue(), pac.unpackInt());
+			}
+		}
+	}
 };
+
diff --git a/java/src/test/java/org/msgpack/TestObjectEquals.java b/java/src/test/java/org/msgpack/TestObjectEquals.java
index b2b018d..25fe927 100644
--- a/java/src/test/java/org/msgpack/TestObjectEquals.java
+++ b/java/src/test/java/org/msgpack/TestObjectEquals.java
@@ -9,6 +9,17 @@ import org.junit.Test;
 import static org.junit.Assert.*;
 
 public class TestObjectEquals {
+	@Test
+	public void testInt() throws Exception {
+		testInt(0);
+		testInt(-1);
+		testInt(1);
+		testInt(Integer.MIN_VALUE);
+		testInt(Integer.MAX_VALUE);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testInt(rand.nextInt());
+	}
 	public void testInt(int val) throws Exception {
 		MessagePackObject objInt = IntegerType.create(val);
 		MessagePackObject objLong = IntegerType.create((long)val);
@@ -23,18 +34,20 @@ public class TestObjectEquals {
 		assertTrue(objBigInt.equals(objLong));
 		assertTrue(objBigInt.equals(objBigInt));
 	}
+
 	@Test
-	public void testInt() throws Exception {
-		testInt(0);
-		testInt(-1);
-		testInt(1);
-		testInt(Integer.MIN_VALUE);
-		testInt(Integer.MAX_VALUE);
+	public void testLong() throws Exception {
+		testLong(0);
+		testLong(-1);
+		testLong(1);
+		testLong(Integer.MIN_VALUE);
+		testLong(Integer.MAX_VALUE);
+		testLong(Long.MIN_VALUE);
+		testLong(Long.MAX_VALUE);
 		Random rand = new Random();
 		for (int i = 0; i < 1000; i++)
-			testInt(rand.nextInt());
+			testLong(rand.nextLong());
 	}
-
 	public void testLong(long val) throws Exception {
 		MessagePackObject objInt = IntegerType.create((int)val);
 		MessagePackObject objLong = IntegerType.create(val);
@@ -61,19 +74,6 @@ public class TestObjectEquals {
 			assertTrue(objBigInt.equals(objBigInt));
 		}
 	}
-	@Test
-	public void testLong() throws Exception {
-		testLong(0);
-		testLong(-1);
-		testLong(1);
-		testLong(Integer.MIN_VALUE);
-		testLong(Integer.MAX_VALUE);
-		testLong(Long.MIN_VALUE);
-		testLong(Long.MAX_VALUE);
-		Random rand = new Random();
-		for (int i = 0; i < 1000; i++)
-			testLong(rand.nextLong());
-	}
 
 	@Test
 	public void testNil() throws Exception {
@@ -82,9 +82,6 @@ public class TestObjectEquals {
 		assertFalse(NilType.create().equals(BooleanType.create(false)));
 	}
 
-	public void testString(String str) throws Exception {
-		assertTrue(RawType.create(str).equals(RawType.create(str)));
-	}
 	@Test
 	public void testString() throws Exception {
 		testString("");
@@ -92,5 +89,8 @@ public class TestObjectEquals {
 		testString("ab");
 		testString("abc");
 	}
+	public void testString(String str) throws Exception {
+		assertTrue(RawType.create(str).equals(RawType.create(str)));
+	}
 }
 
diff --git a/java/src/test/java/org/msgpack/TestPackUnpack.java b/java/src/test/java/org/msgpack/TestPackUnpack.java
index 8163678..7edd411 100644
--- a/java/src/test/java/org/msgpack/TestPackUnpack.java
+++ b/java/src/test/java/org/msgpack/TestPackUnpack.java
@@ -11,20 +11,14 @@ import static org.junit.Assert.*;
 public class TestPackUnpack {
 	public MessagePackObject unpackOne(ByteArrayOutputStream out) {
 		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-		Unpacker upk = new Unpacker(in);
-		Iterator it = upk.iterator();
+		Unpacker pac = new Unpacker(in);
+		Iterator it = pac.iterator();
 		assertEquals(true, it.hasNext());
 		MessagePackObject obj = it.next();
 		assertEquals(false, it.hasNext());
 		return obj;
 	}
 
-	public void testInt(int val) throws Exception {
-		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		new Packer(out).pack(val);
-		MessagePackObject obj = unpackOne(out);
-		assertEquals(val, obj.asInt());
-	}
 	@Test
 	public void testInt() throws Exception {
 		testInt(0);
@@ -36,13 +30,13 @@ public class TestPackUnpack {
 		for (int i = 0; i < 1000; i++)
 			testInt(rand.nextInt());
 	}
-
-	public void testLong(long val) throws Exception {
+	public void testInt(int val) throws Exception {
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
 		new Packer(out).pack(val);
 		MessagePackObject obj = unpackOne(out);
-		assertEquals(val, obj.asLong());
+		assertEquals(val, obj.asInt());
 	}
+
 	@Test
 	public void testLong() throws Exception {
 		testLong(0);
@@ -56,13 +50,13 @@ public class TestPackUnpack {
 		for (int i = 0; i < 1000; i++)
 			testLong(rand.nextLong());
 	}
-
-	public void testBigInteger(BigInteger val) throws Exception {
+	public void testLong(long val) throws Exception {
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
 		new Packer(out).pack(val);
 		MessagePackObject obj = unpackOne(out);
-		assertEquals(val, obj.asBigInteger());
+		assertEquals(val, obj.asLong());
 	}
+
 	@Test
 	public void testBigInteger() throws Exception {
 		testBigInteger(BigInteger.valueOf(0));
@@ -78,13 +72,13 @@ public class TestPackUnpack {
 		for (int i = 0; i < 1000; i++)
 			testBigInteger( max.subtract(BigInteger.valueOf( Math.abs(rand.nextLong()) )) );
 	}
-
-	public void testFloat(float val) throws Exception {
+	public void testBigInteger(BigInteger val) throws Exception {
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
 		new Packer(out).pack(val);
 		MessagePackObject obj = unpackOne(out);
-		assertEquals(val, obj.asFloat(), 10e-10);
+		assertEquals(val, obj.asBigInteger());
 	}
+
 	@Test
 	public void testFloat() throws Exception {
 		testFloat((float)0.0);
@@ -100,13 +94,14 @@ public class TestPackUnpack {
 		for (int i = 0; i < 1000; i++)
 			testFloat(rand.nextFloat());
 	}
-
-	public void testDouble(double val) throws Exception {
+	public void testFloat(float val) throws Exception {
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
 		new Packer(out).pack(val);
 		MessagePackObject obj = unpackOne(out);
-		assertEquals(val, obj.asDouble(), 10e-10);
+		float f = obj.asFloat();
+		assertEquals(val, f, 10e-10);
 	}
+
 	@Test
 	public void testDouble() throws Exception {
 		testDouble((double)0.0);
@@ -122,6 +117,13 @@ public class TestPackUnpack {
 		for (int i = 0; i < 1000; i++)
 			testDouble(rand.nextDouble());
 	}
+	public void testDouble(double val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		MessagePackObject obj = unpackOne(out);
+		double f = obj.asDouble();
+		assertEquals(val, f, 10e-10);
+	}
 
 	@Test
 	public void testNil() throws Exception {
@@ -143,12 +145,6 @@ public class TestPackUnpack {
 		assertEquals(val, obj.asBoolean());
 	}
 
-	public void testString(String val) throws Exception {
-		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		new Packer(out).pack(val);
-		MessagePackObject obj = unpackOne(out);
-		assertEquals(val, obj.asString());
-	}
 	@Test
 	public void testString() throws Exception {
 		testString("");
@@ -183,6 +179,12 @@ public class TestPackUnpack {
 			testString(sb.toString());
 		}
 	}
+	public void testString(String val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		MessagePackObject obj = unpackOne(out);
+		assertEquals(val, obj.asString());
+	}
 
 	@Test
 	public void testArray() throws Exception {
-- 
cgit v1.2.1


From 1d17836b7d2eb4e5e0f25d2466df70e137642061 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Thu, 19 Aug 2010 00:54:23 +0900
Subject: java: NilType::create() returns NilType's one and only instance

---
 java/src/main/java/org/msgpack/MessagePackObject.java |  2 +-
 java/src/main/java/org/msgpack/object/NilType.java    | 10 ++++++----
 java/src/test/java/org/msgpack/TestPackUnpack.java    |  2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/MessagePackObject.java b/java/src/main/java/org/msgpack/MessagePackObject.java
index 6181f7a..2424446 100644
--- a/java/src/main/java/org/msgpack/MessagePackObject.java
+++ b/java/src/main/java/org/msgpack/MessagePackObject.java
@@ -23,7 +23,7 @@ import java.util.Map;
 import java.math.BigInteger;
 
 public abstract class MessagePackObject implements Cloneable, MessagePackable {
-	public boolean isNull() {
+	public boolean isNil() {
 		return false;
 	}
 
diff --git a/java/src/main/java/org/msgpack/object/NilType.java b/java/src/main/java/org/msgpack/object/NilType.java
index d0572f1..c443db1 100644
--- a/java/src/main/java/org/msgpack/object/NilType.java
+++ b/java/src/main/java/org/msgpack/object/NilType.java
@@ -21,14 +21,16 @@ import java.io.IOException;
 import org.msgpack.*;
 
 public class NilType extends MessagePackObject {
-	private static NilType instance = new NilType();
+	private final static NilType INSTANCE = new NilType();
 
 	public static NilType create() {
-		return instance;
+		return INSTANCE;
 	}
 
+	private NilType() { }
+
 	@Override
-	public boolean isNull() {
+	public boolean isNil() {
 		return true;
 	}
 
@@ -52,7 +54,7 @@ public class NilType extends MessagePackObject {
 
 	@Override
 	public Object clone() {
-		return new NilType();
+		return INSTANCE;
 	}
 }
 
diff --git a/java/src/test/java/org/msgpack/TestPackUnpack.java b/java/src/test/java/org/msgpack/TestPackUnpack.java
index 7edd411..494c8a8 100644
--- a/java/src/test/java/org/msgpack/TestPackUnpack.java
+++ b/java/src/test/java/org/msgpack/TestPackUnpack.java
@@ -130,7 +130,7 @@ public class TestPackUnpack {
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
 		new Packer(out).packNil();
 		MessagePackObject obj = unpackOne(out);
-		assertTrue(obj.isNull());
+		assertTrue(obj.isNil());
 	}
 
 	@Test
-- 
cgit v1.2.1


From b4c98584db002cbb4d3960b6ed025212248dcce8 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Thu, 19 Aug 2010 01:19:34 +0900
Subject: java: adds Unpacker.unpackBigInteger()

---
 .../java/org/msgpack/BufferedUnpackerImpl.java     | 25 ++++++++++++++++++----
 java/src/main/java/org/msgpack/Unpacker.java       | 10 +++++++++
 .../java/org/msgpack/TestDirectConversion.java     | 24 +++++++++++++++++++++
 3 files changed, 55 insertions(+), 4 deletions(-)

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
index 9496238..5b449c7 100644
--- a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
+++ b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
@@ -19,7 +19,7 @@ package org.msgpack;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
-//import java.math.BigInteger;
+import java.math.BigInteger;
 
 abstract class BufferedUnpackerImpl extends UnpackerImpl {
 	int offset = 0;
@@ -198,8 +198,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
 			{
 				long o = castBuffer.getLong(0);
 				if(o < 0) {
-					// FIXME unpackBigInteger
-					throw new MessageTypeException("uint 64 bigger than 0x7fffffff is not supported");
+					throw new MessageTypeException();
 				}
 				advance(9);
 				return o;
@@ -231,7 +230,25 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
 		}
 	}
 
-	// FIXME unpackBigInteger
+	final BigInteger unpackBigInteger() throws IOException, MessageTypeException {
+		more(1);
+		int b = buffer[offset];
+		if((b & 0xff) != 0xcf) {
+			return BigInteger.valueOf(unpackLong());
+		}
+
+		// unsigned int 64
+		more(9);
+		castBuffer.rewind();
+		castBuffer.put(buffer, offset+1, 8);
+		advance(9);
+		long o = castBuffer.getLong(0);
+		if(o < 0) {
+			return new BigInteger(1, castBuffer.array());
+		} else {
+			return BigInteger.valueOf(o);
+		}
+	}
 
 	final float unpackFloat() throws IOException, MessageTypeException {
 		more(1);
diff --git a/java/src/main/java/org/msgpack/Unpacker.java b/java/src/main/java/org/msgpack/Unpacker.java
index 3a95243..3cae502 100644
--- a/java/src/main/java/org/msgpack/Unpacker.java
+++ b/java/src/main/java/org/msgpack/Unpacker.java
@@ -22,6 +22,7 @@ import java.io.InputStream;
 import java.io.IOException;
 import java.util.Iterator;
 import java.nio.ByteBuffer;
+import java.math.BigInteger;
 
 /**
  * Unpacker enables you to deserialize objects from stream.
@@ -452,6 +453,15 @@ public class Unpacker implements Iterable {
 		return impl.unpackLong();
 	}
 
+	/**
+	 * Gets one {@code BigInteger} value from the buffer.
+	 * This method calls {@link fill()} method if needed.
+	 * @throws MessageTypeException the first value of the buffer is not a {@code BigInteger}.
+	 */
+	public BigInteger unpackBigInteger() throws IOException, MessageTypeException {
+		return impl.unpackBigInteger();
+	}
+
 	/**
 	 * Gets one {@code float} value from the buffer.
 	 * This method calls {@link fill()} method if needed.
diff --git a/java/src/test/java/org/msgpack/TestDirectConversion.java b/java/src/test/java/org/msgpack/TestDirectConversion.java
index dbacf01..1822ecb 100644
--- a/java/src/test/java/org/msgpack/TestDirectConversion.java
+++ b/java/src/test/java/org/msgpack/TestDirectConversion.java
@@ -3,6 +3,7 @@ package org.msgpack;
 import org.msgpack.*;
 import java.io.*;
 import java.util.*;
+import java.math.BigInteger;
 
 import org.junit.Test;
 import static org.junit.Assert.*;
@@ -48,6 +49,29 @@ public class TestDirectConversion {
 		assertEquals(val, pac.unpackLong());
 	}
 
+	@Test
+	public void testBigInteger() throws Exception {
+		testBigInteger(BigInteger.valueOf(0));
+		testBigInteger(BigInteger.valueOf(-1));
+		testBigInteger(BigInteger.valueOf(1));
+		testBigInteger(BigInteger.valueOf(Integer.MIN_VALUE));
+		testBigInteger(BigInteger.valueOf(Integer.MAX_VALUE));
+		testBigInteger(BigInteger.valueOf(Long.MIN_VALUE));
+		testBigInteger(BigInteger.valueOf(Long.MAX_VALUE));
+		BigInteger max = BigInteger.valueOf(Long.MAX_VALUE).setBit(63);
+		testBigInteger(max);
+		Random rand = new Random();
+		for (int i = 0; i < 1000; i++)
+			testBigInteger( max.subtract(BigInteger.valueOf( Math.abs(rand.nextLong()) )) );
+	}
+	public void testBigInteger(BigInteger val) throws Exception {
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		new Packer(out).pack(val);
+		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+		Unpacker pac = new Unpacker(in);
+		assertEquals(val, pac.unpackBigInteger());
+	}
+
 	@Test
 	public void testFloat() throws Exception {
 		testFloat((float)0.0);
-- 
cgit v1.2.1


From c8e351b31e28042c10f7406238636c92a64a696c Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Sat, 21 Aug 2010 03:36:44 +0900
Subject: java: adds TestMessageUnpackable test

---
 java/src/main/java/org/msgpack/Packer.java         |  2 +-
 java/src/test/java/org/msgpack/Image.java          | 50 ++++++++++++++++++++++
 .../java/org/msgpack/TestMessageUnpackable.java    | 34 +++++++++++++++
 3 files changed, 85 insertions(+), 1 deletion(-)
 create mode 100644 java/src/test/java/org/msgpack/Image.java
 create mode 100644 java/src/test/java/org/msgpack/TestMessageUnpackable.java

(limited to 'java')

diff --git a/java/src/main/java/org/msgpack/Packer.java b/java/src/main/java/org/msgpack/Packer.java
index 0ac8d89..139b3b1 100644
--- a/java/src/main/java/org/msgpack/Packer.java
+++ b/java/src/main/java/org/msgpack/Packer.java
@@ -212,7 +212,7 @@ public class Packer {
 			out.write(castBytes);
 			return this;
 		} else {
-			throw new MessageTypeException("can't BigInteger larger than 0xffffffffffffffff");
+			throw new MessageTypeException("can't pack BigInteger larger than 0xffffffffffffffff");
 		}
 	}
 
diff --git a/java/src/test/java/org/msgpack/Image.java b/java/src/test/java/org/msgpack/Image.java
new file mode 100644
index 0000000..3fcfe38
--- /dev/null
+++ b/java/src/test/java/org/msgpack/Image.java
@@ -0,0 +1,50 @@
+package org.msgpack;
+
+import org.msgpack.*;
+import java.io.*;
+import java.util.*;
+
+public class Image implements MessagePackable, MessageUnpackable {
+	public String uri = "";
+	public String title = "";
+	public int width = 0;
+	public int height = 0;
+	public int size = 0;
+
+	public void messagePack(Packer pk) throws IOException {
+		pk.packArray(5);
+		pk.pack(uri);
+		pk.pack(title);
+		pk.pack(width);
+		pk.pack(height);
+		pk.pack(size);
+	}
+
+	public void messageUnpack(Unpacker pac) throws IOException, MessageTypeException {
+		int length = pac.unpackArray();
+		if(length != 5) {
+			throw new MessageTypeException();
+		}
+		uri = pac.unpackString();
+		title = pac.unpackString();
+		width = pac.unpackInt();
+		height = pac.unpackInt();
+		size = pac.unpackInt();
+	}
+
+	public boolean equals(Image obj) {
+		return uri.equals(obj.uri) &&
+			title.equals(obj.title) &&
+			width == obj.width &&
+			height == obj.height &&
+			size == obj.size;
+	}
+
+	public boolean equals(Object obj) {
+		if(obj.getClass() != Image.class) {
+			return false;
+		}
+		return equals((Image)obj);
+	}
+}
+
diff --git a/java/src/test/java/org/msgpack/TestMessageUnpackable.java b/java/src/test/java/org/msgpack/TestMessageUnpackable.java
new file mode 100644
index 0000000..9099f91
--- /dev/null
+++ b/java/src/test/java/org/msgpack/TestMessageUnpackable.java
@@ -0,0 +1,34 @@
+package org.msgpack;
+
+import org.msgpack.*;
+import java.io.*;
+import java.util.*;
+import java.math.BigInteger;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TestMessageUnpackable {
+	@Test
+	public void testImage() throws Exception {
+		Image src = new Image();
+		src.title = "msgpack";
+		src.uri = "http://msgpack.org/";
+		src.width = 2560;
+		src.height = 1600;
+		src.size = 4096000;
+
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		src.messagePack(new Packer(out));
+
+		Image dst = new Image();
+
+		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+		Unpacker pac = new Unpacker(in);
+
+		dst.messageUnpack(pac);
+
+		assertEquals(src, dst);
+	}
+}
+
-- 
cgit v1.2.1


From 3c75361e5a195eba9622927cac7aebe0944f9232 Mon Sep 17 00:00:00 2001
From: frsyuki 
Date: Sun, 29 Aug 2010 18:24:32 +0900
Subject: cpp: updates README.md

---
 java/src/test/java/org/msgpack/TestMessageUnpackable.java | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

(limited to 'java')

diff --git a/java/src/test/java/org/msgpack/TestMessageUnpackable.java b/java/src/test/java/org/msgpack/TestMessageUnpackable.java
index 9099f91..32917c7 100644
--- a/java/src/test/java/org/msgpack/TestMessageUnpackable.java
+++ b/java/src/test/java/org/msgpack/TestMessageUnpackable.java
@@ -24,9 +24,7 @@ public class TestMessageUnpackable {
 		Image dst = new Image();
 
 		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-		Unpacker pac = new Unpacker(in);
-
-		dst.messageUnpack(pac);
+		dst.messageUnpack(new Unpacker(in));
 
 		assertEquals(src, dst);
 	}
-- 
cgit v1.2.1