Added multiple custom tags

This commit is contained in:
Steveice10 2012-03-25 15:35:11 -07:00
parent bf5b435d2a
commit 0abd56a624
24 changed files with 1024 additions and 71 deletions

View File

@ -61,7 +61,14 @@ public final class NBTConstants {
TYPE_LIST = 9,
TYPE_COMPOUND = 10,
TYPE_INT_ARRAY = 11,
TYPE_UNKNOWN = 60;
TYPE_DOUBLE_ARRAY = 60,
TYPE_FLOAT_ARRAY = 61,
TYPE_LONG_ARRAY = 62,
TYPE_OBJECT_ARRAY = 63,
TYPE_OBJECT = 64,
TYPE_SHORT_ARRAY = 65,
TYPE_STRING_ARRAY = 66,
TYPE_UNKNOWN = 67;
/**
* Default private constructor.

View File

@ -5,7 +5,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Logger;
import ch.spacebase.opennbt.exception.InvalidNBTException;
import ch.spacebase.opennbt.tag.ByteArrayTag;
import ch.spacebase.opennbt.tag.ByteTag;
@ -20,9 +19,14 @@ import ch.spacebase.opennbt.tag.LongTag;
import ch.spacebase.opennbt.tag.ShortTag;
import ch.spacebase.opennbt.tag.StringTag;
import ch.spacebase.opennbt.tag.Tag;
import ch.spacebase.opennbt.tag.UnknownTag;
import ch.spacebase.opennbt.tag.custom.DoubleArrayTag;
import ch.spacebase.opennbt.tag.custom.FloatArrayTag;
import ch.spacebase.opennbt.tag.custom.LongArrayTag;
import ch.spacebase.opennbt.tag.custom.ObjectArrayTag;
import ch.spacebase.opennbt.tag.custom.ObjectTag;
import ch.spacebase.opennbt.tag.custom.ShortArrayTag;
import ch.spacebase.opennbt.tag.custom.StringArrayTag;
import ch.spacebase.opennbt.tag.custom.UnknownTag;
/*
* OpenNBT License
@ -95,6 +99,20 @@ public final class NBTUtils {
return "TAG_String";
} else if (clazz.equals(IntArrayTag.class)) {
return "TAG_Int_Array";
} else if (clazz.equals(DoubleArrayTag.class)) {
return "TAG_Double_Array";
} else if (clazz.equals(FloatArrayTag.class)) {
return "TAG_Float_Array";
} else if (clazz.equals(LongArrayTag.class)) {
return "TAG_Long_Array";
} else if (clazz.equals(ObjectArrayTag.class)) {
return "TAG_Object_Array";
} else if (clazz.equals(ObjectTag.class)) {
return "TAG_Object";
} else if (clazz.equals(ShortArrayTag.class)) {
return "TAG_Short_Array";
} else if (clazz.equals(StringArrayTag.class)) {
return "TAG_String_Array";
} else if (clazz.equals(UnknownTag.class)) {
return "TAG_Unknown";
} else {
@ -134,6 +152,20 @@ public final class NBTUtils {
return NBTConstants.TYPE_STRING;
} else if(clazz.equals(IntArrayTag.class)) {
return NBTConstants.TYPE_INT_ARRAY;
} else if(clazz.equals(DoubleArrayTag.class)) {
return NBTConstants.TYPE_DOUBLE_ARRAY;
} else if(clazz.equals(FloatArrayTag.class)) {
return NBTConstants.TYPE_FLOAT_ARRAY;
} else if(clazz.equals(LongArrayTag.class)) {
return NBTConstants.TYPE_LONG_ARRAY;
} else if(clazz.equals(ObjectArrayTag.class)) {
return NBTConstants.TYPE_OBJECT_ARRAY;
} else if(clazz.equals(ObjectTag.class)) {
return NBTConstants.TYPE_OBJECT;
} else if(clazz.equals(ShortArrayTag.class)) {
return NBTConstants.TYPE_SHORT_ARRAY;
} else if(clazz.equals(StringArrayTag.class)) {
return NBTConstants.TYPE_STRING_ARRAY;
} else if(clazz.equals(UnknownTag.class)) {
return NBTConstants.TYPE_UNKNOWN;
} else {
@ -197,42 +229,6 @@ public final class NBTUtils {
return newMap;
}
/**
* Clones a byte array
* @param array to clone
* @return clone of array
*/
public static byte[] cloneByteArray(byte[] array) {
if(array == null) {
return null;
} else {
int size = array.length;
byte[] newArray = new byte[size];
System.arraycopy(array, 0, newArray, 0, size);
return newArray;
}
}
/**
* Clones an int array
* @param array to clone
* @return clone of array
*/
public static int[] cloneIntArray(int[] array) {
if(array == null) {
return null;
} else {
int size = array.length;
int[] newArray = new int[size];
System.arraycopy(array, 0, newArray, 0, size);
return newArray;
}
}
/**
* Get child tag of a NBT structure.
*

View File

@ -38,6 +38,7 @@ import java.io.Closeable;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -60,7 +61,14 @@ import ch.spacebase.opennbt.tag.LongTag;
import ch.spacebase.opennbt.tag.ShortTag;
import ch.spacebase.opennbt.tag.StringTag;
import ch.spacebase.opennbt.tag.Tag;
import ch.spacebase.opennbt.tag.UnknownTag;
import ch.spacebase.opennbt.tag.custom.DoubleArrayTag;
import ch.spacebase.opennbt.tag.custom.FloatArrayTag;
import ch.spacebase.opennbt.tag.custom.LongArrayTag;
import ch.spacebase.opennbt.tag.custom.ObjectArrayTag;
import ch.spacebase.opennbt.tag.custom.ObjectTag;
import ch.spacebase.opennbt.tag.custom.ShortArrayTag;
import ch.spacebase.opennbt.tag.custom.StringArrayTag;
import ch.spacebase.opennbt.tag.custom.UnknownTag;
/**
* <p>This class reads <strong>NBT</strong>, or
@ -201,6 +209,84 @@ public final class NBTInputStream implements Closeable {
}
return new IntArrayTag(name, data);
case NBTConstants.TYPE_DOUBLE_ARRAY:
length = is.readInt();
double[] dat = new double[length];
for (int i = 0; i < length; i++) {
dat[i] = is.readDouble();
}
return new DoubleArrayTag(name, dat);
case NBTConstants.TYPE_FLOAT_ARRAY:
length = is.readInt();
float[] floats = new float[length];
for (int i = 0; i < length; i++) {
floats[i] = is.readFloat();
}
return new FloatArrayTag(name, floats);
case NBTConstants.TYPE_LONG_ARRAY:
length = is.readInt();
long[] longs = new long[length];
for (int i = 0; i < length; i++) {
longs[i] = is.readLong();
}
return new LongArrayTag(name, longs);
case NBTConstants.TYPE_OBJECT_ARRAY:
length = is.readInt();
Object[] objs = new Object[length];
ObjectInputStream str = new ObjectInputStream(is);
for(int i = 0; i < length; i++) {
try {
objs[i] = str.readObject();
} catch (ClassNotFoundException e) {
logger.severe("Class not found while reading ObjectTag!");
e.printStackTrace();
continue;
}
}
return new ObjectArrayTag(name, objs);
case NBTConstants.TYPE_OBJECT:
str = new ObjectInputStream(is);
Object o = null;
try {
o = str.readObject();
} catch (ClassNotFoundException e) {
logger.severe("Class not found while reading ObjectTag!");
e.printStackTrace();
return null;
}
return new ObjectTag(name, o);
case NBTConstants.TYPE_SHORT_ARRAY:
length = is.readInt();
short[] shorts = new short[length];
for (int i = 0; i < length; i++) {
shorts[i] = is.readShort();
}
return new ShortArrayTag(name, shorts);
case NBTConstants.TYPE_STRING_ARRAY:
length = is.readInt();
String[] strings = new String[length];
for(int i = 0; i < length; i++) {
int size = is.readShort();
bytes = new byte[size];
is.readFully(bytes);
strings[i] = new String(bytes, NBTConstants.CHARSET);
}
return new StringArrayTag(name, strings);
default:
logger.warning("Unknown tag found while reading.");
return new UnknownTag(name);

View File

@ -3,6 +3,7 @@ package ch.spacebase.opennbt.stream;
import java.io.Closeable;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.logging.Logger;
import java.util.zip.GZIPOutputStream;
@ -22,6 +23,13 @@ import ch.spacebase.opennbt.tag.LongTag;
import ch.spacebase.opennbt.tag.ShortTag;
import ch.spacebase.opennbt.tag.StringTag;
import ch.spacebase.opennbt.tag.Tag;
import ch.spacebase.opennbt.tag.custom.DoubleArrayTag;
import ch.spacebase.opennbt.tag.custom.FloatArrayTag;
import ch.spacebase.opennbt.tag.custom.LongArrayTag;
import ch.spacebase.opennbt.tag.custom.ObjectArrayTag;
import ch.spacebase.opennbt.tag.custom.ObjectTag;
import ch.spacebase.opennbt.tag.custom.ShortArrayTag;
import ch.spacebase.opennbt.tag.custom.StringArrayTag;
/*
* OpenNBT License
@ -154,6 +162,27 @@ public final class NBTOutputStream implements Closeable {
case NBTConstants.TYPE_INT_ARRAY:
writeIntArrayTagPayload((IntArrayTag) tag);
break;
case NBTConstants.TYPE_DOUBLE_ARRAY:
writeDoubleArrayTagPayload((DoubleArrayTag) tag);
break;
case NBTConstants.TYPE_FLOAT_ARRAY:
writeFloatArrayTagPayload((FloatArrayTag) tag);
break;
case NBTConstants.TYPE_LONG_ARRAY:
writeLongArrayTagPayload((LongArrayTag) tag);
break;
case NBTConstants.TYPE_OBJECT_ARRAY:
writeObjectArrayTagPayload((ObjectArrayTag) tag);
break;
case NBTConstants.TYPE_OBJECT:
writeObjectTagPayload((ObjectTag) tag);
break;
case NBTConstants.TYPE_SHORT_ARRAY:
writeShortArrayTagPayload((ShortArrayTag) tag);
break;
case NBTConstants.TYPE_STRING_ARRAY:
writeStringArrayTagPayload((StringArrayTag) tag);
break;
default:
logger.warning("Unknown tag found while writing, ignoring...");
}
@ -285,6 +314,102 @@ public final class NBTOutputStream implements Closeable {
os.writeInt(data[i]);
}
}
/** Writes a <code>TAG_Double_Array<code> tag.
* @param tag The tag
* @throws IOException if an I/O error occurs.
*/
private void writeDoubleArrayTagPayload(DoubleArrayTag tag) throws IOException {
double[] data = tag.getValue();
os.writeInt(data.length);
for (int i = 0; i < data.length; i++) {
os.writeDouble(data[i]);
}
}
/** Writes a <code>TAG_Float_Array<code> tag.
* @param tag The tag
* @throws IOException if an I/O error occurs.
*/
private void writeFloatArrayTagPayload(FloatArrayTag tag) throws IOException {
float[] data = tag.getValue();
os.writeInt(data.length);
for (int i = 0; i < data.length; i++) {
os.writeFloat(data[i]);
}
}
/** Writes a <code>TAG_Long_Array<code> tag.
* @param tag The tag
* @throws IOException if an I/O error occurs.
*/
private void writeLongArrayTagPayload(LongArrayTag tag) throws IOException {
long[] data = tag.getValue();
os.writeInt(data.length);
for (int i = 0; i < data.length; i++) {
os.writeLong(data[i]);
}
}
/** Writes a <code>TAG_Object_Array<code> tag.
* @param tag The tag
* @throws IOException if an I/O error occurs.
*/
private void writeObjectArrayTagPayload(ObjectArrayTag tag) throws IOException {
Object[] data = tag.getValue();
os.writeInt(data.length);
ObjectOutputStream str = new ObjectOutputStream(os);
for (int i = 0; i < data.length; i++) {
str.writeObject(data[i]);
}
}
/** Writes a <code>TAG_Object<code> tag.
* @param tag The tag
* @throws IOException if an I/O error occurs.
*/
private void writeObjectTagPayload(ObjectTag tag) throws IOException {
(new ObjectOutputStream(os)).writeObject(tag.getValue());
}
/** Writes a <code>TAG_Short_Array<code> tag.
* @param tag The tag
* @throws IOException if an I/O error occurs.
*/
private void writeShortArrayTagPayload(ShortArrayTag tag) throws IOException {
short[] data = tag.getValue();
os.writeInt(data.length);
for (int i = 0; i < data.length; i++) {
os.writeShort(data[i]);
}
}
/** Writes a <code>TAG_String_Array<code> tag.
* @param tag The tag
* @throws IOException if an I/O error occurs.
*/
private void writeStringArrayTagPayload(StringArrayTag tag) throws IOException {
String[] data = tag.getValue();
os.writeInt(data.length);
byte[] bytes;
for (int i = 0; i < data.length; i++) {
bytes = data[i].getBytes(NBTConstants.CHARSET);
os.writeShort(bytes.length);
os.write(bytes);
}
}
@Override
public void close() throws IOException {

View File

@ -2,11 +2,6 @@ package ch.spacebase.opennbt.tag;
import java.util.Arrays;
import ch.spacebase.opennbt.NBTUtils;
/*
* OpenNBT License
*
@ -68,20 +63,14 @@ public final class ByteArrayTag extends Tag {
@Override
public String toString() {
StringBuilder hex = new StringBuilder();
for(byte b : value) {
String hexDigits = Integer.toHexString(b).toUpperCase();
if(hexDigits.length() == 1) {
hex.append("0");
}
hex.append(hexDigits).append(" ");
}
String name = getName();
String append = "";
if(name != null && !name.equals("")) {
append = "(\"" + this.getName() + "\")";
}
return "TAG_Byte_Array" + append + ": " + hex.toString();
return "TAG_Byte_Array" + append + ": " + Arrays.toString(value);
}
@Override
@ -93,8 +82,8 @@ public final class ByteArrayTag extends Tag {
return Arrays.equals(this.getValue(), tag.getValue()) && this.getName().equals(tag.getName());
}
public Tag clone() {
byte[] clonedArray = NBTUtils.cloneByteArray(this.getValue());
public ByteArrayTag clone() {
byte[] clonedArray = this.getValue().clone();
return new ByteArrayTag(this.getName(), clonedArray);
}

View File

@ -69,7 +69,7 @@ public final class ByteTag extends Tag {
return "TAG_Byte" + append + ": " + value;
}
public Tag clone() {
public ByteTag clone() {
return new ByteTag(this.getName(), this.getValue());
}

View File

@ -98,7 +98,7 @@ public final class CompoundTag extends Tag {
return bldr.toString();
}
public Tag clone() {
public CompoundTag clone() {
Map<String, Tag> newMap = NBTUtils.cloneMap(this.getValue());
return new CompoundTag(this.getName(), newMap);

View File

@ -69,7 +69,7 @@ public final class DoubleTag extends Tag {
return "TAG_Double" + append + ": " + value;
}
public Tag clone() {
public DoubleTag clone() {
return new DoubleTag(this.getName(), this.getValue());
}

View File

@ -56,7 +56,7 @@ public final class EndTag extends Tag {
return "TAG_End";
}
public Tag clone() {
public EndTag clone() {
return new EndTag();
}

View File

@ -69,7 +69,7 @@ public final class FloatTag extends Tag {
return "TAG_Float" + append + ": " + value;
}
public Tag clone() {
public FloatTag clone() {
return new FloatTag(this.getName(), this.getValue());
}

View File

@ -1,6 +1,7 @@
package ch.spacebase.opennbt.tag;
import ch.spacebase.opennbt.NBTUtils;
import java.util.Arrays;
import ch.spacebase.opennbt.tag.Tag;
/*
@ -88,10 +89,19 @@ public final class IntArrayTag extends Tag {
return "TAG_Int_Array" + append + ": " + hex.toString();
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof IntArrayTag)) return false;
IntArrayTag tag = (IntArrayTag) obj;
return Arrays.equals(this.getValue(), tag.getValue()) && this.getName().equals(tag.getName());
}
@Override
public Tag clone() {
int[] clonedArray = NBTUtils.cloneIntArray(this.getValue());
public IntArrayTag clone() {
int[] clonedArray = this.getValue().clone();
return new IntArrayTag(this.getName(), clonedArray);
}

View File

@ -69,7 +69,7 @@ public final class IntTag extends Tag {
return "TAG_Int" + append + ": " + value;
}
public Tag clone() {
public IntTag clone() {
return new IntTag(this.getName(), this.getValue());
}

View File

@ -113,7 +113,7 @@ public final class ListTag<T extends Tag> extends Tag implements Iterable<T> {
}
@SuppressWarnings("unchecked")
public Tag clone() {
public ListTag<T> clone() {
List<T> newList = new ArrayList<T>();
for(T value : this.getValue()) {

View File

@ -69,7 +69,7 @@ public final class LongTag extends Tag {
return "TAG_Long" + append + ": " + value;
}
public Tag clone() {
public LongTag clone() {
return new LongTag(this.getName(), this.getValue());
}

View File

@ -69,7 +69,7 @@ public final class ShortTag extends Tag {
return "TAG_Short" + append + ": " + value;
}
public Tag clone() {
public ShortTag clone() {
return new ShortTag(this.getName(), this.getValue());
}

View File

@ -69,7 +69,7 @@ public final class StringTag extends Tag {
return "TAG_String" + append + ": " + value;
}
public Tag clone() {
public StringTag clone() {
return new StringTag(this.getName(), this.getValue());
}

View File

@ -0,0 +1,97 @@
package ch.spacebase.opennbt.tag.custom;
import java.util.Arrays;
import ch.spacebase.opennbt.tag.Tag;
/*
* OpenNBT License
*
* JNBT Copyright (c) 2010 Graham Edgecombe
* OpenNBT Copyright(c) 2012 Steveice10
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the JNBT team nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The <code>TAG_Double_Array</code> tag.
*/
public final class DoubleArrayTag extends Tag {
/**
* The value.
*/
private final double[] value;
/**
* Creates the tag.
*
* @param name
* The name.
* @param value
* The value.
*/
public DoubleArrayTag(String name, double[] value) {
super(name);
this.value = value;
}
@Override
public double[] getValue() {
return value;
}
@Override
public String toString() {
String name = getName();
String append = "";
if (name != null && !name.equals("")) {
append = "(\"" + this.getName() + "\")";
}
return "TAG_Double_Array" + append + ": " + Arrays.toString(value);
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof DoubleArrayTag)) return false;
DoubleArrayTag tag = (DoubleArrayTag) obj;
return Arrays.equals(this.getValue(), tag.getValue()) && this.getName().equals(tag.getName());
}
@Override
public DoubleArrayTag clone() {
double[] clonedArray = this.getValue().clone();
return new DoubleArrayTag(this.getName(), clonedArray);
}
}

