diff --git a/java/src/main/java/org/msgpack/type/Raw.java b/java/src/main/java/org/msgpack/type/Raw.java index 24d4b444..cdd0c220 100644 --- a/java/src/main/java/org/msgpack/type/Raw.java +++ b/java/src/main/java/org/msgpack/type/Raw.java @@ -22,17 +22,10 @@ import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import org.msgpack.*; -public final class Raw/* implements MessagePackable, MessageUnpackable, MessageConvertable*/ { +public final class Raw { private byte[] bytes; private String string; - /* - public Raw() { - this.bytes = null; - this.string = ""; - } - */ - public Raw(byte[] bytes) { this.bytes = bytes; this.string = null; @@ -69,22 +62,8 @@ public final class Raw/* implements MessagePackable, MessageUnpackable, MessageC return ByteBuffer.wrap(toByteArray()); } - /* - public void messagePack(Packer pk) throws IOException { - pk.packByteArray(toByteArray()); + static { + RawTemplate.load(); } - - public void messageUnpack(Unpacker pac) throws IOException, MessageTypeException { - // FIXME immutable - this.bytes = pac.unpackByteArray(); - this.string = null; - } - - public void messageConvert(MessagePackObject obj) throws MessageTypeException { - // FIXME immutable - this.bytes = obj.asByteArray(); - this.string = null; - } - */ } diff --git a/java/src/main/java/org/msgpack/type/RawTemplate.java b/java/src/main/java/org/msgpack/type/RawTemplate.java new file mode 100644 index 00000000..85fb5e46 --- /dev/null +++ b/java/src/main/java/org/msgpack/type/RawTemplate.java @@ -0,0 +1,51 @@ +// +// 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.type; + +import java.io.IOException; +import org.msgpack.*; +import org.msgpack.template.TemplateRegistry; + +public class RawTemplate implements Template { + static void load() { } + + private RawTemplate() { } + + public void pack(Packer pk, Object target) throws IOException { + pk.packByteArray(((Raw)target).toByteArray()); + } + + public Object unpack(Unpacker pac, Object to) throws IOException, MessageTypeException { + return new Raw(pac.unpackByteArray()); + } + + public Object convert(MessagePackObject from, Object to) throws MessageTypeException { + return new Raw(from.asByteArray()); + } + + static public RawTemplate getInstance() { + return instance; + } + + static final RawTemplate instance = new RawTemplate(); + + static { + TemplateRegistry.register(Raw.class, instance); + } +} +