http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/ListType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/ListType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/ListType.java deleted file mode 100644 index 4a5caed..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/ListType.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -public class ListType extends AbstractPrimitiveType<List> -{ - private final ListEncoding _listEncoding; - private final ListEncoding _shortListEncoding; - private EncoderImpl _encoder; - - private static interface ListEncoding extends PrimitiveTypeEncoding<List> - { - void setValue(List value, int length); - } - - ListType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _encoder = encoder; - _listEncoding = new AllListEncoding(encoder, decoder); - _shortListEncoding = new ShortListEncoding(encoder, decoder); - encoder.register(List.class, this); - decoder.register(this); - } - - public Class<List> getTypeClass() - { - return List.class; - } - - public ListEncoding getEncoding(final List val) - { - - int calculatedSize = calculateSize(val, _encoder); - ListEncoding encoding = (val.size() > 255 || calculatedSize >= 254) - ? _listEncoding - : _shortListEncoding; - - encoding.setValue(val, calculatedSize); - return encoding; - } - - private static int calculateSize(final List val, EncoderImpl encoder) - { - int len = 0; - final int count = val.size(); - - for(int i = 0; i < count; i++) - { - Object element = val.get(i); - TypeEncoding elementEncoding = encoder.getType(element).getEncoding(element); - len += elementEncoding.getConstructorSize()+elementEncoding.getValueSize(element); - } - return len; - } - - - public ListEncoding getCanonicalEncoding() - { - return _listEncoding; - } - - public Collection<ListEncoding> getAllEncodings() - { - return Arrays.asList(_shortListEncoding, _listEncoding); - } - - private class AllListEncoding - extends LargeFloatingSizePrimitiveTypeEncoding<List> - implements ListEncoding - { - - private List _value; - private int _length; - - public AllListEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final List val) - { - getEncoder().writeRaw(val.size()); - - final int count = val.size(); - - for(int i = 0; i < count; i++) - { - Object element = val.get(i); - TypeEncoding elementEncoding = getEncoder().getType(element).getEncoding(element); - elementEncoding.writeConstructor(); - elementEncoding.writeValue(element); - } - } - - @Override - protected int getEncodedValueSize(final List val) - { - return 4 + ((val == _value) ? _length : calculateSize(val, getEncoder())); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.LIST32; - } - - public ListType getType() - { - return ListType.this; - } - - public boolean encodesSuperset(final TypeEncoding<List> encoding) - { - return (getType() == encoding.getType()); - } - - public List readValue() - { - DecoderImpl decoder = getDecoder(); - int size = decoder.readRawInt(); - // todo - limit the decoder with size - int count = decoder.readRawInt(); - List list = new ArrayList(count); - for(int i = 0; i < count; i++) - { - list.add(decoder.readObject()); - } - return list; - } - - public void setValue(final List value, final int length) - { - _value = value; - _length = length; - } - } - - private class ShortListEncoding - extends SmallFloatingSizePrimitiveTypeEncoding<List> - implements ListEncoding - { - - private List _value; - private int _length; - - public ShortListEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final List val) - { - getEncoder().writeRaw((byte)val.size()); - - final int count = val.size(); - - for(int i = 0; i < count; i++) - { - Object element = val.get(i); TypeEncoding elementEncoding = getEncoder().getType(element).getEncoding(element); - elementEncoding.writeConstructor(); - elementEncoding.writeValue(element); - } - } - - @Override - protected int getEncodedValueSize(final List val) - { - return 1 + ((val == _value) ? _length : calculateSize(val, getEncoder())); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.LIST8; - } - - public ListType getType() - { - return ListType.this; - } - - public boolean encodesSuperset(final TypeEncoding<List> encoder) - { - return encoder == this; - } - - public List readValue() - { - - DecoderImpl decoder = getDecoder(); - int size = ((int)decoder.readRawByte()) & 0xff; - // todo - limit the decoder with size - int count = ((int)decoder.readRawByte()) & 0xff; - List list = new ArrayList(count); - for(int i = 0; i < count; i++) - { - list.add(decoder.readObject()); - } - return list; - } - - public void setValue(final List value, final int length) - { - _value = value; - _length = length; - } - } -}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/LongType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/LongType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/LongType.java deleted file mode 100644 index 47532df..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/LongType.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import java.util.Arrays; -import java.util.Collection; - -public class LongType extends AbstractPrimitiveType<Long> -{ - - public static interface LongEncoding extends PrimitiveTypeEncoding<Long> - { - void write(long l); - void writeValue(long l); - public long readPrimitiveValue(); - } - - private LongEncoding _longEncoding; - private LongEncoding _smallLongEncoding; - - LongType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _longEncoding = new AllLongEncoding(encoder, decoder); - _smallLongEncoding = new SmallLongEncoding(encoder, decoder); - encoder.register(Long.class, this); - decoder.register(this); - } - - public Class<Long> getTypeClass() - { - return Long.class; - } - - public LongEncoding getEncoding(final Long val) - { - return getEncoding(val.longValue()); - } - - public LongEncoding getEncoding(final long l) - { - return (l >= -128l && l <= 127l) ? _smallLongEncoding : _longEncoding; - } - - - public LongEncoding getCanonicalEncoding() - { - return _longEncoding; - } - - public Collection<LongEncoding> getAllEncodings() - { - return Arrays.asList(_smallLongEncoding, _longEncoding); - } - - public void write(long l) - { - if(l >= -128l && l <= 127l) - { - _smallLongEncoding.write(l); - } - else - { - _longEncoding.write(l); - } - } - - private class AllLongEncoding extends FixedSizePrimitiveTypeEncoding<Long> implements LongEncoding - { - - public AllLongEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 8; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.LONG; - } - - public LongType getType() - { - return LongType.this; - } - - public void writeValue(final Long val) - { - getEncoder().writeRaw(val.longValue()); - } - - public void write(final long l) - { - writeConstructor(); - getEncoder().writeRaw(l); - - } - - public void writeValue(final long l) - { - getEncoder().writeRaw(l); - } - - public boolean encodesSuperset(final TypeEncoding<Long> encoding) - { - return (getType() == encoding.getType()); - } - - public Long readValue() - { - return readPrimitiveValue(); - } - - public long readPrimitiveValue() - { - return getDecoder().readRawLong(); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } - - private class SmallLongEncoding extends FixedSizePrimitiveTypeEncoding<Long> implements LongEncoding - { - public SmallLongEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SMALLLONG; - } - - @Override - protected int getFixedSize() - { - return 1; - } - - public void write(final long l) - { - writeConstructor(); - getEncoder().writeRaw((byte)l); - } - - public void writeValue(final long l) - { - getEncoder().writeRaw((byte)l); - } - - public long readPrimitiveValue() - { - return (long) getDecoder().readRawByte(); - } - - public LongType getType() - { - return LongType.this; - } - - public void writeValue(final Long val) - { - getEncoder().writeRaw((byte)val.longValue()); - } - - public boolean encodesSuperset(final TypeEncoding<Long> encoder) - { - return encoder == this; - } - - public Long readValue() - { - return readPrimitiveValue(); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/MapType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/MapType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/MapType.java deleted file mode 100644 index f0913ff..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/MapType.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import java.util.*; - -public class MapType extends AbstractPrimitiveType<Map> -{ - private final MapEncoding _mapEncoding; - private final MapEncoding _shortMapEncoding; - private EncoderImpl _encoder; - - private static interface MapEncoding extends PrimitiveTypeEncoding<Map> - { - void setValue(Map value, int length); - } - - MapType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _encoder = encoder; - _mapEncoding = new AllMapEncoding(encoder, decoder); - _shortMapEncoding = new ShortMapEncoding(encoder, decoder); - encoder.register(Map.class, this); - decoder.register(this); - } - - public Class<Map> getTypeClass() - { - return Map.class; - } - - public MapEncoding getEncoding(final Map val) - { - - int calculatedSize = calculateSize(val, _encoder); - MapEncoding encoding = (val.size() > 127 || calculatedSize >= 254) - ? _mapEncoding - : _shortMapEncoding; - - encoding.setValue(val, calculatedSize); - return encoding; - } - - private static int calculateSize(final Map val, EncoderImpl encoder) - { - int len = 0; - Iterator<Map.Entry> iter = val.entrySet().iterator(); - - while(iter.hasNext()) - { - Map.Entry element = iter.next(); - TypeEncoding elementEncoding = encoder.getType(element.getKey()).getEncoding(element.getKey()); - len += elementEncoding.getConstructorSize()+elementEncoding.getValueSize(element.getKey()); - elementEncoding = encoder.getType(element.getValue()).getEncoding(element.getValue()); - len += elementEncoding.getConstructorSize()+elementEncoding.getValueSize(element.getValue()); - - } - return len; - } - - - public MapEncoding getCanonicalEncoding() - { - return _mapEncoding; - } - - public Collection<MapEncoding> getAllEncodings() - { - return Arrays.asList(_shortMapEncoding, _mapEncoding); - } - - private class AllMapEncoding - extends LargeFloatingSizePrimitiveTypeEncoding<Map> - implements MapEncoding - { - - private Map _value; - private int _length; - - public AllMapEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final Map val) - { - getEncoder().writeRaw(2 * val.size()); - - - Iterator<Map.Entry> iter = val.entrySet().iterator(); - - while(iter.hasNext()) - { - Map.Entry element = iter.next(); - TypeEncoding elementEncoding = getEncoder().getType(element.getKey()).getEncoding(element.getKey()); - elementEncoding.writeConstructor(); - elementEncoding.writeValue(element.getKey()); - elementEncoding = getEncoder().getType(element.getValue()).getEncoding(element.getValue()); - elementEncoding.writeConstructor(); - elementEncoding.writeValue(element.getValue()); - } - } - - @Override - protected int getEncodedValueSize(final Map val) - { - return 4 + ((val == _value) ? _length : calculateSize(val, getEncoder())); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.MAP32; - } - - public MapType getType() - { - return MapType.this; - } - - public boolean encodesSuperset(final TypeEncoding<Map> encoding) - { - return (getType() == encoding.getType()); - } - - public Map readValue() - { - - DecoderImpl decoder = getDecoder(); - int size = decoder.readRawInt(); - // todo - limit the decoder with size - int count = decoder.readRawInt(); - Map map = new HashMap(count); - for(int i = 0; i < count; i++) - { - Object key = decoder.readObject(); - i++; - Object value = decoder.readObject(); - map.put(key, value); - } - return map; - } - - public void setValue(final Map value, final int length) - { - _value = value; - _length = length; - } - } - - private class ShortMapEncoding - extends SmallFloatingSizePrimitiveTypeEncoding<Map> - implements MapEncoding - { - - private Map _value; - private int _length; - - public ShortMapEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final Map val) - { - getEncoder().writeRaw((byte)(2*val.size())); - - - Iterator<Map.Entry> iter = val.entrySet().iterator(); - - while(iter.hasNext()) - { - Map.Entry element = iter.next(); - TypeEncoding elementEncoding = getEncoder().getType(element.getKey()).getEncoding(element.getKey()); - elementEncoding.writeConstructor(); - elementEncoding.writeValue(element.getKey()); - elementEncoding = getEncoder().getType(element.getValue()).getEncoding(element.getValue()); - elementEncoding.writeConstructor(); - elementEncoding.writeValue(element.getValue()); - } - } - - @Override - protected int getEncodedValueSize(final Map val) - { - return 1 + ((val == _value) ? _length : calculateSize(val, getEncoder())); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.MAP8; - } - - public MapType getType() - { - return MapType.this; - } - - public boolean encodesSuperset(final TypeEncoding<Map> encoder) - { - return encoder == this; - } - - public Map readValue() - { - DecoderImpl decoder = getDecoder(); - int size = ((int)decoder.readRawByte()) & 0xff; - // todo - limit the decoder with size - int count = ((int)decoder.readRawByte()) & 0xff; - - Map map = new HashMap(count); - for(int i = 0; i < count; i++) - { - Object key = decoder.readObject(); - i++; - Object value = decoder.readObject(); - map.put(key, value); - } - return map; - } - - public void setValue(final Map value, final int length) - { - _value = value; - _length = length; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/NullType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/NullType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/NullType.java deleted file mode 100644 index 5449f9b..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/NullType.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import java.util.Collection; -import java.util.Collections; - -public final class NullType extends AbstractPrimitiveType<Void> -{ - private NullEncoding _nullEncoding; - - NullType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _nullEncoding = new NullEncoding(encoder, decoder); - encoder.register(Void.class, this); - decoder.register(this); - } - - public Class<Void> getTypeClass() - { - return Void.class; - } - - public NullEncoding getEncoding(final Void val) - { - return _nullEncoding; - } - - - public NullEncoding getCanonicalEncoding() - { - return _nullEncoding; - } - - public Collection<NullEncoding> getAllEncodings() - { - return Collections.singleton(_nullEncoding); - } - - public void write() - { - _nullEncoding.write(); - } - - private class NullEncoding extends FixedSizePrimitiveTypeEncoding<Void> - { - - public NullEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 0; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.NULL; - } - - public NullType getType() - { - return NullType.this; - } - - public void writeValue(final Void val) - { - } - - public void writeValue() - { - } - - public boolean encodesSuperset(final TypeEncoding<Void> encoding) - { - return encoding == this; - } - - public Void readValue() - { - return null; - } - - public void write() - { - writeConstructor(); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/PrimitiveType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/PrimitiveType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/PrimitiveType.java deleted file mode 100644 index 25fb9c6..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/PrimitiveType.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import java.util.Collection; - -public interface PrimitiveType<V> extends AMQPType<V> -{ - - PrimitiveTypeEncoding<V> getEncoding(V val); - - PrimitiveTypeEncoding<V> getCanonicalEncoding(); - - Collection<? extends PrimitiveTypeEncoding<V>> getAllEncodings(); - - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/PrimitiveTypeEncoding.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/PrimitiveTypeEncoding.java b/proton-j/codec/src/org/apache/qpid/proton/codec/PrimitiveTypeEncoding.java deleted file mode 100644 index 475d207..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/PrimitiveTypeEncoding.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -public interface PrimitiveTypeEncoding<T> extends TypeEncoding<T> -{ - PrimitiveType<T> getType(); - - byte getEncodingCode(); - - void writeConstructor(); - - int getConstructorSize(); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/ShortType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/ShortType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/ShortType.java deleted file mode 100644 index 7dfe035..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/ShortType.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import java.util.Collection; -import java.util.Collections; - -public class ShortType extends AbstractPrimitiveType<Short> -{ - private ShortEncoding _shortEncoding; - - ShortType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _shortEncoding = new ShortEncoding(encoder, decoder); - encoder.register(Short.class, this); - decoder.register(this); - } - - public Class<Short> getTypeClass() - { - return Short.class; - } - - public ShortEncoding getEncoding(final Short val) - { - return _shortEncoding; - } - - public void write(short s) - { - _shortEncoding.write(s); - } - - public ShortEncoding getCanonicalEncoding() - { - return _shortEncoding; - } - - public Collection<ShortEncoding> getAllEncodings() - { - return Collections.singleton(_shortEncoding); - } - - public class ShortEncoding extends FixedSizePrimitiveTypeEncoding<Short> - { - - public ShortEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 2; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SHORT; - } - - public ShortType getType() - { - return ShortType.this; - } - - public void writeValue(final Short val) - { - getEncoder().writeRaw(val); - } - - public void writeValue(final short val) - { - getEncoder().writeRaw(val); - } - - - public void write(final short s) - { - writeConstructor(); - getEncoder().writeRaw(s); - } - - public boolean encodesSuperset(final TypeEncoding<Short> encoding) - { - return (getType() == encoding.getType()); - } - - public Short readValue() - { - return readPrimitiveValue(); - } - - public short readPrimitiveValue() - { - return getDecoder().readRawShort(); - } - - - @Override - public boolean encodesJavaPrimitive() - { - return true; - } - - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/SmallFloatingSizePrimitiveTypeEncoding.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/SmallFloatingSizePrimitiveTypeEncoding.java b/proton-j/codec/src/org/apache/qpid/proton/codec/SmallFloatingSizePrimitiveTypeEncoding.java deleted file mode 100644 index 75e405a..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/SmallFloatingSizePrimitiveTypeEncoding.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -abstract class SmallFloatingSizePrimitiveTypeEncoding<T> extends FloatingSizePrimitiveTypeEncoding<T> -{ - - SmallFloatingSizePrimitiveTypeEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public int getSizeBytes() - { - return 1; - } - - @Override - protected void writeSize(final T val) - { - getEncoder().writeRaw((byte)getEncodedValueSize(val)); - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/StringType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/StringType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/StringType.java deleted file mode 100644 index da685ae..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/StringType.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; -import java.util.Arrays; -import java.util.Collection; - -public class StringType extends AbstractPrimitiveType<String> -{ - private static final Charset Charset_UTF8 = Charset.forName("UTF-8"); - private static final DecoderImpl.TypeDecoder<String> _stringCreator = - new DecoderImpl.TypeDecoder<String>() - { - - public String decode(final ByteBuffer buf) - { - CharsetDecoder charsetDecoder = Charset_UTF8.newDecoder(); - try - { - CharBuffer charBuf = charsetDecoder.decode(buf); - return charBuf.toString(); - } - catch (CharacterCodingException e) - { - throw new IllegalArgumentException("Cannot parse String"); - } - - } - }; - - - public static interface StringEncoding extends PrimitiveTypeEncoding<String> - { - void setValue(String val, int length); - } - - private final StringEncoding _stringEncoding; - private final StringEncoding _shortStringEncoding; - - StringType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _stringEncoding = new AllStringEncoding(encoder, decoder); - _shortStringEncoding = new ShortStringEncoding(encoder, decoder); - encoder.register(String.class, this); - decoder.register(this); - } - - public Class<String> getTypeClass() - { - return String.class; - } - - public StringEncoding getEncoding(final String val) - { - final int length = calculateUTF8Length(val); - StringEncoding encoding = length <= 255 - ? _shortStringEncoding - : _stringEncoding; - encoding.setValue(val, length); - return encoding; - } - - private static int calculateUTF8Length(final String s) - { - int len = s.length(); - int i = 0; - final int length = s.length(); - while(i < length) - { - char c = s.charAt(i); - if(c > 127) - { - len++; - if(c > 0x07ff) - { - len++; - if(c >= 0xD800 && c <= 0xDBFF) - { - i++; - len++; - } - } - } - i++; - - } - return len; - } - - - public StringEncoding getCanonicalEncoding() - { - return _stringEncoding; - } - - public Collection<StringEncoding> getAllEncodings() - { - return Arrays.asList(_shortStringEncoding, _stringEncoding); - } - - private class AllStringEncoding - extends LargeFloatingSizePrimitiveTypeEncoding<String> - implements StringEncoding - { - - private String _value; - private int _length; - - - public AllStringEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final String val) - { - final CharsetEncoder charsetEncoder = Charset_UTF8.newEncoder(); - getEncoder().writeRaw(new StringWritable(charsetEncoder, val)); - } - - @Override - protected int getEncodedValueSize(final String val) - { - return (val == _value) ? _length : calculateUTF8Length(val); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.STR32; - } - - public StringType getType() - { - return StringType.this; - } - - public boolean encodesSuperset(final TypeEncoding<String> encoding) - { - return (getType() == encoding.getType()); - } - - public String readValue() - { - - DecoderImpl decoder = getDecoder(); - int size = decoder.readRawInt(); - return decoder.readRaw(_stringCreator, size); - } - - public void setValue(final String val, final int length) - { - _value = val; - _length = length; - } - - } - - private class ShortStringEncoding - extends SmallFloatingSizePrimitiveTypeEncoding<String> - implements StringEncoding - { - - private String _value; - private int _length; - - public ShortStringEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - - @Override - protected void writeEncodedValue(final String val) - { - final CharsetEncoder charsetEncoder = Charset_UTF8.newEncoder(); - getEncoder().writeRaw(new StringWritable(charsetEncoder, val)); - } - - @Override - protected int getEncodedValueSize(final String val) - { - return (val == _value) ? _length : calculateUTF8Length(val); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.STR8; - } - - public StringType getType() - { - return StringType.this; - } - - public boolean encodesSuperset(final TypeEncoding<String> encoder) - { - return encoder == this; - } - - public String readValue() - { - - DecoderImpl decoder = getDecoder(); - int size = ((int)decoder.readRawByte()) & 0xff; - return decoder.readRaw(_stringCreator, size); - } - - public void setValue(final String val, final int length) - { - _value = val; - _length = length; - } - } - - - private static class StringWritable implements EncoderImpl.Writable - { - - private final CharsetEncoder _charsetEncoder; - private final String _val; - - public StringWritable(final CharsetEncoder charsetEncoder, final String val) - { - _charsetEncoder = charsetEncoder; - _val = val; - } - - public void writeTo(final ByteBuffer buf) - { - _charsetEncoder.encode(CharBuffer.wrap(_val), buf, true); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/SymbolType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/SymbolType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/SymbolType.java deleted file mode 100644 index ae26c21..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/SymbolType.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import org.apache.qpid.proton.type.Symbol; - -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -public class SymbolType extends AbstractPrimitiveType<Symbol> -{ - private static final Charset ASCII_CHARSET = Charset.forName("US-ASCII"); - private final SymbolEncoding _symbolEncoding; - private final SymbolEncoding _shortSymbolEncoding; - - private final Map<ByteBuffer, Symbol> _symbolCache = new HashMap<ByteBuffer, Symbol>(); - private DecoderImpl.TypeDecoder<Symbol> _symbolCreator = - new DecoderImpl.TypeDecoder<Symbol>() - { - - public Symbol decode(final ByteBuffer buf) - { - - Symbol symbol = _symbolCache.get(buf); - if(symbol == null) - { - byte[] bytes = new byte[buf.limit()]; - buf.get(bytes); - - String str = new String(bytes, ASCII_CHARSET); - symbol = Symbol.getSymbol(str); - - _symbolCache.put(ByteBuffer.wrap(bytes), symbol); - } - return symbol; - } - }; - - public static interface SymbolEncoding extends PrimitiveTypeEncoding<Symbol> - { - - } - - SymbolType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _symbolEncoding = new LongSymbolEncoding(encoder, decoder); - _shortSymbolEncoding = new ShortSymbolEncoding(encoder, decoder); - encoder.register(Symbol.class, this); - decoder.register(this); - } - - public Class<Symbol> getTypeClass() - { - return Symbol.class; - } - - public SymbolEncoding getEncoding(final Symbol val) - { - return val.length() <= 255 ? _shortSymbolEncoding : _symbolEncoding; - } - - - public SymbolEncoding getCanonicalEncoding() - { - return _symbolEncoding; - } - - public Collection<SymbolEncoding> getAllEncodings() - { - return Arrays.asList(_shortSymbolEncoding, _symbolEncoding); - } - - private class LongSymbolEncoding - extends LargeFloatingSizePrimitiveTypeEncoding<Symbol> - implements SymbolEncoding - { - - public LongSymbolEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final Symbol val) - { - final int length = val.length(); - final EncoderImpl encoder = getEncoder(); - - for(int i = 0; i < length; i++) - { - encoder.writeRaw((byte)val.charAt(i)); - } - } - - @Override - protected int getEncodedValueSize(final Symbol val) - { - return val.length(); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SYM32; - } - - public SymbolType getType() - { - return SymbolType.this; - } - - public boolean encodesSuperset(final TypeEncoding<Symbol> encoding) - { - return (getType() == encoding.getType()); - } - - public Symbol readValue() - { - DecoderImpl decoder = getDecoder(); - int size = decoder.readRawInt(); - return decoder.readRaw(_symbolCreator, size); - } - } - - private class ShortSymbolEncoding - extends SmallFloatingSizePrimitiveTypeEncoding<Symbol> - implements SymbolEncoding - { - - public ShortSymbolEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected void writeEncodedValue(final Symbol val) - { - - final int length = val.length(); - final EncoderImpl encoder = getEncoder(); - - for(int i = 0; i < length; i++) - { - encoder.writeRaw((byte)val.charAt(i)); - } - } - - @Override - protected int getEncodedValueSize(final Symbol val) - { - return val.length(); - } - - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SYM8; - } - - public SymbolType getType() - { - return SymbolType.this; - } - - public boolean encodesSuperset(final TypeEncoding<Symbol> encoder) - { - return encoder == this; - } - - public Symbol readValue() - { - DecoderImpl decoder = getDecoder(); - int size = ((int)decoder.readRawByte()) & 0xff; - return decoder.readRaw(_symbolCreator, size); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/TimestampType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/TimestampType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/TimestampType.java deleted file mode 100644 index 54baa25..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/TimestampType.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import java.util.Collection; -import java.util.Collections; -import java.util.Date; - -public class TimestampType extends AbstractPrimitiveType<Date> -{ - private TimestampEncoding _timestampEncoding; - - TimestampType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _timestampEncoding = new TimestampEncoding(encoder, decoder); - encoder.register(Date.class, this); - decoder.register(this); - } - - public Class<Date> getTypeClass() - { - return Date.class; - } - - public TimestampEncoding getEncoding(final Date val) - { - return _timestampEncoding; - } - - - public TimestampEncoding getCanonicalEncoding() - { - return _timestampEncoding; - } - - public Collection<TimestampEncoding> getAllEncodings() - { - return Collections.singleton(_timestampEncoding); - } - - public void write(long l) - { - _timestampEncoding.write(l); - } - - private class TimestampEncoding extends FixedSizePrimitiveTypeEncoding<Date> - { - - public TimestampEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 8; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.TIMESTAMP; - } - - public TimestampType getType() - { - return TimestampType.this; - } - - public void writeValue(final Date val) - { - getEncoder().writeRaw(val.getTime()); - } - - public void write(final long l) - { - writeConstructor(); - getEncoder().writeRaw(l); - - } - - public boolean encodesSuperset(final TypeEncoding<Date> encoding) - { - return (getType() == encoding.getType()); - } - - public Date readValue() - { - return new Date(getDecoder().readRawLong()); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/TypeConstructor.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/TypeConstructor.java b/proton-j/codec/src/org/apache/qpid/proton/codec/TypeConstructor.java deleted file mode 100644 index 7b3f3a0..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/TypeConstructor.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -public interface TypeConstructor<V> -{ - V readValue(); - - boolean encodesJavaPrimitive(); - - Class<V> getTypeClass(); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/TypeEncoding.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/TypeEncoding.java b/proton-j/codec/src/org/apache/qpid/proton/codec/TypeEncoding.java deleted file mode 100644 index ad31576..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/TypeEncoding.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -public interface TypeEncoding<V> extends TypeConstructor<V> -{ - AMQPType<V> getType(); - - void writeConstructor(); - - int getConstructorSize(); - - void writeValue(V val); - - int getValueSize(V val); - - boolean isFixedSizeVal(); - - boolean encodesSuperset(TypeEncoding<V> encoder); - - boolean encodesJavaPrimitive(); -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/UUIDType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/UUIDType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/UUIDType.java deleted file mode 100644 index 20b9002..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/UUIDType.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import java.util.Collection; -import java.util.Collections; -import java.util.UUID; - -public class UUIDType extends AbstractPrimitiveType<UUID> -{ - private UUIDEncoding _uuidEncoding; - - UUIDType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _uuidEncoding = new UUIDEncoding(encoder, decoder); - encoder.register(UUID.class, this); - decoder.register(this); - } - - public Class<UUID> getTypeClass() - { - return UUID.class; - } - - public UUIDEncoding getEncoding(final UUID val) - { - return _uuidEncoding; - } - - - public UUIDEncoding getCanonicalEncoding() - { - return _uuidEncoding; - } - - public Collection<UUIDEncoding> getAllEncodings() - { - return Collections.singleton(_uuidEncoding); - } - - private class UUIDEncoding extends FixedSizePrimitiveTypeEncoding<UUID> - { - - public UUIDEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 16; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.UUID; - } - - public UUIDType getType() - { - return UUIDType.this; - } - - public void writeValue(final UUID val) - { - getEncoder().writeRaw(val.getMostSignificantBits()); - getEncoder().writeRaw(val.getLeastSignificantBits()); - } - - public boolean encodesSuperset(final TypeEncoding<UUID> encoding) - { - return (getType() == encoding.getType()); - } - - public UUID readValue() - { - long msb = getDecoder().readRawLong(); - long lsb = getDecoder().readRawLong(); - - return new UUID(msb, lsb); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedByteType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedByteType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedByteType.java deleted file mode 100644 index f4d00d6..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedByteType.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import org.apache.qpid.proton.type.UnsignedByte; - -import java.util.Collection; -import java.util.Collections; - -public class UnsignedByteType extends AbstractPrimitiveType<UnsignedByte> -{ - private UnsignedByteEncoding _unsignedByteEncoding; - - UnsignedByteType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _unsignedByteEncoding = new UnsignedByteEncoding(encoder, decoder); - encoder.register(UnsignedByte.class, this); - decoder.register(this); - } - - public Class<UnsignedByte> getTypeClass() - { - return UnsignedByte.class; - } - - public UnsignedByteEncoding getEncoding(final UnsignedByte val) - { - return _unsignedByteEncoding; - } - - - public UnsignedByteEncoding getCanonicalEncoding() - { - return _unsignedByteEncoding; - } - - public Collection<UnsignedByteEncoding> getAllEncodings() - { - return Collections.singleton(_unsignedByteEncoding); - } - - public class UnsignedByteEncoding extends FixedSizePrimitiveTypeEncoding<UnsignedByte> - { - - public UnsignedByteEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 1; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.UBYTE; - } - - public UnsignedByteType getType() - { - return UnsignedByteType.this; - } - - public void writeValue(final UnsignedByte val) - { - getEncoder().writeRaw(val.byteValue()); - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedByte> encoding) - { - return (getType() == encoding.getType()); - } - - public UnsignedByte readValue() - { - return UnsignedByte.valueOf(getDecoder().readRawByte()); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedIntegerType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedIntegerType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedIntegerType.java deleted file mode 100644 index 850164e..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedIntegerType.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import org.apache.qpid.proton.type.UnsignedInteger; - -import java.util.Arrays; -import java.util.Collection; - -public class UnsignedIntegerType extends AbstractPrimitiveType<UnsignedInteger> -{ - public static interface UnsignedIntegerEncoding extends PrimitiveTypeEncoding<UnsignedInteger> - { - - } - - private UnsignedIntegerEncoding _unsignedIntegerEncoding; - private UnsignedIntegerEncoding _smallUnsignedIntegerEncoding; - private UnsignedIntegerEncoding _zeroUnsignedIntegerEncoding; - - - UnsignedIntegerType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _unsignedIntegerEncoding = new AllUnsignedIntegerEncoding(encoder, decoder); - _smallUnsignedIntegerEncoding = new SmallUnsignedIntegerEncoding(encoder, decoder); - _zeroUnsignedIntegerEncoding = new ZeroUnsignedIntegerEncoding(encoder, decoder); - encoder.register(UnsignedInteger.class, this); - decoder.register(this); - } - - public Class<UnsignedInteger> getTypeClass() - { - return UnsignedInteger.class; - } - - public UnsignedIntegerEncoding getEncoding(final UnsignedInteger val) - { - int i = val.intValue(); - return i == 0 - ? _zeroUnsignedIntegerEncoding - : (i <= 255) ? _smallUnsignedIntegerEncoding : _unsignedIntegerEncoding; - } - - - public UnsignedIntegerEncoding getCanonicalEncoding() - { - return _unsignedIntegerEncoding; - } - - public Collection<UnsignedIntegerEncoding> getAllEncodings() - { - return Arrays.asList(_unsignedIntegerEncoding, _smallUnsignedIntegerEncoding, _zeroUnsignedIntegerEncoding); - } - - - private class AllUnsignedIntegerEncoding - extends FixedSizePrimitiveTypeEncoding<UnsignedInteger> - implements UnsignedIntegerEncoding - { - - public AllUnsignedIntegerEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 4; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.UINT; - } - - public UnsignedIntegerType getType() - { - return UnsignedIntegerType.this; - } - - public void writeValue(final UnsignedInteger val) - { - getEncoder().writeRaw(val.intValue()); - } - - public void write(final int i) - { - writeConstructor(); - getEncoder().writeRaw(i); - - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedInteger> encoding) - { - return (getType() == encoding.getType()); - } - - public UnsignedInteger readValue() - { - return UnsignedInteger.valueOf(getDecoder().readRawInt()); - } - } - - private class SmallUnsignedIntegerEncoding - extends FixedSizePrimitiveTypeEncoding<UnsignedInteger> - implements UnsignedIntegerEncoding - { - public SmallUnsignedIntegerEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SMALLUINT; - } - - @Override - protected int getFixedSize() - { - return 1; - } - - - public UnsignedIntegerType getType() - { - return UnsignedIntegerType.this; - } - - public void writeValue(final UnsignedInteger val) - { - getEncoder().writeRaw((byte)val.intValue()); - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedInteger> encoder) - { - return encoder == this || encoder instanceof ZeroUnsignedIntegerEncoding; - } - - public UnsignedInteger readValue() - { - return UnsignedInteger.valueOf(((int)getDecoder().readRawByte()) & 0xff); - } - } - - - private class ZeroUnsignedIntegerEncoding - extends FixedSizePrimitiveTypeEncoding<UnsignedInteger> - implements UnsignedIntegerEncoding - { - public ZeroUnsignedIntegerEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.UINT0; - } - - @Override - protected int getFixedSize() - { - return 0; - } - - - public UnsignedIntegerType getType() - { - return UnsignedIntegerType.this; - } - - public void writeValue(final UnsignedInteger val) - { - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedInteger> encoder) - { - return encoder == this; - } - - public UnsignedInteger readValue() - { - return UnsignedInteger.ZERO; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedLongType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedLongType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedLongType.java deleted file mode 100644 index a85af37..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedLongType.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import org.apache.qpid.proton.type.UnsignedLong; - -import java.util.Arrays; -import java.util.Collection; - -public class UnsignedLongType extends AbstractPrimitiveType<UnsignedLong> -{ - public static interface UnsignedLongEncoding extends PrimitiveTypeEncoding<UnsignedLong> - { - - } - - private UnsignedLongEncoding _unsignedLongEncoding; - private UnsignedLongEncoding _smallUnsignedLongEncoding; - private UnsignedLongEncoding _zeroUnsignedLongEncoding; - - - UnsignedLongType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _unsignedLongEncoding = new AllUnsignedLongEncoding(encoder, decoder); - _smallUnsignedLongEncoding = new SmallUnsignedLongEncoding(encoder, decoder); - _zeroUnsignedLongEncoding = new ZeroUnsignedLongEncoding(encoder, decoder); - encoder.register(UnsignedLong.class, this); - decoder.register(this); - } - - public Class<UnsignedLong> getTypeClass() - { - return UnsignedLong.class; - } - - public UnsignedLongEncoding getEncoding(final UnsignedLong val) - { - long l = val.longValue(); - return l == 0L - ? _zeroUnsignedLongEncoding - : (l <= 255L) ? _smallUnsignedLongEncoding : _unsignedLongEncoding; - } - - - public UnsignedLongEncoding getCanonicalEncoding() - { - return _unsignedLongEncoding; - } - - public Collection<UnsignedLongEncoding> getAllEncodings() - { - return Arrays.asList(_zeroUnsignedLongEncoding, _smallUnsignedLongEncoding, _unsignedLongEncoding); - } - - - private class AllUnsignedLongEncoding - extends FixedSizePrimitiveTypeEncoding<UnsignedLong> - implements UnsignedLongEncoding - { - - public AllUnsignedLongEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 8; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.ULONG; - } - - public UnsignedLongType getType() - { - return UnsignedLongType.this; - } - - public void writeValue(final UnsignedLong val) - { - getEncoder().writeRaw(val.longValue()); - } - - - public boolean encodesSuperset(final TypeEncoding<UnsignedLong> encoding) - { - return (getType() == encoding.getType()); - } - - public UnsignedLong readValue() - { - return UnsignedLong.valueOf(getDecoder().readRawLong()); - } - } - - private class SmallUnsignedLongEncoding - extends FixedSizePrimitiveTypeEncoding<UnsignedLong> - implements UnsignedLongEncoding - { - public SmallUnsignedLongEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.SMALLULONG; - } - - @Override - protected int getFixedSize() - { - return 1; - } - - - public UnsignedLongType getType() - { - return UnsignedLongType.this; - } - - public void writeValue(final UnsignedLong val) - { - getEncoder().writeRaw((byte)val.longValue()); - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedLong> encoder) - { - return encoder == this || encoder instanceof ZeroUnsignedLongEncoding; - } - - public UnsignedLong readValue() - { - return UnsignedLong.valueOf(((long)getDecoder().readRawByte())&0xffl); - } - } - - - private class ZeroUnsignedLongEncoding - extends FixedSizePrimitiveTypeEncoding<UnsignedLong> - implements UnsignedLongEncoding - { - public ZeroUnsignedLongEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.ULONG0; - } - - @Override - protected int getFixedSize() - { - return 0; - } - - - public UnsignedLongType getType() - { - return UnsignedLongType.this; - } - - public void writeValue(final UnsignedLong val) - { - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedLong> encoder) - { - return encoder == this; - } - - public UnsignedLong readValue() - { - return UnsignedLong.ZERO; - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedShortType.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedShortType.java b/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedShortType.java deleted file mode 100644 index 7774fd9..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/codec/UnsignedShortType.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.codec; - -import org.apache.qpid.proton.type.UnsignedShort; - -import java.util.Collection; -import java.util.Collections; - -public class UnsignedShortType extends AbstractPrimitiveType<UnsignedShort> -{ - private UnsignedShortEncoding _unsignedShortEncoder; - - UnsignedShortType(final EncoderImpl encoder, final DecoderImpl decoder) - { - _unsignedShortEncoder = new UnsignedShortEncoding(encoder, decoder); - encoder.register(UnsignedShort.class, this); - decoder.register(this); - } - - public Class<UnsignedShort> getTypeClass() - { - return UnsignedShort.class; - } - - public UnsignedShortEncoding getEncoding(final UnsignedShort val) - { - return _unsignedShortEncoder; - } - - - public UnsignedShortEncoding getCanonicalEncoding() - { - return _unsignedShortEncoder; - } - - public Collection<UnsignedShortEncoding> getAllEncodings() - { - return Collections.singleton(_unsignedShortEncoder); - } - - private class UnsignedShortEncoding extends FixedSizePrimitiveTypeEncoding<UnsignedShort> - { - - public UnsignedShortEncoding(final EncoderImpl encoder, final DecoderImpl decoder) - { - super(encoder, decoder); - } - - @Override - protected int getFixedSize() - { - return 2; - } - - @Override - public byte getEncodingCode() - { - return EncodingCodes.USHORT; - } - - public UnsignedShortType getType() - { - return UnsignedShortType.this; - } - - public void writeValue(final UnsignedShort val) - { - getEncoder().writeRaw(val.shortValue()); - } - - public boolean encodesSuperset(final TypeEncoding<UnsignedShort> encoding) - { - return (getType() == encoding.getType()); - } - - public UnsignedShort readValue() - { - return UnsignedShort.valueOf(getDecoder().readRawShort()); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/framing/TransportFrame.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/framing/TransportFrame.java b/proton-j/codec/src/org/apache/qpid/proton/framing/TransportFrame.java deleted file mode 100644 index 6523d99..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/framing/TransportFrame.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.framing; - -import org.apache.qpid.proton.type.transport.FrameBody; - -import java.nio.ByteBuffer; - -public class TransportFrame -{ - private final int _channel; - private final FrameBody _body; - private final ByteBuffer _payload; - - - public TransportFrame(final int channel, - final FrameBody body, - final ByteBuffer payload) - { - _payload = payload; - _body = body; - _channel = channel; - } - - public int getChannel() - { - return _channel; - } - - public FrameBody getBody() - { - return _body; - } - - public ByteBuffer getPayload() - { - return _payload; - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/type/AMQPDefinedTypes.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/type/AMQPDefinedTypes.java b/proton-j/codec/src/org/apache/qpid/proton/type/AMQPDefinedTypes.java deleted file mode 100644 index e4aafef..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/type/AMQPDefinedTypes.java +++ /dev/null @@ -1,95 +0,0 @@ - -/* -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you 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.apache.qpid.proton.type; - -import org.apache.qpid.proton.codec.Decoder; - -public class AMQPDefinedTypes -{ - public static void registerAllTypes(Decoder decoder) - { - registerTransportTypes(decoder); - registerMessagingTypes(decoder); - registerTransactionTypes(decoder); - registerSecurityTypes(decoder); - } - - - public static void registerTransportTypes(Decoder decoder) - { - org.apache.qpid.proton.type.transport.Open.register( decoder ); - org.apache.qpid.proton.type.transport.Begin.register( decoder ); - org.apache.qpid.proton.type.transport.Attach.register( decoder ); - org.apache.qpid.proton.type.transport.Flow.register( decoder ); - org.apache.qpid.proton.type.transport.Transfer.register( decoder ); - org.apache.qpid.proton.type.transport.Disposition.register( decoder ); - org.apache.qpid.proton.type.transport.Detach.register( decoder ); - org.apache.qpid.proton.type.transport.End.register( decoder ); - org.apache.qpid.proton.type.transport.Close.register( decoder ); - org.apache.qpid.proton.type.transport.Error.register( decoder ); - } - - public static void registerMessagingTypes(Decoder decoder) - { - org.apache.qpid.proton.type.messaging.Header.register( decoder ); - org.apache.qpid.proton.type.messaging.DeliveryAnnotations.register( decoder ); - org.apache.qpid.proton.type.messaging.MessageAnnotations.register( decoder ); - org.apache.qpid.proton.type.messaging.Properties.register( decoder ); - org.apache.qpid.proton.type.messaging.ApplicationProperties.register( decoder ); - org.apache.qpid.proton.type.messaging.Data.register( decoder ); - org.apache.qpid.proton.type.messaging.AmqpSequence.register( decoder ); - org.apache.qpid.proton.type.messaging.AmqpValue.register( decoder ); - org.apache.qpid.proton.type.messaging.Footer.register( decoder ); - org.apache.qpid.proton.type.messaging.Received.register( decoder ); - org.apache.qpid.proton.type.messaging.Accepted.register( decoder ); - org.apache.qpid.proton.type.messaging.Rejected.register( decoder ); - org.apache.qpid.proton.type.messaging.Released.register( decoder ); - org.apache.qpid.proton.type.messaging.Modified.register( decoder ); - org.apache.qpid.proton.type.messaging.Source.register( decoder ); - org.apache.qpid.proton.type.messaging.Target.register( decoder ); - org.apache.qpid.proton.type.messaging.DeleteOnClose.register( decoder ); - org.apache.qpid.proton.type.messaging.DeleteOnNoLinks.register( decoder ); - org.apache.qpid.proton.type.messaging.DeleteOnNoMessages.register( decoder ); - org.apache.qpid.proton.type.messaging.DeleteOnNoLinksOrMessages.register( decoder ); - } - - public static void registerTransactionTypes(Decoder decoder) - { - org.apache.qpid.proton.type.transaction.Coordinator.register( decoder ); - org.apache.qpid.proton.type.transaction.Declare.register( decoder ); - org.apache.qpid.proton.type.transaction.Discharge.register( decoder ); - org.apache.qpid.proton.type.transaction.Declared.register( decoder ); - org.apache.qpid.proton.type.transaction.TransactionalState.register( decoder ); - } - - public static void registerSecurityTypes(Decoder decoder) - { - org.apache.qpid.proton.type.security.SaslMechanisms.register( decoder ); - org.apache.qpid.proton.type.security.SaslInit.register( decoder ); - org.apache.qpid.proton.type.security.SaslChallenge.register( decoder ); - org.apache.qpid.proton.type.security.SaslResponse.register( decoder ); - org.apache.qpid.proton.type.security.SaslOutcome.register( decoder ); - } - -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/e57c2a52/proton-j/codec/src/org/apache/qpid/proton/type/Binary.java ---------------------------------------------------------------------- diff --git a/proton-j/codec/src/org/apache/qpid/proton/type/Binary.java b/proton-j/codec/src/org/apache/qpid/proton/type/Binary.java deleted file mode 100644 index 3a702af..0000000 --- a/proton-j/codec/src/org/apache/qpid/proton/type/Binary.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.proton.type; - -import java.nio.ByteBuffer; -import java.util.Collection; - -import static java.lang.Math.min; - -public class Binary -{ - - private final byte[] _data; - private final int _offset; - private final int _length; - private final int _hashCode; - - public Binary(final byte[] data) - { - this(data, 0, data.length); - } - - public Binary(final byte[] data, final int offset, final int length) - { - - _data = data; - _offset = offset; - _length = length; - int hc = 0; - for (int i = 0; i < length; i++) - { - hc = 31*hc + (0xFF & data[offset + i]); - } - _hashCode = hc; - } - - public ByteBuffer asByteBuffer() - { - return ByteBuffer.wrap(_data, _offset, _length); - } - - public final int hashCode() - { - return _hashCode; - } - - public final boolean equals(Object o) - { - Binary buf = (Binary) o; - if(o == null) - { - return false; - } - final int size = _length; - if (size != buf._length) - { - return false; - } - - final byte[] myData = _data; - final byte[] theirData = buf._data; - int myOffset = _offset; - int theirOffset = buf._offset; - final int myLimit = myOffset + size; - - while(myOffset < myLimit) - { - if (myData[myOffset++] != theirData[theirOffset++]) - { - return false; - } - } - - return true; - } - - - public int getArrayOffset() - { - return _offset; - } - - public byte[] getArray() - { - return _data; - } - - public int getLength() - { - return _length; - } - - public String toString() - { - StringBuilder str = new StringBuilder(); - - - for (int i = _offset; i < _length; i++) - { - byte c = _data[i]; - - if (c > 31 && c < 127 && c != '\\') - { - str.append((char)c); - } - else - { - str.append(String.format("\\x%02x", c)); - } - } - - return str.toString(); - - } - - public static Binary combine(final Collection<Binary> binaries) - { - - if(binaries.size() == 1) - { - return binaries.iterator().next(); - } - - int size = 0; - for(Binary binary : binaries) - { - size += binary.getLength(); - } - byte[] data = new byte[size]; - int offset = 0; - for(Binary binary : binaries) - { - System.arraycopy(binary._data, binary._offset, data, offset, binary._length); - offset += binary._length; - } - return new Binary(data); - } - - public Binary subBinary(final int offset, final int length) - { - return new Binary(_data, _offset+offset, length); - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