View File

@ -0,0 +1,97 @@
package ch.spacebase.opennbt.tag.custom;
import java.util.Arrays;
import ch.spacebase.opennbt.tag.Tag;
/*
* OpenNBT License
*
* JNBT Copyright (c) 2010 Graham Edgecombe
* OpenNBT Copyright(c) 2012 Steveice10
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the JNBT team nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The <code>TAG_Float_Array</code> tag.
*/
public final class FloatArrayTag extends Tag {
/**
* The value.
*/
private final float[] value;
/**
* Creates the tag.
*
* @param name
* The name.
* @param value
* The value.
*/
public FloatArrayTag(String name, float[] value) {
super(name);
this.value = value;
}
@Override
public float[] getValue() {
return value;
}
@Override
public String toString() {
String name = getName();
String append = "";
if (name != null && !name.equals("")) {
append = "(\"" + this.getName() + "\")";
}
return "TAG_Float_Array" + append + ": " + Arrays.toString(value);
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof FloatArrayTag)) return false;
FloatArrayTag tag = (FloatArrayTag) obj;
return Arrays.equals(this.getValue(), tag.getValue()) && this.getName().equals(tag.getName());
}
@Override
public FloatArrayTag clone() {
float[] clonedArray = this.getValue().clone();
return new FloatArrayTag(this.getName(), clonedArray);
}
}

