From 1164dab7161469f5efe66f6ca58f51d7c85795cc Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Fri, 1 Sep 2017 12:52:20 -0700 Subject: [PATCH] Format code. --- .../com/github/steveice10/opennbt/NBTIO.java | 694 +++++++++--------- .../conversion/ConversionException.java | 26 +- .../ConverterRegisterException.java | 26 +- .../opennbt/conversion/ConverterRegistry.java | 239 +++--- .../opennbt/conversion/TagConverter.java | 30 +- .../builtin/ByteArrayTagConverter.java | 16 +- .../conversion/builtin/ByteTagConverter.java | 16 +- .../builtin/CompoundTagConverter.java | 40 +- .../builtin/DoubleTagConverter.java | 16 +- .../conversion/builtin/FloatTagConverter.java | 16 +- .../builtin/IntArrayTagConverter.java | 16 +- .../conversion/builtin/IntTagConverter.java | 16 +- .../conversion/builtin/ListTagConverter.java | 42 +- .../conversion/builtin/LongTagConverter.java | 16 +- .../conversion/builtin/ShortTagConverter.java | 16 +- .../builtin/StringTagConverter.java | 16 +- .../custom/DoubleArrayTagConverter.java | 16 +- .../custom/FloatArrayTagConverter.java | 16 +- .../builtin/custom/LongArrayTagConverter.java | 16 +- .../custom/SerializableArrayTagConverter.java | 16 +- .../custom/SerializableTagConverter.java | 16 +- .../custom/ShortArrayTagConverter.java | 16 +- .../custom/StringArrayTagConverter.java | 16 +- .../opennbt/tag/TagCreateException.java | 26 +- .../opennbt/tag/TagRegisterException.java | 26 +- .../steveice10/opennbt/tag/TagRegistry.java | 168 ++--- .../opennbt/tag/builtin/ByteArrayTag.java | 148 ++-- .../opennbt/tag/builtin/ByteTag.java | 86 +-- .../opennbt/tag/builtin/CompoundTag.java | 292 ++++---- .../opennbt/tag/builtin/DoubleTag.java | 86 +-- .../opennbt/tag/builtin/FloatTag.java | 86 +-- .../opennbt/tag/builtin/IntArrayTag.java | 156 ++-- .../opennbt/tag/builtin/IntTag.java | 86 +-- .../opennbt/tag/builtin/ListTag.java | 312 ++++---- .../opennbt/tag/builtin/LongTag.java | 86 +-- .../opennbt/tag/builtin/ShortTag.java | 86 +-- .../opennbt/tag/builtin/StringTag.java | 86 +-- .../steveice10/opennbt/tag/builtin/Tag.java | 182 ++--- .../tag/builtin/custom/DoubleArrayTag.java | 156 ++-- .../tag/builtin/custom/FloatArrayTag.java | 156 ++-- .../tag/builtin/custom/LongArrayTag.java | 156 ++-- .../builtin/custom/SerializableArrayTag.java | 177 ++--- .../tag/builtin/custom/SerializableTag.java | 241 +++--- .../tag/builtin/custom/ShortArrayTag.java | 156 ++-- .../tag/builtin/custom/StringArrayTag.java | 156 ++-- 45 files changed, 2250 insertions(+), 2213 deletions(-) diff --git a/src/main/java/com/github/steveice10/opennbt/NBTIO.java b/src/main/java/com/github/steveice10/opennbt/NBTIO.java index b2cb482..b098be8 100644 --- a/src/main/java/com/github/steveice10/opennbt/NBTIO.java +++ b/src/main/java/com/github/steveice10/opennbt/NBTIO.java @@ -1,11 +1,23 @@ package com.github.steveice10.opennbt; -import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.TagCreateException; import com.github.steveice10.opennbt.tag.TagRegistry; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.Tag; -import java.io.*; +import java.io.DataInput; +import java.io.DataInputStream; +import java.io.DataOutput; +import java.io.DataOutputStream; +import java.io.EOFException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FilterInputStream; +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; @@ -13,125 +25,125 @@ import java.util.zip.GZIPOutputStream; * A class containing methods for reading/writing NBT tags. */ public class NBTIO { - /** - * Reads the compressed, big endian root CompoundTag from the given file. - * - * @param path Path of the file. - * @return The read compound tag. - * @throws java.io.IOException If an I/O error occurs. - */ - public static CompoundTag readFile(String path) throws IOException { - return readFile(new File(path)); - } + /** + * Reads the compressed, big endian root CompoundTag from the given file. + * + * @param path Path of the file. + * @return The read compound tag. + * @throws java.io.IOException If an I/O error occurs. + */ + public static CompoundTag readFile(String path) throws IOException { + return readFile(new File(path)); + } - /** - * Reads the compressed, big endian root CompoundTag from the given file. - * - * @param file File to read from. - * @return The read compound tag. - * @throws java.io.IOException If an I/O error occurs. - */ - public static CompoundTag readFile(File file) throws IOException { - return readFile(file, true, false); - } + /** + * Reads the compressed, big endian root CompoundTag from the given file. + * + * @param file File to read from. + * @return The read compound tag. + * @throws java.io.IOException If an I/O error occurs. + */ + public static CompoundTag readFile(File file) throws IOException { + return readFile(file, true, false); + } - /** - * Reads the root CompoundTag from the given file. - * - * @param path Path of the file. - * @param compressed Whether the NBT file is compressed. + /** + * Reads the root CompoundTag from the given file. + * + * @param path Path of the file. + * @param compressed Whether the NBT file is compressed. * @param littleEndian Whether the NBT file is little endian. - * @return The read compound tag. - * @throws java.io.IOException If an I/O error occurs. - */ - public static CompoundTag readFile(String path, boolean compressed, boolean littleEndian) throws IOException { - return readFile(new File(path), compressed, littleEndian); - } + * @return The read compound tag. + * @throws java.io.IOException If an I/O error occurs. + */ + public static CompoundTag readFile(String path, boolean compressed, boolean littleEndian) throws IOException { + return readFile(new File(path), compressed, littleEndian); + } - /** - * Reads the root CompoundTag from the given file. - * - * @param file File to read from. - * @param compressed Whether the NBT file is compressed. + /** + * Reads the root CompoundTag from the given file. + * + * @param file File to read from. + * @param compressed Whether the NBT file is compressed. * @param littleEndian Whether the NBT file is little endian. - * @return The read compound tag. - * @throws java.io.IOException If an I/O error occurs. - */ - public static CompoundTag readFile(File file, boolean compressed, boolean littleEndian) throws IOException { - InputStream in = new FileInputStream(file); - if(compressed) { - in = new GZIPInputStream(in); - } + * @return The read compound tag. + * @throws java.io.IOException If an I/O error occurs. + */ + public static CompoundTag readFile(File file, boolean compressed, boolean littleEndian) throws IOException { + InputStream in = new FileInputStream(file); + if(compressed) { + in = new GZIPInputStream(in); + } - Tag tag = readTag(in, littleEndian); - if(!(tag instanceof CompoundTag)) { - throw new IOException("Root tag is not a CompoundTag!"); - } + Tag tag = readTag(in, littleEndian); + if(!(tag instanceof CompoundTag)) { + throw new IOException("Root tag is not a CompoundTag!"); + } - return (CompoundTag) tag; - } + return (CompoundTag) tag; + } - /** - * Writes the given root CompoundTag to the given file, compressed and in big endian. - * - * @param tag Tag to write. - * @param path Path to write to. - * @throws java.io.IOException If an I/O error occurs. - */ - public static void writeFile(CompoundTag tag, String path) throws IOException { - writeFile(tag, new File(path)); - } + /** + * Writes the given root CompoundTag to the given file, compressed and in big endian. + * + * @param tag Tag to write. + * @param path Path to write to. + * @throws java.io.IOException If an I/O error occurs. + */ + public static void writeFile(CompoundTag tag, String path) throws IOException { + writeFile(tag, new File(path)); + } - /** - * Writes the given root CompoundTag to the given file, compressed and in big endian. - * - * @param tag Tag to write. - * @param file File to write to. - * @throws java.io.IOException If an I/O error occurs. - */ - public static void writeFile(CompoundTag tag, File file) throws IOException { - writeFile(tag, file, true, false); - } + /** + * Writes the given root CompoundTag to the given file, compressed and in big endian. + * + * @param tag Tag to write. + * @param file File to write to. + * @throws java.io.IOException If an I/O error occurs. + */ + public static void writeFile(CompoundTag tag, File file) throws IOException { + writeFile(tag, file, true, false); + } - /** - * Writes the given root CompoundTag to the given file. - * - * @param tag Tag to write. - * @param path Path to write to. - * @param compressed Whether the NBT file should be compressed. + /** + * Writes the given root CompoundTag to the given file. + * + * @param tag Tag to write. + * @param path Path to write to. + * @param compressed Whether the NBT file should be compressed. * @param littleEndian Whether to write little endian NBT. - * @throws java.io.IOException If an I/O error occurs. - */ - public static void writeFile(CompoundTag tag, String path, boolean compressed, boolean littleEndian) throws IOException { - writeFile(tag, new File(path), compressed, littleEndian); - } + * @throws java.io.IOException If an I/O error occurs. + */ + public static void writeFile(CompoundTag tag, String path, boolean compressed, boolean littleEndian) throws IOException { + writeFile(tag, new File(path), compressed, littleEndian); + } - /** - * Writes the given root CompoundTag to the given file. - * - * @param tag Tag to write. - * @param file File to write to. - * @param compressed Whether the NBT file should be compressed. + /** + * Writes the given root CompoundTag to the given file. + * + * @param tag Tag to write. + * @param file File to write to. + * @param compressed Whether the NBT file should be compressed. * @param littleEndian Whether to write little endian NBT. - * @throws java.io.IOException If an I/O error occurs. - */ - public static void writeFile(CompoundTag tag, File file, boolean compressed, boolean littleEndian) throws IOException { - if(!file.exists()) { - if(file.getParentFile() != null && !file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } + * @throws java.io.IOException If an I/O error occurs. + */ + public static void writeFile(CompoundTag tag, File file, boolean compressed, boolean littleEndian) throws IOException { + if(!file.exists()) { + if(file.getParentFile() != null && !file.getParentFile().exists()) { + file.getParentFile().mkdirs(); + } - file.createNewFile(); - } + file.createNewFile(); + } - OutputStream out = new FileOutputStream(file); - if(compressed) { - out = new GZIPOutputStream(out); - } + OutputStream out = new FileOutputStream(file); + if(compressed) { + out = new GZIPOutputStream(out); + } - writeTag(out, tag, littleEndian); - out.close(); - } + writeTag(out, tag, littleEndian); + out.close(); + } /** * Reads a big endian NBT tag. @@ -144,17 +156,17 @@ public class NBTIO { return readTag(in, false); } - /** - * Reads an NBT tag. - * - * @param in Input stream to read from. + /** + * Reads an NBT tag. + * + * @param in Input stream to read from. * @param littleEndian Whether to read little endian NBT. - * @return The read tag, or null if the tag is an end tag. - * @throws java.io.IOException If an I/O error occurs. - */ - public static Tag readTag(InputStream in, boolean littleEndian) throws IOException { - return readTag((DataInput) (littleEndian ? new LittleEndianDataInputStream(in) : new DataInputStream(in))); - } + * @return The read tag, or null if the tag is an end tag. + * @throws java.io.IOException If an I/O error occurs. + */ + public static Tag readTag(InputStream in, boolean littleEndian) throws IOException { + return readTag((DataInput) (littleEndian ? new LittleEndianDataInputStream(in) : new DataInputStream(in))); + } /** * Reads an NBT tag. @@ -201,9 +213,9 @@ public class NBTIO { * @param littleEndian Whether to write little endian NBT. * @throws java.io.IOException If an I/O error occurs. */ - public static void writeTag(OutputStream out, Tag tag, boolean littleEndian) throws IOException { + public static void writeTag(OutputStream out, Tag tag, boolean littleEndian) throws IOException { writeTag((DataOutput) (littleEndian ? new LittleEndianDataOutputStream(out) : new DataOutputStream(out)), tag); - } + } /** * Writes an NBT tag. @@ -218,222 +230,222 @@ public class NBTIO { tag.write(out); } - private static class LittleEndianDataInputStream extends FilterInputStream implements DataInput { - public LittleEndianDataInputStream(InputStream in) { - super(in); - } - - @Override - public int read(byte[] b) throws IOException { - return this.in.read(b, 0, b.length); - - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - return this.in.read(b, off, len); - } - - @Override - public void readFully(byte[] b) throws IOException { - this.readFully(b, 0, b.length); - } - - @Override - public void readFully(byte[] b, int off, int len) throws IOException { - if(len < 0) { - throw new IndexOutOfBoundsException(); - } else { - int read; - for(int pos = 0; pos < len; pos += read) { - read = this.in.read(b, off + pos, len - pos); - if(read < 0) { - throw new EOFException(); - } - } - } - } - - @Override - public int skipBytes(int n) throws IOException { - int total = 0; - int skipped = 0; - while(total < n && (skipped = (int) this.in.skip(n - total)) > 0) { - total += skipped; - } - - return total; - } - - @Override - public boolean readBoolean() throws IOException { - int val = this.in.read(); - if(val < 0) { - throw new EOFException(); - } - - return val != 0; - } - - @Override - public byte readByte() throws IOException { - int val = this.in.read(); - if(val < 0) { - throw new EOFException(); - } - - return (byte) val; - } - - @Override - public int readUnsignedByte() throws IOException { - int val = this.in.read(); - if(val < 0) { - throw new EOFException(); - } - - return val; - } - - @Override - public short readShort() throws IOException { - int b1 = this.in.read(); - int b2 = this.in.read(); - if((b1 | b2) < 0) { - throw new EOFException(); - } - - return (short) (b1 | (b2 << 8)); - } - - @Override - public int readUnsignedShort() throws IOException { - int b1 = this.in.read(); - int b2 = this.in.read(); - if((b1 | b2) < 0) { - throw new EOFException(); - } - - return b1 | (b2 << 8); - } - - @Override - public char readChar() throws IOException { - int b1 = this.in.read(); - int b2 = this.in.read(); - if((b1 | b2) < 0) { - throw new EOFException(); - } - - return (char) (b1 | (b2 << 8)); - } - - @Override - public int readInt() throws IOException { - int b1 = this.in.read(); - int b2 = this.in.read(); - int b3 = this.in.read(); - int b4 = this.in.read(); - if((b1 | b2 | b3 | b4) < 0) { - throw new EOFException(); - } - - return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24); - } - - @Override - public long readLong() throws IOException { - long b1 = this.in.read(); - long b2 = this.in.read(); - long b3 = this.in.read(); - long b4 = this.in.read(); - long b5 = this.in.read(); - long b6 = this.in.read(); - long b7 = this.in.read(); - long b8 = this.in.read(); - if((b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8) < 0) { - throw new EOFException(); - } - - return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24) | (b5 << 32) | (b6 << 40) | (b7 << 48) | (b8 << 56); - } - - @Override - public float readFloat() throws IOException { - return Float.intBitsToFloat(this.readInt()); - } - - @Override - public double readDouble() throws IOException { - return Double.longBitsToDouble(this.readLong()); - } - - @Override - public String readLine() throws IOException { - throw new UnsupportedOperationException("Use readUTF."); - } - - @Override - public String readUTF() throws IOException { - byte[] bytes = new byte[this.readUnsignedShort()]; - this.readFully(bytes); - - return new String(bytes, "UTF-8"); - } - } - - private static class LittleEndianDataOutputStream extends FilterOutputStream implements DataOutput { - public LittleEndianDataOutputStream(OutputStream out) { - super(out); - } - - @Override - public synchronized void write(int b) throws IOException { - this.out.write(b); - } + private static class LittleEndianDataInputStream extends FilterInputStream implements DataInput { + public LittleEndianDataInputStream(InputStream in) { + super(in); + } @Override - public synchronized void write(byte[] b, int off, int len) throws IOException { - this.out.write(b, off, len); - } + public int read(byte[] b) throws IOException { + return this.in.read(b, 0, b.length); + + } @Override - public void flush() throws IOException { - this.out.flush(); - } + public int read(byte[] b, int off, int len) throws IOException { + return this.in.read(b, off, len); + } @Override - public void writeBoolean(boolean b) throws IOException { - this.out.write(b ? 1 : 0); - } + public void readFully(byte[] b) throws IOException { + this.readFully(b, 0, b.length); + } @Override - public void writeByte(int b) throws IOException { - this.out.write(b); - } + public void readFully(byte[] b, int off, int len) throws IOException { + if(len < 0) { + throw new IndexOutOfBoundsException(); + } else { + int read; + for(int pos = 0; pos < len; pos += read) { + read = this.in.read(b, off + pos, len - pos); + if(read < 0) { + throw new EOFException(); + } + } + } + } @Override - public void writeShort(int s) throws IOException { - this.out.write(s & 0xFF); - this.out.write((s >>> 8) & 0xFF); - } + public int skipBytes(int n) throws IOException { + int total = 0; + int skipped = 0; + while(total < n && (skipped = (int) this.in.skip(n - total)) > 0) { + total += skipped; + } + + return total; + } @Override - public void writeChar(int c) throws IOException { - this.out.write(c & 0xFF); - this.out.write((c >>> 8) & 0xFF); - } + public boolean readBoolean() throws IOException { + int val = this.in.read(); + if(val < 0) { + throw new EOFException(); + } + + return val != 0; + } @Override - public void writeInt(int i) throws IOException { - this.out.write(i & 0xFF); - this.out.write((i >>> 8) & 0xFF); - this.out.write((i >>> 16) & 0xFF); - this.out.write((i >>> 24) & 0xFF); - } + public byte readByte() throws IOException { + int val = this.in.read(); + if(val < 0) { + throw new EOFException(); + } + + return (byte) val; + } @Override - public void writeLong(long l) throws IOException { + public int readUnsignedByte() throws IOException { + int val = this.in.read(); + if(val < 0) { + throw new EOFException(); + } + + return val; + } + + @Override + public short readShort() throws IOException { + int b1 = this.in.read(); + int b2 = this.in.read(); + if((b1 | b2) < 0) { + throw new EOFException(); + } + + return (short) (b1 | (b2 << 8)); + } + + @Override + public int readUnsignedShort() throws IOException { + int b1 = this.in.read(); + int b2 = this.in.read(); + if((b1 | b2) < 0) { + throw new EOFException(); + } + + return b1 | (b2 << 8); + } + + @Override + public char readChar() throws IOException { + int b1 = this.in.read(); + int b2 = this.in.read(); + if((b1 | b2) < 0) { + throw new EOFException(); + } + + return (char) (b1 | (b2 << 8)); + } + + @Override + public int readInt() throws IOException { + int b1 = this.in.read(); + int b2 = this.in.read(); + int b3 = this.in.read(); + int b4 = this.in.read(); + if((b1 | b2 | b3 | b4) < 0) { + throw new EOFException(); + } + + return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24); + } + + @Override + public long readLong() throws IOException { + long b1 = this.in.read(); + long b2 = this.in.read(); + long b3 = this.in.read(); + long b4 = this.in.read(); + long b5 = this.in.read(); + long b6 = this.in.read(); + long b7 = this.in.read(); + long b8 = this.in.read(); + if((b1 | b2 | b3 | b4 | b5 | b6 | b7 | b8) < 0) { + throw new EOFException(); + } + + return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24) | (b5 << 32) | (b6 << 40) | (b7 << 48) | (b8 << 56); + } + + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(this.readInt()); + } + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(this.readLong()); + } + + @Override + public String readLine() throws IOException { + throw new UnsupportedOperationException("Use readUTF."); + } + + @Override + public String readUTF() throws IOException { + byte[] bytes = new byte[this.readUnsignedShort()]; + this.readFully(bytes); + + return new String(bytes, "UTF-8"); + } + } + + private static class LittleEndianDataOutputStream extends FilterOutputStream implements DataOutput { + public LittleEndianDataOutputStream(OutputStream out) { + super(out); + } + + @Override + public synchronized void write(int b) throws IOException { + this.out.write(b); + } + + @Override + public synchronized void write(byte[] b, int off, int len) throws IOException { + this.out.write(b, off, len); + } + + @Override + public void flush() throws IOException { + this.out.flush(); + } + + @Override + public void writeBoolean(boolean b) throws IOException { + this.out.write(b ? 1 : 0); + } + + @Override + public void writeByte(int b) throws IOException { + this.out.write(b); + } + + @Override + public void writeShort(int s) throws IOException { + this.out.write(s & 0xFF); + this.out.write((s >>> 8) & 0xFF); + } + + @Override + public void writeChar(int c) throws IOException { + this.out.write(c & 0xFF); + this.out.write((c >>> 8) & 0xFF); + } + + @Override + public void writeInt(int i) throws IOException { + this.out.write(i & 0xFF); + this.out.write((i >>> 8) & 0xFF); + this.out.write((i >>> 16) & 0xFF); + this.out.write((i >>> 24) & 0xFF); + } + + @Override + public void writeLong(long l) throws IOException { this.out.write((int) (l & 0xFF)); this.out.write((int) ((l >>> 8) & 0xFF)); this.out.write((int) ((l >>> 16) & 0xFF)); @@ -442,42 +454,42 @@ public class NBTIO { this.out.write((int) ((l >>> 40) & 0xFF)); this.out.write((int) ((l >>> 48) & 0xFF)); this.out.write((int) ((l >>> 56) & 0xFF)); - } + } @Override - public void writeFloat(float f) throws IOException { - this.writeInt(Float.floatToIntBits(f)); - } + public void writeFloat(float f) throws IOException { + this.writeInt(Float.floatToIntBits(f)); + } @Override - public void writeDouble(double d) throws IOException { - this.writeLong(Double.doubleToLongBits(d)); - } + public void writeDouble(double d) throws IOException { + this.writeLong(Double.doubleToLongBits(d)); + } @Override - public void writeBytes(String s) throws IOException { - int len = s.length(); - for(int index = 0; index < len; index++) { - this.out.write((byte) s.charAt(index)); - } - } + public void writeBytes(String s) throws IOException { + int len = s.length(); + for(int index = 0; index < len; index++) { + this.out.write((byte) s.charAt(index)); + } + } @Override - public void writeChars(String s) throws IOException { - int len = s.length(); - for(int index = 0; index < len; index++) { - char c = s.charAt(index); - this.out.write(c & 0xFF); - this.out.write((c >>> 8) & 0xFF); - } - } + public void writeChars(String s) throws IOException { + int len = s.length(); + for(int index = 0; index < len; index++) { + char c = s.charAt(index); + this.out.write(c & 0xFF); + this.out.write((c >>> 8) & 0xFF); + } + } @Override - public void writeUTF(String s) throws IOException { + public void writeUTF(String s) throws IOException { byte[] bytes = s.getBytes("UTF-8"); this.writeShort(bytes.length); this.write(bytes); - } - } + } + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/ConversionException.java b/src/main/java/com/github/steveice10/opennbt/conversion/ConversionException.java index e01c191..12423d9 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/ConversionException.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/ConversionException.java @@ -4,21 +4,21 @@ package com.github.steveice10.opennbt.conversion; * An exception thrown when an error occurs while converting something. */ public class ConversionException extends RuntimeException { - private static final long serialVersionUID = -2022049594558041160L; + private static final long serialVersionUID = -2022049594558041160L; - public ConversionException() { - super(); - } + public ConversionException() { + super(); + } - public ConversionException(String message) { - super(message); - } + public ConversionException(String message) { + super(message); + } - public ConversionException(Throwable cause) { - super(cause); - } + public ConversionException(Throwable cause) { + super(cause); + } - public ConversionException(String message, Throwable cause) { - super(message, cause); - } + public ConversionException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/ConverterRegisterException.java b/src/main/java/com/github/steveice10/opennbt/conversion/ConverterRegisterException.java index 81bc4d9..a71b675 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/ConverterRegisterException.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/ConverterRegisterException.java @@ -4,21 +4,21 @@ package com.github.steveice10.opennbt.conversion; * An exception thrown when an error occurs while registering a converter. */ public class ConverterRegisterException extends RuntimeException { - private static final long serialVersionUID = -2022049594558041160L; + private static final long serialVersionUID = -2022049594558041160L; - public ConverterRegisterException() { - super(); - } + public ConverterRegisterException() { + super(); + } - public ConverterRegisterException(String message) { - super(message); - } + public ConverterRegisterException(String message) { + super(message); + } - public ConverterRegisterException(Throwable cause) { - super(cause); - } + public ConverterRegisterException(Throwable cause) { + super(cause); + } - public ConverterRegisterException(String message, Throwable cause) { - super(message, cause); - } + public ConverterRegisterException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/ConverterRegistry.java b/src/main/java/com/github/steveice10/opennbt/conversion/ConverterRegistry.java index bd9e3ea..360455d 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/ConverterRegistry.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/ConverterRegistry.java @@ -18,6 +18,7 @@ import com.github.steveice10.opennbt.conversion.builtin.custom.SerializableArray import com.github.steveice10.opennbt.conversion.builtin.custom.SerializableTagConverter; import com.github.steveice10.opennbt.conversion.builtin.custom.ShortArrayTagConverter; import com.github.steveice10.opennbt.conversion.builtin.custom.StringArrayTagConverter; +import com.github.steveice10.opennbt.tag.TagRegisterException; import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag; import com.github.steveice10.opennbt.tag.builtin.ByteTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; @@ -37,145 +38,149 @@ import com.github.steveice10.opennbt.tag.builtin.custom.SerializableArrayTag; import com.github.steveice10.opennbt.tag.builtin.custom.SerializableTag; import com.github.steveice10.opennbt.tag.builtin.custom.ShortArrayTag; import com.github.steveice10.opennbt.tag.builtin.custom.StringArrayTag; -import com.github.steveice10.opennbt.tag.TagRegisterException; import java.io.Serializable; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * A registry mapping tags and value types to converters. */ public class ConverterRegistry { - private static final Map, TagConverter> tagToConverter = new HashMap, TagConverter>(); - private static final Map, TagConverter> typeToConverter = new HashMap, TagConverter>(); + private static final Map, TagConverter> tagToConverter = new HashMap, TagConverter>(); + private static final Map, TagConverter> typeToConverter = new HashMap, TagConverter>(); - static { - register(ByteTag.class, Byte.class, new ByteTagConverter()); - register(ShortTag.class, Short.class, new ShortTagConverter()); - register(IntTag.class, Integer.class, new IntTagConverter()); - register(LongTag.class, Long.class, new LongTagConverter()); - register(FloatTag.class, Float.class, new FloatTagConverter()); - register(DoubleTag.class, Double.class, new DoubleTagConverter()); - register(ByteArrayTag.class, byte[].class, new ByteArrayTagConverter()); - register(StringTag.class, String.class, new StringTagConverter()); - register(ListTag.class, List.class, new ListTagConverter()); - register(CompoundTag.class, Map.class, new CompoundTagConverter()); - register(IntArrayTag.class, int[].class, new IntArrayTagConverter()); + static { + register(ByteTag.class, Byte.class, new ByteTagConverter()); + register(ShortTag.class, Short.class, new ShortTagConverter()); + register(IntTag.class, Integer.class, new IntTagConverter()); + register(LongTag.class, Long.class, new LongTagConverter()); + register(FloatTag.class, Float.class, new FloatTagConverter()); + register(DoubleTag.class, Double.class, new DoubleTagConverter()); + register(ByteArrayTag.class, byte[].class, new ByteArrayTagConverter()); + register(StringTag.class, String.class, new StringTagConverter()); + register(ListTag.class, List.class, new ListTagConverter()); + register(CompoundTag.class, Map.class, new CompoundTagConverter()); + register(IntArrayTag.class, int[].class, new IntArrayTagConverter()); - register(DoubleArrayTag.class, double[].class, new DoubleArrayTagConverter()); - register(FloatArrayTag.class, float[].class, new FloatArrayTagConverter()); - register(LongArrayTag.class, long[].class, new LongArrayTagConverter()); - register(SerializableArrayTag.class, Serializable[].class, new SerializableArrayTagConverter()); - register(SerializableTag.class, Serializable.class, new SerializableTagConverter()); - register(ShortArrayTag.class, short[].class, new ShortArrayTagConverter()); - register(StringArrayTag.class, String[].class, new StringArrayTagConverter()); - } + register(DoubleArrayTag.class, double[].class, new DoubleArrayTagConverter()); + register(FloatArrayTag.class, float[].class, new FloatArrayTagConverter()); + register(LongArrayTag.class, long[].class, new LongArrayTagConverter()); + register(SerializableArrayTag.class, Serializable[].class, new SerializableArrayTagConverter()); + register(SerializableTag.class, Serializable.class, new SerializableTagConverter()); + register(ShortArrayTag.class, short[].class, new ShortArrayTagConverter()); + register(StringArrayTag.class, String[].class, new StringArrayTagConverter()); + } - /** - * Registers a converter. - * - * @param Tag type to convert from. - * @param Value type to convert to. - * @param tag Tag type class to register the converter to. - * @param type Value type class to register the converter to. - * @param converter Converter to register. - * @throws ConverterRegisterException If an error occurs while registering the converter. - */ - public static void register(Class tag, Class type, TagConverter converter) throws ConverterRegisterException { - if(tagToConverter.containsKey(tag)) { - throw new TagRegisterException("Type conversion to tag " + tag.getName() + " is already registered."); - } + /** + * Registers a converter. + * + * @param Tag type to convert from. + * @param Value type to convert to. + * @param tag Tag type class to register the converter to. + * @param type Value type class to register the converter to. + * @param converter Converter to register. + * @throws ConverterRegisterException If an error occurs while registering the converter. + */ + public static void register(Class tag, Class type, TagConverter converter) throws ConverterRegisterException { + if(tagToConverter.containsKey(tag)) { + throw new TagRegisterException("Type conversion to tag " + tag.getName() + " is already registered."); + } - if(typeToConverter.containsKey(type)) { - throw new TagRegisterException("Tag conversion to type " + type.getName() + " is already registered."); - } + if(typeToConverter.containsKey(type)) { + throw new TagRegisterException("Tag conversion to type " + type.getName() + " is already registered."); + } - tagToConverter.put(tag, converter); - typeToConverter.put(type, converter); - } + tagToConverter.put(tag, converter); + typeToConverter.put(type, converter); + } - /** - * Converts the given tag to a value. - * - * @param Tag type to convert from. - * @param Value type to convert to. - * @param tag Tag to convert. - * @return The converted value. - * @throws ConversionException If a suitable converter could not be found. - */ - public static V convertToValue(T tag) throws ConversionException { - if(tag == null || tag.getValue() == null) { - return null; - } + /** + * Converts the given tag to a value. + * + * @param Tag type to convert from. + * @param Value type to convert to. + * @param tag Tag to convert. + * @return The converted value. + * @throws ConversionException If a suitable converter could not be found. + */ + public static V convertToValue(T tag) throws ConversionException { + if(tag == null || tag.getValue() == null) { + return null; + } - if(!tagToConverter.containsKey(tag.getClass())) { - throw new ConversionException("Tag type " + tag.getClass().getName() + " has no converter."); - } + if(!tagToConverter.containsKey(tag.getClass())) { + throw new ConversionException("Tag type " + tag.getClass().getName() + " has no converter."); + } - TagConverter converter = (TagConverter) tagToConverter.get(tag.getClass()); - return (V) converter.convert(tag); - } + TagConverter converter = (TagConverter) tagToConverter.get(tag.getClass()); + return (V) converter.convert(tag); + } - /** - * Converts the given value to a tag. - * - * @param Value type to convert from. - * @param Tag type to convert to. - * @param name Name of the resulting tag. - * @param value Value to convert. - * @return The converted tag. - * @throws ConversionException If a suitable converter could not be found. - */ - public static T convertToTag(String name, V value) throws ConversionException { - if(value == null) { - return null; - } + /** + * Converts the given value to a tag. + * + * @param Value type to convert from. + * @param Tag type to convert to. + * @param name Name of the resulting tag. + * @param value Value to convert. + * @return The converted tag. + * @throws ConversionException If a suitable converter could not be found. + */ + public static T convertToTag(String name, V value) throws ConversionException { + if(value == null) { + return null; + } - TagConverter converter = (TagConverter) typeToConverter.get(value.getClass()); - if(converter == null) { - for(Class clazz : getAllClasses(value.getClass())) { - if(typeToConverter.containsKey(clazz)) { - try { - converter = (TagConverter) typeToConverter.get(clazz); - break; - } catch(ClassCastException e) { - } - } - } - } + TagConverter converter = (TagConverter) typeToConverter.get(value.getClass()); + if(converter == null) { + for(Class clazz : getAllClasses(value.getClass())) { + if(typeToConverter.containsKey(clazz)) { + try { + converter = (TagConverter) typeToConverter.get(clazz); + break; + } catch(ClassCastException e) { + } + } + } + } - if(converter == null) { - throw new ConversionException("Value type " + value.getClass().getName() + " has no converter."); - } + if(converter == null) { + throw new ConversionException("Value type " + value.getClass().getName() + " has no converter."); + } - return converter.convert(name, value); - } + return converter.convert(name, value); + } - private static Set> getAllClasses(Class clazz) { - Set> ret = new LinkedHashSet>(); - Class c = clazz; - while(c != null) { - ret.add(c); - ret.addAll(getAllSuperInterfaces(c)); - c = c.getSuperclass(); - } + private static Set> getAllClasses(Class clazz) { + Set> ret = new LinkedHashSet>(); + Class c = clazz; + while(c != null) { + ret.add(c); + ret.addAll(getAllSuperInterfaces(c)); + c = c.getSuperclass(); + } - // Make sure Serializable is at the end to avoid mix-ups. - if(ret.contains(Serializable.class)) { - ret.remove(Serializable.class); - ret.add(Serializable.class); - } + // Make sure Serializable is at the end to avoid mix-ups. + if(ret.contains(Serializable.class)) { + ret.remove(Serializable.class); + ret.add(Serializable.class); + } - return ret; - } + return ret; + } - private static Set> getAllSuperInterfaces(Class clazz) { - Set> ret = new HashSet>(); - for(Class c : clazz.getInterfaces()) { - ret.add(c); - ret.addAll(getAllSuperInterfaces(c)); - } + private static Set> getAllSuperInterfaces(Class clazz) { + Set> ret = new HashSet>(); + for(Class c : clazz.getInterfaces()) { + ret.add(c); + ret.addAll(getAllSuperInterfaces(c)); + } - return ret; - } + return ret; + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/TagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/TagConverter.java index 1ed1794..4e6b732 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/TagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/TagConverter.java @@ -9,20 +9,20 @@ import com.github.steveice10.opennbt.tag.builtin.Tag; * @param Value type. */ public interface TagConverter { - /** - * Converts a tag to a value. - * - * @param tag Tag to convert. - * @return The converted value. - */ - public V convert(T tag); + /** + * Converts a tag to a value. + * + * @param tag Tag to convert. + * @return The converted value. + */ + public V convert(T tag); - /** - * Converts a value to a tag. - * - * @param name Name of the tag. - * @param value Value to convert. - * @return The converted tag. - */ - public T convert(String name, V value); + /** + * Converts a value to a tag. + * + * @param name Name of the tag. + * @param value Value to convert. + * @return The converted tag. + */ + public T convert(String name, V value); } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ByteArrayTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ByteArrayTagConverter.java index 6385992..c74efa5 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ByteArrayTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ByteArrayTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag; * A converter that converts between ByteArrayTag and byte[]. */ public class ByteArrayTagConverter implements TagConverter { - @Override - public byte[] convert(ByteArrayTag tag) { - return tag.getValue(); - } + @Override + public byte[] convert(ByteArrayTag tag) { + return tag.getValue(); + } - @Override - public ByteArrayTag convert(String name, byte[] value) { - return new ByteArrayTag(name, value); - } + @Override + public ByteArrayTag convert(String name, byte[] value) { + return new ByteArrayTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ByteTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ByteTagConverter.java index d734634..204e4d1 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ByteTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ByteTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.ByteTag; * A converter that converts between ByteTag and byte. */ public class ByteTagConverter implements TagConverter { - @Override - public Byte convert(ByteTag tag) { - return tag.getValue(); - } + @Override + public Byte convert(ByteTag tag) { + return tag.getValue(); + } - @Override - public ByteTag convert(String name, Byte value) { - return new ByteTag(name, value); - } + @Override + public ByteTag convert(String name, Byte value) { + return new ByteTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/CompoundTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/CompoundTagConverter.java index e41627e..b4d9bd4 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/CompoundTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/CompoundTagConverter.java @@ -1,7 +1,7 @@ package com.github.steveice10.opennbt.conversion.builtin; -import com.github.steveice10.opennbt.conversion.TagConverter; import com.github.steveice10.opennbt.conversion.ConverterRegistry; +import com.github.steveice10.opennbt.conversion.TagConverter; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.Tag; @@ -12,26 +12,26 @@ import java.util.Map; * A converter that converts between CompoundTag and Map. */ public class CompoundTagConverter implements TagConverter { - @Override - public Map convert(CompoundTag tag) { - Map ret = new HashMap(); - Map tags = tag.getValue(); - for(String name : tags.keySet()) { - Tag t = tags.get(name); - ret.put(t.getName(), ConverterRegistry.convertToValue(t)); - } + @Override + public Map convert(CompoundTag tag) { + Map ret = new HashMap(); + Map tags = tag.getValue(); + for(String name : tags.keySet()) { + Tag t = tags.get(name); + ret.put(t.getName(), ConverterRegistry.convertToValue(t)); + } - return ret; - } + return ret; + } - @Override - public CompoundTag convert(String name, Map value) { - Map tags = new HashMap(); - for(Object na : value.keySet()) { - String n = (String) na; - tags.put(n, ConverterRegistry.convertToTag(n, value.get(n))); - } + @Override + public CompoundTag convert(String name, Map value) { + Map tags = new HashMap(); + for(Object na : value.keySet()) { + String n = (String) na; + tags.put(n, ConverterRegistry.convertToTag(n, value.get(n))); + } - return new CompoundTag(name, tags); - } + return new CompoundTag(name, tags); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/DoubleTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/DoubleTagConverter.java index 3085f23..fe34af7 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/DoubleTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/DoubleTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.DoubleTag; * A converter that converts between DoubleTag and double. */ public class DoubleTagConverter implements TagConverter { - @Override - public Double convert(DoubleTag tag) { - return tag.getValue(); - } + @Override + public Double convert(DoubleTag tag) { + return tag.getValue(); + } - @Override - public DoubleTag convert(String name, Double value) { - return new DoubleTag(name, value); - } + @Override + public DoubleTag convert(String name, Double value) { + return new DoubleTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/FloatTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/FloatTagConverter.java index c358617..212976b 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/FloatTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/FloatTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.FloatTag; * A converter that converts between FloatTag and float. */ public class FloatTagConverter implements TagConverter { - @Override - public Float convert(FloatTag tag) { - return tag.getValue(); - } + @Override + public Float convert(FloatTag tag) { + return tag.getValue(); + } - @Override - public FloatTag convert(String name, Float value) { - return new FloatTag(name, value); - } + @Override + public FloatTag convert(String name, Float value) { + return new FloatTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/IntArrayTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/IntArrayTagConverter.java index 16cfb1a..06aae58 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/IntArrayTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/IntArrayTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.IntArrayTag; * A converter that converts between IntArrayTag and int[]. */ public class IntArrayTagConverter implements TagConverter { - @Override - public int[] convert(IntArrayTag tag) { - return tag.getValue(); - } + @Override + public int[] convert(IntArrayTag tag) { + return tag.getValue(); + } - @Override - public IntArrayTag convert(String name, int[] value) { - return new IntArrayTag(name, value); - } + @Override + public IntArrayTag convert(String name, int[] value) { + return new IntArrayTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/IntTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/IntTagConverter.java index 2136b30..290d695 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/IntTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/IntTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.IntTag; * A converter that converts between IntTag and int. */ public class IntTagConverter implements TagConverter { - @Override - public Integer convert(IntTag tag) { - return tag.getValue(); - } + @Override + public Integer convert(IntTag tag) { + return tag.getValue(); + } - @Override - public IntTag convert(String name, Integer value) { - return new IntTag(name, value); - } + @Override + public IntTag convert(String name, Integer value) { + return new IntTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ListTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ListTagConverter.java index deb11d4..b634c14 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ListTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ListTagConverter.java @@ -1,7 +1,7 @@ package com.github.steveice10.opennbt.conversion.builtin; -import com.github.steveice10.opennbt.conversion.TagConverter; import com.github.steveice10.opennbt.conversion.ConverterRegistry; +import com.github.steveice10.opennbt.conversion.TagConverter; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.Tag; @@ -12,28 +12,28 @@ import java.util.List; * A converter that converts between CompoundTag and Map. */ public class ListTagConverter implements TagConverter { - @Override - public List convert(ListTag tag) { - List ret = new ArrayList(); - List tags = tag.getValue(); - for(Tag t : tags) { - ret.add(ConverterRegistry.convertToValue(t)); - } + @Override + public List convert(ListTag tag) { + List ret = new ArrayList(); + List tags = tag.getValue(); + for(Tag t : tags) { + ret.add(ConverterRegistry.convertToValue(t)); + } - return ret; - } + return ret; + } - @Override - public ListTag convert(String name, List value) { - if(value.isEmpty()) { - throw new IllegalArgumentException("Cannot convert ListTag with size of 0."); - } + @Override + public ListTag convert(String name, List value) { + if(value.isEmpty()) { + throw new IllegalArgumentException("Cannot convert ListTag with size of 0."); + } - List tags = new ArrayList(); - for(Object o : value) { - tags.add(ConverterRegistry.convertToTag("", o)); - } + List tags = new ArrayList(); + for(Object o : value) { + tags.add(ConverterRegistry.convertToTag("", o)); + } - return new ListTag(name, tags); - } + return new ListTag(name, tags); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/LongTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/LongTagConverter.java index 399658e..0c3ee10 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/LongTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/LongTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.LongTag; * A converter that converts between LongTag and long. */ public class LongTagConverter implements TagConverter { - @Override - public Long convert(LongTag tag) { - return tag.getValue(); - } + @Override + public Long convert(LongTag tag) { + return tag.getValue(); + } - @Override - public LongTag convert(String name, Long value) { - return new LongTag(name, value); - } + @Override + public LongTag convert(String name, Long value) { + return new LongTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ShortTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ShortTagConverter.java index cb9fb51..5f12727 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ShortTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/ShortTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.ShortTag; * A converter that converts between ShortTag and short. */ public class ShortTagConverter implements TagConverter { - @Override - public Short convert(ShortTag tag) { - return tag.getValue(); - } + @Override + public Short convert(ShortTag tag) { + return tag.getValue(); + } - @Override - public ShortTag convert(String name, Short value) { - return new ShortTag(name, value); - } + @Override + public ShortTag convert(String name, Short value) { + return new ShortTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/StringTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/StringTagConverter.java index 95a0047..3429484 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/StringTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/StringTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag; * A converter that converts between StringTag and String. */ public class StringTagConverter implements TagConverter { - @Override - public String convert(StringTag tag) { - return tag.getValue(); - } + @Override + public String convert(StringTag tag) { + return tag.getValue(); + } - @Override - public StringTag convert(String name, String value) { - return new StringTag(name, value); - } + @Override + public StringTag convert(String name, String value) { + return new StringTag(name, value); + } } \ No newline at end of file diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/DoubleArrayTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/DoubleArrayTagConverter.java index 60a6c84..245f251 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/DoubleArrayTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/DoubleArrayTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.custom.DoubleArrayTag; * A converter that converts between DoubleArrayTag and double[]. */ public class DoubleArrayTagConverter implements TagConverter { - @Override - public double[] convert(DoubleArrayTag tag) { - return tag.getValue(); - } + @Override + public double[] convert(DoubleArrayTag tag) { + return tag.getValue(); + } - @Override - public DoubleArrayTag convert(String name, double[] value) { - return new DoubleArrayTag(name, value); - } + @Override + public DoubleArrayTag convert(String name, double[] value) { + return new DoubleArrayTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/FloatArrayTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/FloatArrayTagConverter.java index 5c0d1b7..5a3863b 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/FloatArrayTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/FloatArrayTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.custom.FloatArrayTag; * A converter that converts between FloatArrayTag and float[]. */ public class FloatArrayTagConverter implements TagConverter { - @Override - public float[] convert(FloatArrayTag tag) { - return tag.getValue(); - } + @Override + public float[] convert(FloatArrayTag tag) { + return tag.getValue(); + } - @Override - public FloatArrayTag convert(String name, float[] value) { - return new FloatArrayTag(name, value); - } + @Override + public FloatArrayTag convert(String name, float[] value) { + return new FloatArrayTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/LongArrayTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/LongArrayTagConverter.java index d4fa023..36af8b0 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/LongArrayTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/LongArrayTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.custom.LongArrayTag; * A converter that converts between LongArrayTag and long[]. */ public class LongArrayTagConverter implements TagConverter { - @Override - public long[] convert(LongArrayTag tag) { - return tag.getValue(); - } + @Override + public long[] convert(LongArrayTag tag) { + return tag.getValue(); + } - @Override - public LongArrayTag convert(String name, long[] value) { - return new LongArrayTag(name, value); - } + @Override + public LongArrayTag convert(String name, long[] value) { + return new LongArrayTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/SerializableArrayTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/SerializableArrayTagConverter.java index e400d0b..48d4d5b 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/SerializableArrayTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/SerializableArrayTagConverter.java @@ -9,13 +9,13 @@ import java.io.Serializable; * A converter that converts between SerializableArrayTag and Serializable[]. */ public class SerializableArrayTagConverter implements TagConverter { - @Override - public Serializable[] convert(SerializableArrayTag tag) { - return tag.getValue(); - } + @Override + public Serializable[] convert(SerializableArrayTag tag) { + return tag.getValue(); + } - @Override - public SerializableArrayTag convert(String name, Serializable[] value) { - return new SerializableArrayTag(name, value); - } + @Override + public SerializableArrayTag convert(String name, Serializable[] value) { + return new SerializableArrayTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/SerializableTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/SerializableTagConverter.java index a433e6d..774ac24 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/SerializableTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/SerializableTagConverter.java @@ -9,13 +9,13 @@ import java.io.Serializable; * A converter that converts between SerializableTag and Serializable. */ public class SerializableTagConverter implements TagConverter { - @Override - public Serializable convert(SerializableTag tag) { - return tag.getValue(); - } + @Override + public Serializable convert(SerializableTag tag) { + return tag.getValue(); + } - @Override - public SerializableTag convert(String name, Serializable value) { - return new SerializableTag(name, value); - } + @Override + public SerializableTag convert(String name, Serializable value) { + return new SerializableTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/ShortArrayTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/ShortArrayTagConverter.java index 189ba96..56a3490 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/ShortArrayTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/ShortArrayTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.custom.ShortArrayTag; * A converter that converts between ShortArrayTag and short[]. */ public class ShortArrayTagConverter implements TagConverter { - @Override - public short[] convert(ShortArrayTag tag) { - return tag.getValue(); - } + @Override + public short[] convert(ShortArrayTag tag) { + return tag.getValue(); + } - @Override - public ShortArrayTag convert(String name, short[] value) { - return new ShortArrayTag(name, value); - } + @Override + public ShortArrayTag convert(String name, short[] value) { + return new ShortArrayTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/StringArrayTagConverter.java b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/StringArrayTagConverter.java index 4588410..dc3d697 100644 --- a/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/StringArrayTagConverter.java +++ b/src/main/java/com/github/steveice10/opennbt/conversion/builtin/custom/StringArrayTagConverter.java @@ -7,13 +7,13 @@ import com.github.steveice10.opennbt.tag.builtin.custom.StringArrayTag; * A converter that converts between StringArrayTag and String[]. */ public class StringArrayTagConverter implements TagConverter { - @Override - public String[] convert(StringArrayTag tag) { - return tag.getValue(); - } + @Override + public String[] convert(StringArrayTag tag) { + return tag.getValue(); + } - @Override - public StringArrayTag convert(String name, String[] value) { - return new StringArrayTag(name, value); - } + @Override + public StringArrayTag convert(String name, String[] value) { + return new StringArrayTag(name, value); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/TagCreateException.java b/src/main/java/com/github/steveice10/opennbt/tag/TagCreateException.java index c7857f9..fabf11a 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/TagCreateException.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/TagCreateException.java @@ -4,21 +4,21 @@ package com.github.steveice10.opennbt.tag; * An exception thrown when an error occurs while created a tag instance. */ public class TagCreateException extends Exception { - private static final long serialVersionUID = -2022049594558041160L; + private static final long serialVersionUID = -2022049594558041160L; - public TagCreateException() { - super(); - } + public TagCreateException() { + super(); + } - public TagCreateException(String message) { - super(message); - } + public TagCreateException(String message) { + super(message); + } - public TagCreateException(Throwable cause) { - super(cause); - } + public TagCreateException(Throwable cause) { + super(cause); + } - public TagCreateException(String message, Throwable cause) { - super(message, cause); - } + public TagCreateException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/TagRegisterException.java b/src/main/java/com/github/steveice10/opennbt/tag/TagRegisterException.java index 84f3f63..d44573f 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/TagRegisterException.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/TagRegisterException.java @@ -4,21 +4,21 @@ package com.github.steveice10.opennbt.tag; * An exception thrown when an error occurs while registering a tag. */ public class TagRegisterException extends RuntimeException { - private static final long serialVersionUID = -2022049594558041160L; + private static final long serialVersionUID = -2022049594558041160L; - public TagRegisterException() { - super(); - } + public TagRegisterException() { + super(); + } - public TagRegisterException(String message) { - super(message); - } + public TagRegisterException(String message) { + super(message); + } - public TagRegisterException(Throwable cause) { - super(cause); - } + public TagRegisterException(Throwable cause) { + super(cause); + } - public TagRegisterException(String message, Throwable cause) { - super(message, cause); - } + public TagRegisterException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/TagRegistry.java b/src/main/java/com/github/steveice10/opennbt/tag/TagRegistry.java index 9f7a4f0..2871244 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/TagRegistry.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/TagRegistry.java @@ -28,99 +28,99 @@ import java.util.Map; * A registry containing different tag classes. */ public class TagRegistry { - private static final Map> idToTag = new HashMap>(); - private static final Map, Integer> tagToId = new HashMap, Integer>(); + private static final Map> idToTag = new HashMap>(); + private static final Map, Integer> tagToId = new HashMap, Integer>(); - static { - register(1, ByteTag.class); - register(2, ShortTag.class); - register(3, IntTag.class); - register(4, LongTag.class); - register(5, FloatTag.class); - register(6, DoubleTag.class); - register(7, ByteArrayTag.class); - register(8, StringTag.class); - register(9, ListTag.class); - register(10, CompoundTag.class); - register(11, IntArrayTag.class); + static { + register(1, ByteTag.class); + register(2, ShortTag.class); + register(3, IntTag.class); + register(4, LongTag.class); + register(5, FloatTag.class); + register(6, DoubleTag.class); + register(7, ByteArrayTag.class); + register(8, StringTag.class); + register(9, ListTag.class); + register(10, CompoundTag.class); + register(11, IntArrayTag.class); - register(60, DoubleArrayTag.class); - register(61, FloatArrayTag.class); - register(62, LongArrayTag.class); - register(63, SerializableArrayTag.class); - register(64, SerializableTag.class); - register(65, ShortArrayTag.class); - register(66, StringArrayTag.class); - } + register(60, DoubleArrayTag.class); + register(61, FloatArrayTag.class); + register(62, LongArrayTag.class); + register(63, SerializableArrayTag.class); + register(64, SerializableTag.class); + register(65, ShortArrayTag.class); + register(66, StringArrayTag.class); + } - /** - * Registers a tag class. - * - * @param id ID of the tag. - * @param tag Tag class to register. - * @throws TagRegisterException If an error occurs while registering the tag. - */ - public static void register(int id, Class tag) throws TagRegisterException { - if(idToTag.containsKey(id)) { - throw new TagRegisterException("Tag ID \"" + id + "\" is already in use."); - } + /** + * Registers a tag class. + * + * @param id ID of the tag. + * @param tag Tag class to register. + * @throws TagRegisterException If an error occurs while registering the tag. + */ + public static void register(int id, Class tag) throws TagRegisterException { + if(idToTag.containsKey(id)) { + throw new TagRegisterException("Tag ID \"" + id + "\" is already in use."); + } - if(tagToId.containsKey(tag)) { - throw new TagRegisterException("Tag \"" + tag.getSimpleName() + "\" is already registered."); - } + if(tagToId.containsKey(tag)) { + throw new TagRegisterException("Tag \"" + tag.getSimpleName() + "\" is already registered."); + } - idToTag.put(id, tag); - tagToId.put(tag, id); - } + idToTag.put(id, tag); + tagToId.put(tag, id); + } - /** - * Gets the tag class with the given id. - * - * @param id Id of the tag. - * @return The tag class with the given id, or null if it cannot be found. - */ - public static Class getClassFor(int id) { - if(!idToTag.containsKey(id)) { - return null; - } + /** + * Gets the tag class with the given id. + * + * @param id Id of the tag. + * @return The tag class with the given id, or null if it cannot be found. + */ + public static Class getClassFor(int id) { + if(!idToTag.containsKey(id)) { + return null; + } - return idToTag.get(id); - } + return idToTag.get(id); + } - /** - * Gets the id of the given tag class. - * - * @param clazz The tag class to get the id of. - * @return The id of the given tag class, or -1 if it cannot be found. - */ - public static int getIdFor(Class clazz) { - if(!tagToId.containsKey(clazz)) { - return -1; - } + /** + * Gets the id of the given tag class. + * + * @param clazz The tag class to get the id of. + * @return The id of the given tag class, or -1 if it cannot be found. + */ + public static int getIdFor(Class clazz) { + if(!tagToId.containsKey(clazz)) { + return -1; + } - return tagToId.get(clazz); - } + return tagToId.get(clazz); + } - /** - * Creates an instance of the tag with the given id, using the String constructor. - * - * @param id Id of the tag. - * @param tagName Name to give the tag. - * @return The created tag. - * @throws TagCreateException If an error occurs while creating the tag. - */ - public static Tag createInstance(int id, String tagName) throws TagCreateException { - Class clazz = idToTag.get(id); - if(clazz == null) { - throw new TagCreateException("Could not find tag with ID \"" + id + "\"."); - } + /** + * Creates an instance of the tag with the given id, using the String constructor. + * + * @param id Id of the tag. + * @param tagName Name to give the tag. + * @return The created tag. + * @throws TagCreateException If an error occurs while creating the tag. + */ + public static Tag createInstance(int id, String tagName) throws TagCreateException { + Class clazz = idToTag.get(id); + if(clazz == null) { + throw new TagCreateException("Could not find tag with ID \"" + id + "\"."); + } - try { - Constructor constructor = clazz.getDeclaredConstructor(String.class); - constructor.setAccessible(true); - return constructor.newInstance(tagName); - } catch(Exception e) { - throw new TagCreateException("Failed to create instance of tag \"" + clazz.getSimpleName() + "\".", e); - } - } + try { + Constructor constructor = clazz.getDeclaredConstructor(String.class); + constructor.setAccessible(true); + return constructor.newInstance(tagName); + } catch(Exception e) { + throw new TagCreateException("Failed to create instance of tag \"" + clazz.getSimpleName() + "\".", e); + } + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/ByteArrayTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/ByteArrayTag.java index 166b28a..fe21efd 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/ByteArrayTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/ByteArrayTag.java @@ -8,89 +8,89 @@ import java.io.IOException; * A tag containing a byte array. */ public class ByteArrayTag extends Tag { - private byte[] value; + private byte[] value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public ByteArrayTag(String name) { - this(name, new byte[0]); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public ByteArrayTag(String name) { + this(name, new byte[0]); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public ByteArrayTag(String name, byte[] value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public ByteArrayTag(String name, byte[] value) { + super(name); + this.value = value; + } - @Override - public byte[] getValue() { - return this.value.clone(); - } + @Override + public byte[] getValue() { + return this.value.clone(); + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(byte[] value) { - if(value == null) { - return; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(byte[] value) { + if(value == null) { + return; + } - this.value = value.clone(); - } + this.value = value.clone(); + } - /** - * Gets a value in this tag's array. - * - * @param index Index of the value. - * @return The value at the given index. - */ - public byte getValue(int index) { - return this.value[index]; - } + /** + * Gets a value in this tag's array. + * + * @param index Index of the value. + * @return The value at the given index. + */ + public byte getValue(int index) { + return this.value[index]; + } - /** - * Sets a value in this tag's array. - * - * @param index Index of the value. - * @param value Value to set. - */ - public void setValue(int index, byte value) { - this.value[index] = value; - } + /** + * Sets a value in this tag's array. + * + * @param index Index of the value. + * @param value Value to set. + */ + public void setValue(int index, byte value) { + this.value[index] = value; + } - /** - * Gets the length of this tag's array. - * - * @return This tag's array length. - */ - public int length() { - return this.value.length; - } + /** + * Gets the length of this tag's array. + * + * @return This tag's array length. + */ + public int length() { + return this.value.length; + } - @Override - public void read(DataInput in) throws IOException { - this.value = new byte[in.readInt()]; - in.readFully(this.value); - } + @Override + public void read(DataInput in) throws IOException { + this.value = new byte[in.readInt()]; + in.readFully(this.value); + } - @Override - public void write(DataOutput out) throws IOException { - out.writeInt(this.value.length); - out.write(this.value); - } + @Override + public void write(DataOutput out) throws IOException { + out.writeInt(this.value.length); + out.write(this.value); + } - @Override - public ByteArrayTag clone() { - return new ByteArrayTag(this.getName(), this.getValue()); - } + @Override + public ByteArrayTag clone() { + return new ByteArrayTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/ByteTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/ByteTag.java index 6f0ed54..7e35cde 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/ByteTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/ByteTag.java @@ -8,54 +8,54 @@ import java.io.IOException; * A tag containing a byte. */ public class ByteTag extends Tag { - private byte value; + private byte value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public ByteTag(String name) { - this(name, (byte) 0); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public ByteTag(String name) { + this(name, (byte) 0); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public ByteTag(String name, byte value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public ByteTag(String name, byte value) { + super(name); + this.value = value; + } - @Override - public Byte getValue() { - return this.value; - } + @Override + public Byte getValue() { + return this.value; + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(byte value) { - this.value = value; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(byte value) { + this.value = value; + } - @Override - public void read(DataInput in) throws IOException { - this.value = in.readByte(); - } + @Override + public void read(DataInput in) throws IOException { + this.value = in.readByte(); + } - @Override - public void write(DataOutput out) throws IOException { - out.writeByte(this.value); - } + @Override + public void write(DataOutput out) throws IOException { + out.writeByte(this.value); + } - @Override - public ByteTag clone() { - return new ByteTag(this.getName(), this.getValue()); - } + @Override + public ByteTag clone() { + return new ByteTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/CompoundTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/CompoundTag.java index 8917cec..bb5b516 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/CompoundTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/CompoundTag.java @@ -6,173 +6,179 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.EOFException; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Set; /** * A compound tag containing other tags. */ public class CompoundTag extends Tag implements Iterable { - private Map value; + private Map value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public CompoundTag(String name) { - this(name, new LinkedHashMap()); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public CompoundTag(String name) { + this(name, new LinkedHashMap()); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public CompoundTag(String name, Map value) { - super(name); - this.value = new LinkedHashMap(value); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public CompoundTag(String name, Map value) { + super(name); + this.value = new LinkedHashMap(value); + } - @Override - public Map getValue() { - return new LinkedHashMap(this.value); - } + @Override + public Map getValue() { + return new LinkedHashMap(this.value); + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(Map value) { - this.value = new LinkedHashMap(value); - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(Map value) { + this.value = new LinkedHashMap(value); + } - /** - * Checks whether the compound tag is empty. - * - * @return Whether the compound tag is empty. - */ - public boolean isEmpty() { - return this.value.isEmpty(); - } + /** + * Checks whether the compound tag is empty. + * + * @return Whether the compound tag is empty. + */ + public boolean isEmpty() { + return this.value.isEmpty(); + } - /** - * Checks whether the compound tag contains a tag with the specified name. - * - * @param tagName Name of the tag to check for. - * @return Whether the compound tag contains a tag with the specified name. - */ - public boolean contains(String tagName) { - return this.value.containsKey(tagName); - } + /** + * Checks whether the compound tag contains a tag with the specified name. + * + * @param tagName Name of the tag to check for. + * @return Whether the compound tag contains a tag with the specified name. + */ + public boolean contains(String tagName) { + return this.value.containsKey(tagName); + } - /** - * Gets the tag with the specified name. - * - * @param Type of tag to get. - * @param tagName Name of the tag. - * @return The tag with the specified name. - */ - public T get(String tagName) { - return (T) this.value.get(tagName); - } + /** + * Gets the tag with the specified name. + * + * @param Type of tag to get. + * @param tagName Name of the tag. + * @return The tag with the specified name. + */ + public T get(String tagName) { + return (T) this.value.get(tagName); + } - /** - * Puts the tag into this compound tag. - * - * @param Type of tag to put. - * @param tag Tag to put into this compound tag. - * @return The previous tag associated with its name, or null if there wasn't one. - */ - public T put(T tag) { - return (T) this.value.put(tag.getName(), tag); - } + /** + * Puts the tag into this compound tag. + * + * @param Type of tag to put. + * @param tag Tag to put into this compound tag. + * @return The previous tag associated with its name, or null if there wasn't one. + */ + public T put(T tag) { + return (T) this.value.put(tag.getName(), tag); + } - /** - * Removes a tag from this compound tag. - * - * @param Type of tag to remove. - * @param tagName Name of the tag to remove. - * @return The removed tag. - */ - public T remove(String tagName) { - return (T) this.value.remove(tagName); - } + /** + * Removes a tag from this compound tag. + * + * @param Type of tag to remove. + * @param tagName Name of the tag to remove. + * @return The removed tag. + */ + public T remove(String tagName) { + return (T) this.value.remove(tagName); + } - /** - * Gets a set of keys in this compound tag. - * - * @return The compound tag's key set. - */ - public Set keySet() { - return this.value.keySet(); - } + /** + * Gets a set of keys in this compound tag. + * + * @return The compound tag's key set. + */ + public Set keySet() { + return this.value.keySet(); + } - /** - * Gets a collection of tags in this compound tag. - * - * @return This compound tag's tags. - */ - public Collection values() { - return this.value.values(); - } + /** + * Gets a collection of tags in this compound tag. + * + * @return This compound tag's tags. + */ + public Collection values() { + return this.value.values(); + } - /** - * Gets the number of tags in this compound tag. - * - * @return This compound tag's size. - */ - public int size() { - return this.value.size(); - } + /** + * Gets the number of tags in this compound tag. + * + * @return This compound tag's size. + */ + public int size() { + return this.value.size(); + } - /** - * Clears all tags from this compound tag. - */ - public void clear() { - this.value.clear(); - } + /** + * Clears all tags from this compound tag. + */ + public void clear() { + this.value.clear(); + } - @Override - public Iterator iterator() { - return this.values().iterator(); - } + @Override + public Iterator iterator() { + return this.values().iterator(); + } - @Override - public void read(DataInput in) throws IOException { - List tags = new ArrayList(); - try { - Tag tag; - while((tag = NBTIO.readTag(in)) != null) { - tags.add(tag); - } - } catch(EOFException e) { - throw new IOException("Closing EndTag was not found!"); - } + @Override + public void read(DataInput in) throws IOException { + List tags = new ArrayList(); + try { + Tag tag; + while((tag = NBTIO.readTag(in)) != null) { + tags.add(tag); + } + } catch(EOFException e) { + throw new IOException("Closing EndTag was not found!"); + } - for(Tag tag : tags) { - this.put(tag); - } - } + for(Tag tag : tags) { + this.put(tag); + } + } - @Override - public void write(DataOutput out) throws IOException { - for(Tag tag : this.value.values()) { - NBTIO.writeTag(out, tag); - } + @Override + public void write(DataOutput out) throws IOException { + for(Tag tag : this.value.values()) { + NBTIO.writeTag(out, tag); + } - out.writeByte(0); - } + out.writeByte(0); + } - @Override - public CompoundTag clone() { - Map newMap = new LinkedHashMap(); - for(Entry entry : this.value.entrySet()) { - newMap.put(entry.getKey(), entry.getValue().clone()); - } + @Override + public CompoundTag clone() { + Map newMap = new LinkedHashMap(); + for(Entry entry : this.value.entrySet()) { + newMap.put(entry.getKey(), entry.getValue().clone()); + } - return new CompoundTag(this.getName(), newMap); - } + return new CompoundTag(this.getName(), newMap); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/DoubleTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/DoubleTag.java index 5de4d00..102d62a 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/DoubleTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/DoubleTag.java @@ -8,54 +8,54 @@ import java.io.IOException; * A tag containing a double. */ public class DoubleTag extends Tag { - private double value; + private double value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public DoubleTag(String name) { - this(name, 0); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public DoubleTag(String name) { + this(name, 0); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public DoubleTag(String name, double value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public DoubleTag(String name, double value) { + super(name); + this.value = value; + } - @Override - public Double getValue() { - return this.value; - } + @Override + public Double getValue() { + return this.value; + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(double value) { - this.value = value; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(double value) { + this.value = value; + } - @Override - public void read(DataInput in) throws IOException { - this.value = in.readDouble(); - } + @Override + public void read(DataInput in) throws IOException { + this.value = in.readDouble(); + } - @Override - public void write(DataOutput out) throws IOException { - out.writeDouble(this.value); - } + @Override + public void write(DataOutput out) throws IOException { + out.writeDouble(this.value); + } - @Override - public DoubleTag clone() { - return new DoubleTag(this.getName(), this.getValue()); - } + @Override + public DoubleTag clone() { + return new DoubleTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/FloatTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/FloatTag.java index 40700e9..fae3d3d 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/FloatTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/FloatTag.java @@ -8,54 +8,54 @@ import java.io.IOException; * A tag containing a float. */ public class FloatTag extends Tag { - private float value; + private float value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public FloatTag(String name) { - this(name, 0); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public FloatTag(String name) { + this(name, 0); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public FloatTag(String name, float value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public FloatTag(String name, float value) { + super(name); + this.value = value; + } - @Override - public Float getValue() { - return this.value; - } + @Override + public Float getValue() { + return this.value; + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(float value) { - this.value = value; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(float value) { + this.value = value; + } - @Override - public void read(DataInput in) throws IOException { - this.value = in.readFloat(); - } + @Override + public void read(DataInput in) throws IOException { + this.value = in.readFloat(); + } - @Override - public void write(DataOutput out) throws IOException { - out.writeFloat(this.value); - } + @Override + public void write(DataOutput out) throws IOException { + out.writeFloat(this.value); + } - @Override - public FloatTag clone() { - return new FloatTag(this.getName(), this.getValue()); - } + @Override + public FloatTag clone() { + return new FloatTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/IntArrayTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/IntArrayTag.java index d18aeb6..42f81dc 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/IntArrayTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/IntArrayTag.java @@ -8,93 +8,93 @@ import java.io.IOException; * A tag containing an integer array. */ public class IntArrayTag extends Tag { - private int[] value; + private int[] value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public IntArrayTag(String name) { - this(name, new int[0]); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public IntArrayTag(String name) { + this(name, new int[0]); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public IntArrayTag(String name, int[] value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public IntArrayTag(String name, int[] value) { + super(name); + this.value = value; + } - @Override - public int[] getValue() { - return this.value.clone(); - } + @Override + public int[] getValue() { + return this.value.clone(); + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(int[] value) { - if(value == null) { - return; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(int[] value) { + if(value == null) { + return; + } - this.value = value.clone(); - } + this.value = value.clone(); + } - /** - * Gets a value in this tag's array. - * - * @param index Index of the value. - * @return The value at the given index. - */ - public int getValue(int index) { - return this.value[index]; - } + /** + * Gets a value in this tag's array. + * + * @param index Index of the value. + * @return The value at the given index. + */ + public int getValue(int index) { + return this.value[index]; + } - /** - * Sets a value in this tag's array. - * - * @param index Index of the value. - * @param value Value to set. - */ - public void setValue(int index, int value) { - this.value[index] = value; - } + /** + * Sets a value in this tag's array. + * + * @param index Index of the value. + * @param value Value to set. + */ + public void setValue(int index, int value) { + this.value[index] = value; + } - /** - * Gets the length of this tag's array. - * - * @return This tag's array length. - */ - public int length() { - return this.value.length; - } + /** + * Gets the length of this tag's array. + * + * @return This tag's array length. + */ + public int length() { + return this.value.length; + } - @Override - public void read(DataInput in) throws IOException { - this.value = new int[in.readInt()]; - for(int index = 0; index < this.value.length; index++) { - this.value[index] = in.readInt(); - } - } + @Override + public void read(DataInput in) throws IOException { + this.value = new int[in.readInt()]; + for(int index = 0; index < this.value.length; index++) { + this.value[index] = in.readInt(); + } + } - @Override - public void write(DataOutput out) throws IOException { - out.writeInt(this.value.length); - for(int index = 0; index < this.value.length; index++) { - out.writeInt(this.value[index]); - } - } + @Override + public void write(DataOutput out) throws IOException { + out.writeInt(this.value.length); + for(int index = 0; index < this.value.length; index++) { + out.writeInt(this.value[index]); + } + } - @Override - public IntArrayTag clone() { - return new IntArrayTag(this.getName(), this.getValue()); - } + @Override + public IntArrayTag clone() { + return new IntArrayTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/IntTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/IntTag.java index ad135d2..a623dee 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/IntTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/IntTag.java @@ -8,54 +8,54 @@ import java.io.IOException; * A tag containing an integer. */ public class IntTag extends Tag { - private int value; + private int value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public IntTag(String name) { - this(name, 0); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public IntTag(String name) { + this(name, 0); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public IntTag(String name, int value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public IntTag(String name, int value) { + super(name); + this.value = value; + } - @Override - public Integer getValue() { - return this.value; - } + @Override + public Integer getValue() { + return this.value; + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(int value) { - this.value = value; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(int value) { + this.value = value; + } - @Override - public void read(DataInput in) throws IOException { - this.value = in.readInt(); - } + @Override + public void read(DataInput in) throws IOException { + this.value = in.readInt(); + } - @Override - public void write(DataOutput out) throws IOException { - out.writeInt(this.value); - } + @Override + public void write(DataOutput out) throws IOException { + out.writeInt(this.value); + } - @Override - public IntTag clone() { - return new IntTag(this.getName(), this.getValue()); - } + @Override + public IntTag clone() { + return new IntTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/ListTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/ListTag.java index f5fcf98..012165e 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/ListTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/ListTag.java @@ -14,183 +14,183 @@ import java.util.List; * A tag containing a list of tags. */ public class ListTag extends Tag implements Iterable { - private Class type; - private List value; + private Class type; + private List value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - private ListTag(String name) { - super(name); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + private ListTag(String name) { + super(name); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param type Tag type of the list. - */ - public ListTag(String name, Class type) { - super(name); - this.type = type; - this.value = new ArrayList(); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param type Tag type of the list. + */ + public ListTag(String name, Class type) { + super(name); + this.type = type; + this.value = new ArrayList(); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - * @throws IllegalArgumentException If all tags in the list are not of the same type. - */ - public ListTag(String name, List value) throws IllegalArgumentException { - super(name); - Class type = null; - for(Tag tag : value) { - if(tag == null) { - throw new IllegalArgumentException("List cannot contain null tags."); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + * @throws IllegalArgumentException If all tags in the list are not of the same type. + */ + public ListTag(String name, List value) throws IllegalArgumentException { + super(name); + Class type = null; + for(Tag tag : value) { + if(tag == null) { + throw new IllegalArgumentException("List cannot contain null tags."); + } - if(type == null) { - type = tag.getClass(); - } else if(tag.getClass() != type) { - throw new IllegalArgumentException("All tags must be of the same type."); - } - } + if(type == null) { + type = tag.getClass(); + } else if(tag.getClass() != type) { + throw new IllegalArgumentException("All tags must be of the same type."); + } + } - this.type = type; - this.value = new ArrayList(value); - } + this.type = type; + this.value = new ArrayList(value); + } - @Override - public List getValue() { - return new ArrayList(this.value); - } + @Override + public List getValue() { + return new ArrayList(this.value); + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(List value) { - for(Tag tag : value) { - if(tag.getClass() != this.type) { - throw new IllegalArgumentException("Tag type cannot differ from ListTag type."); - } - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(List value) { + for(Tag tag : value) { + if(tag.getClass() != this.type) { + throw new IllegalArgumentException("Tag type cannot differ from ListTag type."); + } + } - this.value = new ArrayList(value); - } + this.value = new ArrayList(value); + } - /** - * Gets the element type of the ListTag. - * - * @return The ListTag's element type. - */ - public Class getElementType() { - return this.type; - } + /** + * Gets the element type of the ListTag. + * + * @return The ListTag's element type. + */ + public Class getElementType() { + return this.type; + } - /** - * Adds a tag to this list tag. - * - * @param tag Tag to add. - * @return If the list was changed as a result. - */ - public boolean add(Tag tag) { - if(tag.getClass() != this.type) { - throw new IllegalArgumentException("Tag type cannot differ from ListTag type."); - } + /** + * Adds a tag to this list tag. + * + * @param tag Tag to add. + * @return If the list was changed as a result. + */ + public boolean add(Tag tag) { + if(tag.getClass() != this.type) { + throw new IllegalArgumentException("Tag type cannot differ from ListTag type."); + } - return this.value.add(tag); - } + return this.value.add(tag); + } - /** - * Removes a tag from this list tag. - * - * @param tag Tag to remove. - * @return If the list contained the tag. - */ - public boolean remove(Tag tag) { - return this.value.remove(tag); - } + /** + * Removes a tag from this list tag. + * + * @param tag Tag to remove. + * @return If the list contained the tag. + */ + public boolean remove(Tag tag) { + return this.value.remove(tag); + } - /** - * Gets the tag at the given index of this list tag. - * - * @param Type of tag to get - * @param index Index of the tag. - * @return The tag at the given index. - */ - public T get(int index) { - return (T) this.value.get(index); - } + /** + * Gets the tag at the given index of this list tag. + * + * @param Type of tag to get + * @param index Index of the tag. + * @return The tag at the given index. + */ + public T get(int index) { + return (T) this.value.get(index); + } - /** - * Gets the number of tags in this list tag. - * - * @return The size of this list tag. - */ - public int size() { - return this.value.size(); - } + /** + * Gets the number of tags in this list tag. + * + * @return The size of this list tag. + */ + public int size() { + return this.value.size(); + } - @Override - public Iterator iterator() { - return this.value.iterator(); - } + @Override + public Iterator iterator() { + return this.value.iterator(); + } - @Override - public void read(DataInput in) throws IOException { - int id = in.readUnsignedByte(); - this.type = TagRegistry.getClassFor(id); - this.value = new ArrayList(); - if(id != 0 && this.type == null) { - throw new IOException("Unknown tag ID in ListTag: " + id); - } + @Override + public void read(DataInput in) throws IOException { + int id = in.readUnsignedByte(); + this.type = TagRegistry.getClassFor(id); + this.value = new ArrayList(); + if(id != 0 && this.type == null) { + throw new IOException("Unknown tag ID in ListTag: " + id); + } - int count = in.readInt(); - for(int index = 0; index < count; index++) { - Tag tag = null; - try { - tag = TagRegistry.createInstance(id, ""); - } catch(TagCreateException e) { - throw new IOException("Failed to create tag.", e); - } + int count = in.readInt(); + for(int index = 0; index < count; index++) { + Tag tag = null; + try { + tag = TagRegistry.createInstance(id, ""); + } catch(TagCreateException e) { + throw new IOException("Failed to create tag.", e); + } - tag.read(in); - this.add(tag); - } - } + tag.read(in); + this.add(tag); + } + } - @Override - public void write(DataOutput out) throws IOException { - if(this.value.isEmpty()) { - out.writeByte(0); - } else { - int id = TagRegistry.getIdFor(this.type); - if(id == -1) { - throw new IOException("ListTag contains unregistered tag class."); - } + @Override + public void write(DataOutput out) throws IOException { + if(this.value.isEmpty()) { + out.writeByte(0); + } else { + int id = TagRegistry.getIdFor(this.type); + if(id == -1) { + throw new IOException("ListTag contains unregistered tag class."); + } - out.writeByte(id); - } + out.writeByte(id); + } - out.writeInt(this.value.size()); - for(Tag tag : this.value) { - tag.write(out); - } - } + out.writeInt(this.value.size()); + for(Tag tag : this.value) { + tag.write(out); + } + } - @Override - public ListTag clone() { - List newList = new ArrayList(); - for(Tag value : this.value) { - newList.add(value.clone()); - } + @Override + public ListTag clone() { + List newList = new ArrayList(); + for(Tag value : this.value) { + newList.add(value.clone()); + } - return new ListTag(this.getName(), newList); - } + return new ListTag(this.getName(), newList); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/LongTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/LongTag.java index d1d8202..efac166 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/LongTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/LongTag.java @@ -8,54 +8,54 @@ import java.io.IOException; * A tag containing a long. */ public class LongTag extends Tag { - private long value; + private long value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public LongTag(String name) { - this(name, 0); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public LongTag(String name) { + this(name, 0); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public LongTag(String name, long value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public LongTag(String name, long value) { + super(name); + this.value = value; + } - @Override - public Long getValue() { - return this.value; - } + @Override + public Long getValue() { + return this.value; + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(long value) { - this.value = value; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(long value) { + this.value = value; + } - @Override - public void read(DataInput in) throws IOException { - this.value = in.readLong(); - } + @Override + public void read(DataInput in) throws IOException { + this.value = in.readLong(); + } - @Override - public void write(DataOutput out) throws IOException { - out.writeLong(this.value); - } + @Override + public void write(DataOutput out) throws IOException { + out.writeLong(this.value); + } - @Override - public LongTag clone() { - return new LongTag(this.getName(), this.getValue()); - } + @Override + public LongTag clone() { + return new LongTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/ShortTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/ShortTag.java index 00eef87..c767024 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/ShortTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/ShortTag.java @@ -8,54 +8,54 @@ import java.io.IOException; * A tag containing a short. */ public class ShortTag extends Tag { - private short value; + private short value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public ShortTag(String name) { - this(name, (short) 0); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public ShortTag(String name) { + this(name, (short) 0); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public ShortTag(String name, short value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public ShortTag(String name, short value) { + super(name); + this.value = value; + } - @Override - public Short getValue() { - return this.value; - } + @Override + public Short getValue() { + return this.value; + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(short value) { - this.value = value; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(short value) { + this.value = value; + } - @Override - public void read(DataInput in) throws IOException { - this.value = in.readShort(); - } + @Override + public void read(DataInput in) throws IOException { + this.value = in.readShort(); + } - @Override - public void write(DataOutput out) throws IOException { - out.writeShort(this.value); - } + @Override + public void write(DataOutput out) throws IOException { + out.writeShort(this.value); + } - @Override - public ShortTag clone() { - return new ShortTag(this.getName(), this.getValue()); - } + @Override + public ShortTag clone() { + return new ShortTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/StringTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/StringTag.java index dd7ede5..6109482 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/StringTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/StringTag.java @@ -8,54 +8,54 @@ import java.io.IOException; * A tag containing a string. */ public class StringTag extends Tag { - private String value; + private String value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public StringTag(String name) { - this(name, ""); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public StringTag(String name) { + this(name, ""); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public StringTag(String name, String value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public StringTag(String name, String value) { + super(name); + this.value = value; + } - @Override - public String getValue() { - return this.value; - } + @Override + public String getValue() { + return this.value; + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(String value) { - this.value = value; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(String value) { + this.value = value; + } - @Override - public void read(DataInput in) throws IOException { - this.value = in.readUTF(); - } + @Override + public void read(DataInput in) throws IOException { + this.value = in.readUTF(); + } - @Override - public void write(DataOutput out) throws IOException { - out.writeUTF(this.value); - } + @Override + public void write(DataOutput out) throws IOException { + out.writeUTF(this.value); + } - @Override - public StringTag clone() { - return new StringTag(this.getName(), this.getValue()); - } + @Override + public StringTag clone() { + return new StringTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/Tag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/Tag.java index f240705..0e24740 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/Tag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/Tag.java @@ -7,116 +7,116 @@ import java.lang.reflect.Array; /** * Represents an NBT tag. - * + *

* All tags must have a constructor with a single string parameter for reading tags (can be any visibility). * Tags should also have setter methods specific to their value types. */ public abstract class Tag implements Cloneable { - private String name; + private String name; - /** - * Creates a tag with the specified name. - * - * @param name The name. - */ - public Tag(String name) { - this.name = name; - } + /** + * Creates a tag with the specified name. + * + * @param name The name. + */ + public Tag(String name) { + this.name = name; + } - /** - * Gets the name of this tag. - * - * @return The name of this tag. - */ - public final String getName() { - return this.name; - } + /** + * Gets the name of this tag. + * + * @return The name of this tag. + */ + public final String getName() { + return this.name; + } - /** - * Gets the value of this tag. - * - * @return The value of this tag. - */ - public abstract Object getValue(); + /** + * Gets the value of this tag. + * + * @return The value of this tag. + */ + public abstract Object getValue(); - /** - * Reads this tag from an input stream. - * - * @param in Stream to write to. - * @throws java.io.IOException If an I/O error occurs. - */ - public abstract void read(DataInput in) throws IOException; + /** + * Reads this tag from an input stream. + * + * @param in Stream to write to. + * @throws java.io.IOException If an I/O error occurs. + */ + public abstract void read(DataInput in) throws IOException; - /** - * Writes this tag to an output stream. - * - * @param out Stream to write to. - * @throws java.io.IOException If an I/O error occurs. - */ - public abstract void write(DataOutput out) throws IOException; + /** + * Writes this tag to an output stream. + * + * @param out Stream to write to. + * @throws java.io.IOException If an I/O error occurs. + */ + public abstract void write(DataOutput out) throws IOException; - @Override - public abstract Tag clone(); + @Override + public abstract Tag clone(); - @Override - public boolean equals(Object obj) { - if(!(obj instanceof Tag)) { - return false; - } + @Override + public boolean equals(Object obj) { + if(!(obj instanceof Tag)) { + return false; + } - Tag tag = (Tag) obj; - if(!this.getName().equals(tag.getName())) { - return false; - } + Tag tag = (Tag) obj; + if(!this.getName().equals(tag.getName())) { + return false; + } - if(this.getValue() == null) { - return tag.getValue() == null; - } else if(tag.getValue() == null) { - return false; - } + if(this.getValue() == null) { + return tag.getValue() == null; + } else if(tag.getValue() == null) { + return false; + } - if(this.getValue().getClass().isArray() && tag.getValue().getClass().isArray()) { - int length = Array.getLength(this.getValue()); - if(Array.getLength(tag.getValue()) != length) { - return false; - } + if(this.getValue().getClass().isArray() && tag.getValue().getClass().isArray()) { + int length = Array.getLength(this.getValue()); + if(Array.getLength(tag.getValue()) != length) { + return false; + } - for(int index = 0; index < length; index++) { - Object o = Array.get(this.getValue(), index); - Object other = Array.get(tag.getValue(), index); - if(o == null && other != null || o != null && !o.equals(other)) { - return false; - } - } + for(int index = 0; index < length; index++) { + Object o = Array.get(this.getValue(), index); + Object other = Array.get(tag.getValue(), index); + if(o == null && other != null || o != null && !o.equals(other)) { + return false; + } + } - return true; - } + return true; + } - return this.getValue().equals(tag.getValue()); - } + return this.getValue().equals(tag.getValue()); + } - @Override - public String toString() { - String name = this.getName() != null && !this.getName().equals("") ? "(" + this.getName() + ")" : ""; - String value = ""; - if(this.getValue() != null) { - value = this.getValue().toString(); - if(this.getValue().getClass().isArray()) { - StringBuilder build = new StringBuilder(); - build.append("["); - for(int index = 0; index < Array.getLength(this.getValue()); index++) { - if(index > 0) { - build.append(", "); - } + @Override + public String toString() { + String name = this.getName() != null && !this.getName().equals("") ? "(" + this.getName() + ")" : ""; + String value = ""; + if(this.getValue() != null) { + value = this.getValue().toString(); + if(this.getValue().getClass().isArray()) { + StringBuilder build = new StringBuilder(); + build.append("["); + for(int index = 0; index < Array.getLength(this.getValue()); index++) { + if(index > 0) { + build.append(", "); + } - build.append(Array.get(this.getValue(), index)); - } + build.append(Array.get(this.getValue(), index)); + } - build.append("]"); - value = build.toString(); - } - } + build.append("]"); + value = build.toString(); + } + } - return this.getClass().getSimpleName() + name + " { " + value + " }"; - } + return this.getClass().getSimpleName() + name + " { " + value + " }"; + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/DoubleArrayTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/DoubleArrayTag.java index fdb572f..9a5202c 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/DoubleArrayTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/DoubleArrayTag.java @@ -10,93 +10,93 @@ import java.io.IOException; * A tag containing a double array. */ public class DoubleArrayTag extends Tag { - private double[] value; + private double[] value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public DoubleArrayTag(String name) { - this(name, new double[0]); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public DoubleArrayTag(String name) { + this(name, new double[0]); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public DoubleArrayTag(String name, double[] value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public DoubleArrayTag(String name, double[] value) { + super(name); + this.value = value; + } - @Override - public double[] getValue() { - return this.value.clone(); - } + @Override + public double[] getValue() { + return this.value.clone(); + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(double[] value) { - if(value == null) { - return; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(double[] value) { + if(value == null) { + return; + } - this.value = value.clone(); - } + this.value = value.clone(); + } - /** - * Gets a value in this tag's array. - * - * @param index Index of the value. - * @return The value at the given index. - */ - public double getValue(int index) { - return this.value[index]; - } + /** + * Gets a value in this tag's array. + * + * @param index Index of the value. + * @return The value at the given index. + */ + public double getValue(int index) { + return this.value[index]; + } - /** - * Sets a value in this tag's array. - * - * @param index Index of the value. - * @param value Value to set. - */ - public void setValue(int index, double value) { - this.value[index] = value; - } + /** + * Sets a value in this tag's array. + * + * @param index Index of the value. + * @param value Value to set. + */ + public void setValue(int index, double value) { + this.value[index] = value; + } - /** - * Gets the length of this tag's array. - * - * @return This tag's array length. - */ - public int length() { - return this.value.length; - } + /** + * Gets the length of this tag's array. + * + * @return This tag's array length. + */ + public int length() { + return this.value.length; + } - @Override - public void read(DataInput in) throws IOException { - this.value = new double[in.readInt()]; - for(int index = 0; index < this.value.length; index++) { - this.value[index] = in.readDouble(); - } - } + @Override + public void read(DataInput in) throws IOException { + this.value = new double[in.readInt()]; + for(int index = 0; index < this.value.length; index++) { + this.value[index] = in.readDouble(); + } + } - @Override - public void write(DataOutput out) throws IOException { - out.writeInt(this.value.length); - for(int index = 0; index < this.value.length; index++) { - out.writeDouble(this.value[index]); - } - } + @Override + public void write(DataOutput out) throws IOException { + out.writeInt(this.value.length); + for(int index = 0; index < this.value.length; index++) { + out.writeDouble(this.value[index]); + } + } - @Override - public DoubleArrayTag clone() { - return new DoubleArrayTag(this.getName(), this.getValue()); - } + @Override + public DoubleArrayTag clone() { + return new DoubleArrayTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/FloatArrayTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/FloatArrayTag.java index 0a53eee..38a46ac 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/FloatArrayTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/FloatArrayTag.java @@ -10,93 +10,93 @@ import java.io.IOException; * A tag containing a float array. */ public class FloatArrayTag extends Tag { - private float[] value; + private float[] value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public FloatArrayTag(String name) { - this(name, new float[0]); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public FloatArrayTag(String name) { + this(name, new float[0]); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public FloatArrayTag(String name, float[] value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public FloatArrayTag(String name, float[] value) { + super(name); + this.value = value; + } - @Override - public float[] getValue() { - return this.value.clone(); - } + @Override + public float[] getValue() { + return this.value.clone(); + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(float[] value) { - if(value == null) { - return; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(float[] value) { + if(value == null) { + return; + } - this.value = value.clone(); - } + this.value = value.clone(); + } - /** - * Gets a value in this tag's array. - * - * @param index Index of the value. - * @return The value at the given index. - */ - public float getValue(int index) { - return this.value[index]; - } + /** + * Gets a value in this tag's array. + * + * @param index Index of the value. + * @return The value at the given index. + */ + public float getValue(int index) { + return this.value[index]; + } - /** - * Sets a value in this tag's array. - * - * @param index Index of the value. - * @param value Value to set. - */ - public void setValue(int index, float value) { - this.value[index] = value; - } + /** + * Sets a value in this tag's array. + * + * @param index Index of the value. + * @param value Value to set. + */ + public void setValue(int index, float value) { + this.value[index] = value; + } - /** - * Gets the length of this tag's array. - * - * @return This tag's array length. - */ - public int length() { - return this.value.length; - } + /** + * Gets the length of this tag's array. + * + * @return This tag's array length. + */ + public int length() { + return this.value.length; + } - @Override - public void read(DataInput in) throws IOException { - this.value = new float[in.readInt()]; - for(int index = 0; index < this.value.length; index++) { - this.value[index] = in.readFloat(); - } - } + @Override + public void read(DataInput in) throws IOException { + this.value = new float[in.readInt()]; + for(int index = 0; index < this.value.length; index++) { + this.value[index] = in.readFloat(); + } + } - @Override - public void write(DataOutput out) throws IOException { - out.writeInt(this.value.length); - for(int index = 0; index < this.value.length; index++) { - out.writeFloat(this.value[index]); - } - } + @Override + public void write(DataOutput out) throws IOException { + out.writeInt(this.value.length); + for(int index = 0; index < this.value.length; index++) { + out.writeFloat(this.value[index]); + } + } - @Override - public FloatArrayTag clone() { - return new FloatArrayTag(this.getName(), this.getValue()); - } + @Override + public FloatArrayTag clone() { + return new FloatArrayTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/LongArrayTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/LongArrayTag.java index 535de80..ae13000 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/LongArrayTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/LongArrayTag.java @@ -10,93 +10,93 @@ import java.io.IOException; * A tag containing a long array. */ public class LongArrayTag extends Tag { - private long[] value; + private long[] value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public LongArrayTag(String name) { - this(name, new long[0]); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public LongArrayTag(String name) { + this(name, new long[0]); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public LongArrayTag(String name, long[] value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public LongArrayTag(String name, long[] value) { + super(name); + this.value = value; + } - @Override - public long[] getValue() { - return this.value.clone(); - } + @Override + public long[] getValue() { + return this.value.clone(); + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(long[] value) { - if(value == null) { - return; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(long[] value) { + if(value == null) { + return; + } - this.value = value.clone(); - } + this.value = value.clone(); + } - /** - * Gets a value in this tag's array. - * - * @param index Index of the value. - * @return The value at the given index. - */ - public long getValue(int index) { - return this.value[index]; - } + /** + * Gets a value in this tag's array. + * + * @param index Index of the value. + * @return The value at the given index. + */ + public long getValue(int index) { + return this.value[index]; + } - /** - * Sets a value in this tag's array. - * - * @param index Index of the value. - * @param value Value to set. - */ - public void setValue(int index, long value) { - this.value[index] = value; - } + /** + * Sets a value in this tag's array. + * + * @param index Index of the value. + * @param value Value to set. + */ + public void setValue(int index, long value) { + this.value[index] = value; + } - /** - * Gets the length of this tag's array. - * - * @return This tag's array length. - */ - public int length() { - return this.value.length; - } + /** + * Gets the length of this tag's array. + * + * @return This tag's array length. + */ + public int length() { + return this.value.length; + } - @Override - public void read(DataInput in) throws IOException { - this.value = new long[in.readInt()]; - for(int index = 0; index < this.value.length; index++) { - this.value[index] = in.readLong(); - } - } + @Override + public void read(DataInput in) throws IOException { + this.value = new long[in.readInt()]; + for(int index = 0; index < this.value.length; index++) { + this.value[index] = in.readLong(); + } + } - @Override - public void write(DataOutput out) throws IOException { - out.writeInt(this.value.length); - for(int index = 0; index < this.value.length; index++) { - out.writeLong(this.value[index]); - } - } + @Override + public void write(DataOutput out) throws IOException { + out.writeInt(this.value.length); + for(int index = 0; index < this.value.length; index++) { + out.writeLong(this.value[index]); + } + } - @Override - public LongArrayTag clone() { - return new LongArrayTag(this.getName(), this.getValue()); - } + @Override + public LongArrayTag clone() { + return new LongArrayTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/SerializableArrayTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/SerializableArrayTag.java index 7074f31..822271f 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/SerializableArrayTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/SerializableArrayTag.java @@ -2,107 +2,114 @@ package com.github.steveice10.opennbt.tag.builtin.custom; import com.github.steveice10.opennbt.tag.builtin.Tag; -import java.io.*; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.io.Serializable; /** * A tag containing an array of serializable objects. */ public class SerializableArrayTag extends Tag { - private Serializable[] value; + private Serializable[] value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public SerializableArrayTag(String name) { - this(name, new Serializable[0]); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public SerializableArrayTag(String name) { + this(name, new Serializable[0]); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public SerializableArrayTag(String name, Serializable[] value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public SerializableArrayTag(String name, Serializable[] value) { + super(name); + this.value = value; + } - @Override - public Serializable[] getValue() { - return this.value.clone(); - } + @Override + public Serializable[] getValue() { + return this.value.clone(); + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(Serializable[] value) { - if(value == null) { - return; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(Serializable[] value) { + if(value == null) { + return; + } - this.value = value.clone(); - } + this.value = value.clone(); + } - /** - * Gets a value in this tag's array. - * - * @param index Index of the value. - * @return The value at the given index. - */ - public Serializable getValue(int index) { - return this.value[index]; - } + /** + * Gets a value in this tag's array. + * + * @param index Index of the value. + * @return The value at the given index. + */ + public Serializable getValue(int index) { + return this.value[index]; + } - /** - * Sets a value in this tag's array. - * - * @param index Index of the value. - * @param value Value to set. - */ - public void setValue(int index, Serializable value) { - this.value[index] = value; - } + /** + * Sets a value in this tag's array. + * + * @param index Index of the value. + * @param value Value to set. + */ + public void setValue(int index, Serializable value) { + this.value[index] = value; + } - /** - * Gets the length of this tag's array. - * - * @return This tag's array length. - */ - public int length() { - return this.value.length; - } + /** + * Gets the length of this tag's array. + * + * @return This tag's array length. + */ + public int length() { + return this.value.length; + } - @Override - public void read(DataInput in) throws IOException { - this.value = new Serializable[in.readInt()]; - ObjectInputStream str = new ObjectInputStream(new DataInputInputStream(in)); - for(int index = 0; index < this.value.length; index++) { - try { - this.value[index] = (Serializable) str.readObject(); - } catch(ClassNotFoundException e) { - throw new IOException("Class not found while reading SerializableArrayTag!", e); - } - } - } + @Override + public void read(DataInput in) throws IOException { + this.value = new Serializable[in.readInt()]; + ObjectInputStream str = new ObjectInputStream(new DataInputInputStream(in)); + for(int index = 0; index < this.value.length; index++) { + try { + this.value[index] = (Serializable) str.readObject(); + } catch(ClassNotFoundException e) { + throw new IOException("Class not found while reading SerializableArrayTag!", e); + } + } + } - @Override - public void write(DataOutput out) throws IOException { - out.writeInt(this.value.length); - ObjectOutputStream str = new ObjectOutputStream(new DataOutputOutputStream(out)); - for(int index = 0; index < this.value.length; index++) { - str.writeObject(this.value[index]); - } - } + @Override + public void write(DataOutput out) throws IOException { + out.writeInt(this.value.length); + ObjectOutputStream str = new ObjectOutputStream(new DataOutputOutputStream(out)); + for(int index = 0; index < this.value.length; index++) { + str.writeObject(this.value[index]); + } + } - @Override - public SerializableArrayTag clone() { - return new SerializableArrayTag(this.getName(), this.getValue()); - } + @Override + public SerializableArrayTag clone() { + return new SerializableArrayTag(this.getName(), this.getValue()); + } private static class DataInputInputStream extends InputStream { private DataInput in; diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/SerializableTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/SerializableTag.java index 1b3e7c3..f79cf7e 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/SerializableTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/SerializableTag.java @@ -2,151 +2,158 @@ package com.github.steveice10.opennbt.tag.builtin.custom; import com.github.steveice10.opennbt.tag.builtin.Tag; -import java.io.*; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.io.Serializable; /** * A tag containing a serializable object. */ public class SerializableTag extends Tag { - private Serializable value; + private Serializable value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public SerializableTag(String name) { - this(name, 0); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public SerializableTag(String name) { + this(name, 0); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public SerializableTag(String name, Serializable value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public SerializableTag(String name, Serializable value) { + super(name); + this.value = value; + } - @Override - public Serializable getValue() { - return this.value; - } + @Override + public Serializable getValue() { + return this.value; + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(Serializable value) { - this.value = value; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(Serializable value) { + this.value = value; + } - @Override - public void read(DataInput in) throws IOException { - ObjectInputStream str = new ObjectInputStream(new DataInputInputStream(in)); - try { - this.value = (Serializable) str.readObject(); - } catch(ClassNotFoundException e) { - throw new IOException("Class not found while reading SerializableTag!", e); - } - } + @Override + public void read(DataInput in) throws IOException { + ObjectInputStream str = new ObjectInputStream(new DataInputInputStream(in)); + try { + this.value = (Serializable) str.readObject(); + } catch(ClassNotFoundException e) { + throw new IOException("Class not found while reading SerializableTag!", e); + } + } - @Override - public void write(DataOutput out) throws IOException { - ObjectOutputStream str = new ObjectOutputStream(new DataOutputOutputStream(out)); - str.writeObject(this.value); - } + @Override + public void write(DataOutput out) throws IOException { + ObjectOutputStream str = new ObjectOutputStream(new DataOutputOutputStream(out)); + str.writeObject(this.value); + } - @Override - public SerializableTag clone() { - return new SerializableTag(this.getName(), this.getValue()); - } + @Override + public SerializableTag clone() { + return new SerializableTag(this.getName(), this.getValue()); + } - private static class DataInputInputStream extends InputStream { - private DataInput in; + private static class DataInputInputStream extends InputStream { + private DataInput in; - public DataInputInputStream(DataInput in) { - this.in = in; - } + public DataInputInputStream(DataInput in) { + this.in = in; + } - @Override - public int read() throws IOException { - return this.in.readUnsignedByte(); - } + @Override + public int read() throws IOException { + return this.in.readUnsignedByte(); + } - @Override - public int read(byte[] b) throws IOException { - this.in.readFully(b); - return b.length; - } + @Override + public int read(byte[] b) throws IOException { + this.in.readFully(b); + return b.length; + } - @Override - public int read(byte[] b, int off, int len) throws IOException { - this.in.readFully(b, off, len); - return len; - } + @Override + public int read(byte[] b, int off, int len) throws IOException { + this.in.readFully(b, off, len); + return len; + } - @Override - public long skip(long l) throws IOException { - return this.in.skipBytes((int) l); - } + @Override + public long skip(long l) throws IOException { + return this.in.skipBytes((int) l); + } - @Override - public int available() throws IOException { - throw new UnsupportedOperationException(); - } + @Override + public int available() throws IOException { + throw new UnsupportedOperationException(); + } - @Override - public void close() throws IOException { - } + @Override + public void close() throws IOException { + } - @Override - public synchronized void mark(int i) { - throw new UnsupportedOperationException(); - } + @Override + public synchronized void mark(int i) { + throw new UnsupportedOperationException(); + } - @Override - public synchronized void reset() throws IOException { - throw new UnsupportedOperationException(); - } + @Override + public synchronized void reset() throws IOException { + throw new UnsupportedOperationException(); + } - @Override - public boolean markSupported() { - return false; - } - } + @Override + public boolean markSupported() { + return false; + } + } - private static class DataOutputOutputStream extends OutputStream { - private DataOutput out; + private static class DataOutputOutputStream extends OutputStream { + private DataOutput out; - public DataOutputOutputStream(DataOutput out) { - this.out = out; - } + public DataOutputOutputStream(DataOutput out) { + this.out = out; + } - @Override - public void write(int b) throws IOException { - this.out.write(b); - } + @Override + public void write(int b) throws IOException { + this.out.write(b); + } - @Override - public void write(byte[] b) throws IOException { - this.out.write(b); - } + @Override + public void write(byte[] b) throws IOException { + this.out.write(b); + } - @Override - public void write(byte[] b, int off, int len) throws IOException { - this.out.write(b, off, len); - } + @Override + public void write(byte[] b, int off, int len) throws IOException { + this.out.write(b, off, len); + } - @Override - public void flush() throws IOException { - } + @Override + public void flush() throws IOException { + } - @Override - public void close() throws IOException { - } - } + @Override + public void close() throws IOException { + } + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/ShortArrayTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/ShortArrayTag.java index 03dec97..8d53aa4 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/ShortArrayTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/ShortArrayTag.java @@ -10,93 +10,93 @@ import java.io.IOException; * A tag containing a short array. */ public class ShortArrayTag extends Tag { - private short[] value; + private short[] value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public ShortArrayTag(String name) { - this(name, new short[0]); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public ShortArrayTag(String name) { + this(name, new short[0]); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public ShortArrayTag(String name, short[] value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public ShortArrayTag(String name, short[] value) { + super(name); + this.value = value; + } - @Override - public short[] getValue() { - return this.value.clone(); - } + @Override + public short[] getValue() { + return this.value.clone(); + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(short[] value) { - if(value == null) { - return; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(short[] value) { + if(value == null) { + return; + } - this.value = value.clone(); - } + this.value = value.clone(); + } - /** - * Gets a value in this tag's array. - * - * @param index Index of the value. - * @return The value at the given index. - */ - public short getValue(int index) { - return this.value[index]; - } + /** + * Gets a value in this tag's array. + * + * @param index Index of the value. + * @return The value at the given index. + */ + public short getValue(int index) { + return this.value[index]; + } - /** - * Sets a value in this tag's array. - * - * @param index Index of the value. - * @param value Value to set. - */ - public void setValue(int index, short value) { - this.value[index] = value; - } + /** + * Sets a value in this tag's array. + * + * @param index Index of the value. + * @param value Value to set. + */ + public void setValue(int index, short value) { + this.value[index] = value; + } - /** - * Gets the length of this tag's array. - * - * @return This tag's array length. - */ - public int length() { - return this.value.length; - } + /** + * Gets the length of this tag's array. + * + * @return This tag's array length. + */ + public int length() { + return this.value.length; + } - @Override - public void read(DataInput in) throws IOException { - this.value = new short[in.readInt()]; - for(int index = 0; index < this.value.length; index++) { - this.value[index] = in.readShort(); - } - } + @Override + public void read(DataInput in) throws IOException { + this.value = new short[in.readInt()]; + for(int index = 0; index < this.value.length; index++) { + this.value[index] = in.readShort(); + } + } - @Override - public void write(DataOutput out) throws IOException { - out.writeInt(this.value.length); - for(int index = 0; index < this.value.length; index++) { - out.writeShort(this.value[index]); - } - } + @Override + public void write(DataOutput out) throws IOException { + out.writeInt(this.value.length); + for(int index = 0; index < this.value.length; index++) { + out.writeShort(this.value[index]); + } + } - @Override - public ShortArrayTag clone() { - return new ShortArrayTag(this.getName(), this.getValue()); - } + @Override + public ShortArrayTag clone() { + return new ShortArrayTag(this.getName(), this.getValue()); + } } diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/StringArrayTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/StringArrayTag.java index a27b4a8..a83bb39 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/StringArrayTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/StringArrayTag.java @@ -10,93 +10,93 @@ import java.io.IOException; * A tag containing a string array. */ public class StringArrayTag extends Tag { - private String[] value; + private String[] value; - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - */ - public StringArrayTag(String name) { - this(name, new String[0]); - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + */ + public StringArrayTag(String name) { + this(name, new String[0]); + } - /** - * Creates a tag with the specified name. - * - * @param name The name of the tag. - * @param value The value of the tag. - */ - public StringArrayTag(String name, String[] value) { - super(name); - this.value = value; - } + /** + * Creates a tag with the specified name. + * + * @param name The name of the tag. + * @param value The value of the tag. + */ + public StringArrayTag(String name, String[] value) { + super(name); + this.value = value; + } - @Override - public String[] getValue() { - return this.value.clone(); - } + @Override + public String[] getValue() { + return this.value.clone(); + } - /** - * Sets the value of this tag. - * - * @param value New value of this tag. - */ - public void setValue(String[] value) { - if(value == null) { - return; - } + /** + * Sets the value of this tag. + * + * @param value New value of this tag. + */ + public void setValue(String[] value) { + if(value == null) { + return; + } - this.value = value.clone(); - } + this.value = value.clone(); + } - /** - * Gets a value in this tag's array. - * - * @param index Index of the value. - * @return The value at the given index. - */ - public String getValue(int index) { - return this.value[index]; - } + /** + * Gets a value in this tag's array. + * + * @param index Index of the value. + * @return The value at the given index. + */ + public String getValue(int index) { + return this.value[index]; + } - /** - * Sets a value in this tag's array. - * - * @param index Index of the value. - * @param value Value to set. - */ - public void setValue(int index, String value) { - this.value[index] = value; - } + /** + * Sets a value in this tag's array. + * + * @param index Index of the value. + * @param value Value to set. + */ + public void setValue(int index, String value) { + this.value[index] = value; + } - /** - * Gets the length of this tag's array. - * - * @return This tag's array length. - */ - public int length() { - return this.value.length; - } + /** + * Gets the length of this tag's array. + * + * @return This tag's array length. + */ + public int length() { + return this.value.length; + } - @Override - public void read(DataInput in) throws IOException { - this.value = new String[in.readInt()]; - for(int index = 0; index < this.value.length; index++) { - this.value[index] = in.readUTF(); - } - } + @Override + public void read(DataInput in) throws IOException { + this.value = new String[in.readInt()]; + for(int index = 0; index < this.value.length; index++) { + this.value[index] = in.readUTF(); + } + } - @Override - public void write(DataOutput out) throws IOException { - out.writeInt(this.value.length); - for(int index = 0; index < this.value.length; index++) { - out.writeUTF(this.value[index]); - } - } + @Override + public void write(DataOutput out) throws IOException { + out.writeInt(this.value.length); + for(int index = 0; index < this.value.length; index++) { + out.writeUTF(this.value[index]); + } + } - @Override - public StringArrayTag clone() { - return new StringArrayTag(this.getName(), this.getValue()); - } + @Override + public StringArrayTag clone() { + return new StringArrayTag(this.getName(), this.getValue()); + } }