View File

@ -0,0 +1,97 @@
package ch.spacebase.opennbt.tag.custom;
import java.util.Arrays;
import ch.spacebase.opennbt.tag.Tag;
/*
* OpenNBT License
*
* JNBT Copyright (c) 2010 Graham Edgecombe
* OpenNBT Copyright(c) 2012 Steveice10
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the JNBT team nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The <code>TAG_Long_Array</code> tag.
*/
public final class LongArrayTag extends Tag {
/**
* The value.
*/
private final long[] value;
/**
* Creates the tag.
*
* @param name
* The name.
* @param value
* The value.
*/
public LongArrayTag(String name, long[] value) {
super(name);
this.value = value;
}
@Override
public long[] getValue() {
return value;
}
@Override
public String toString() {
String name = getName();
String append = "";
if (name != null && !name.equals("")) {
append = "(\"" + this.getName() + "\")";
}
return "TAG_Long_Array" + append + ": " + Arrays.toString(value);
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof LongArrayTag)) return false;
LongArrayTag tag = (LongArrayTag) obj;
return Arrays.equals(this.getValue(), tag.getValue()) && this.getName().equals(tag.getName());
}
@Override
public LongArrayTag clone() {
long[] clonedArray = this.getValue().clone();
return new LongArrayTag(this.getName(), clonedArray);
}
}

View File

@ -0,0 +1,96 @@
package ch.spacebase.opennbt.tag.custom;
import java.util.Arrays;
import ch.spacebase.opennbt.tag.Tag;
/*
* OpenNBT License
*
* JNBT Copyright (c) 2010 Graham Edgecombe
* OpenNBT Copyright(c) 2012 Steveice10
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the JNBT team nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The <code>TAG_Object_Array</code> tag.
*/
public final class ObjectArrayTag extends Tag {
/**
* The value.
*/
private final Object[] value;
/**
* Creates the tag.
*
* @param name
* The name.
* @param value
* The value.
*/
public ObjectArrayTag(String name, Object[] value) {
super(name);
this.value = value;
}
@Override
public Object[] getValue() {
return value;
}
@Override
public String toString() {
String name = getName();
String append = "";
if (name != null && !name.equals("")) {
append = "(\"" + this.getName() + "\")";
}
return "TAG_Object_Array" + append + ": " + Arrays.toString(value);
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof ObjectArrayTag)) return false;
ObjectArrayTag tag = (ObjectArrayTag) obj;
return Arrays.equals(this.getValue(), tag.getValue()) && this.getName().equals(tag.getName());
}
@Override
public ObjectArrayTag clone() {
Object[] clonedArray = this.getValue().clone();
return new ObjectArrayTag(this.getName(), clonedArray);
}
}

View File

@ -0,0 +1,78 @@
package ch.spacebase.opennbt.tag.custom;
import ch.spacebase.opennbt.tag.Tag;
/*
* OpenNBT License
*
* JNBT Copyright (c) 2010 Graham Edgecombe
* OpenNBT Copyright(c) 2012 Steveice10
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the JNBT team nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The <code>TAG_Object</code> tag.
*/
public final class ObjectTag extends Tag {
/**
* The value.
*/
private final Object value;
/**
* Creates the tag.
* @param name The name.
* @param value The value.
*/
public ObjectTag(String name, Object value) {
super(name);
this.value = value;
}
@Override
public Object getValue() {
return value;
}
@Override
public String toString() {
String name = getName();
String append = "";
if(name != null && !name.equals("")) {
append = "(\"" + this.getName() + "\")";
}
return "TAG_Object" + append + ": " + value.toString();
}
public ObjectTag clone() {
return new ObjectTag(this.getName(), this.getValue());
}
}

View File

@ -0,0 +1,97 @@
package ch.spacebase.opennbt.tag.custom;
import java.util.Arrays;
import ch.spacebase.opennbt.tag.Tag;
/*
* OpenNBT License
*
* JNBT Copyright (c) 2010 Graham Edgecombe
* OpenNBT Copyright(c) 2012 Steveice10
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the JNBT team nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The <code>TAG_Short_Array</code> tag.
*/
public final class ShortArrayTag extends Tag {
/**
* The value.
*/
private final short[] value;
/**
* Creates the tag.
*
* @param name
* The name.
* @param value
* The value.
*/
public ShortArrayTag(String name, short[] value) {
super(name);
this.value = value;
}
@Override
public short[] getValue() {
return value;
}
@Override
public String toString() {
String name = getName();
String append = "";
if (name != null && !name.equals("")) {
append = "(\"" + this.getName() + "\")";
}
return "TAG_Short_Array" + append + ": " + Arrays.toString(value);
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof ShortArrayTag)) return false;
ShortArrayTag tag = (ShortArrayTag) obj;
return Arrays.equals(this.getValue(), tag.getValue()) && this.getName().equals(tag.getName());
}
@Override
public ShortArrayTag clone() {
short[] clonedArray = this.getValue().clone();
return new ShortArrayTag(this.getName(), clonedArray);
}
}

View File

@ -0,0 +1,97 @@
package ch.spacebase.opennbt.tag.custom;
import java.util.Arrays;
import ch.spacebase.opennbt.tag.Tag;
/*
* OpenNBT License
*
* JNBT Copyright (c) 2010 Graham Edgecombe
* OpenNBT Copyright(c) 2012 Steveice10
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the JNBT team nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The <code>TAG_String_Array</code> tag.
*/
public final class StringArrayTag extends Tag {
/**
* The value.
*/
private final String[] value;
/**
* Creates the tag.
*
* @param name
* The name.
* @param value
* The value.
*/
public StringArrayTag(String name, String[] value) {
super(name);
this.value = value;
}
@Override
public String[] getValue() {
return value;
}
@Override
public String toString() {
String name = getName();
String append = "";
if (name != null && !name.equals("")) {
append = "(\"" + this.getName() + "\")";
}
return "TAG_String_Array" + append + ": " + Arrays.toString(value);
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof StringArrayTag)) return false;
StringArrayTag tag = (StringArrayTag) obj;
return Arrays.equals(this.getValue(), tag.getValue()) && this.getName().equals(tag.getName());
}
@Override
public StringArrayTag clone() {
String[] clonedArray = this.getValue().clone();
return new StringArrayTag(this.getName(), clonedArray);
}
}

View File

@ -0,0 +1,81 @@
package ch.spacebase.opennbt.tag.custom;
import ch.spacebase.opennbt.tag.Tag;
/*
* OpenNBT License
*
* JNBT Copyright (c) 2010 Graham Edgecombe
* OpenNBT Copyright(c) 2012 Steveice10
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the JNBT team nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The <code>TAG_Unknown</code> tag.
*/
public class UnknownTag extends Tag {
/**
* Creates the tag.
* @param name The name.
* @param value The value.
*/
public UnknownTag(String name) {
super(name);
}
@Override
public Object getValue() {
return null;
}
@Override
public String toString() {
String name = getName();
String append = "";
if(name != null && !name.equals("")) {
append = "(\"" + this.getName() + "\")";
}
return "TAG_Unknown" + append;
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof UnknownTag)) return false;
UnknownTag tag = (UnknownTag) obj;
return tag.getName().equals(this.getName());
}
public UnknownTag clone() {
return new UnknownTag(this.getName());
}
}