Refactored ch.spacebase to org.spacehq, reformatted code and line endings.

This commit is contained in:
Steveice10 2014-03-01 16:46:32 -08:00
parent d7f2398e00
commit 7f7acc4193
27 changed files with 1404 additions and 1336 deletions

10
.gitignore vendored
View File

@ -1,6 +1,12 @@
bin
.git
lib
.settings
.classpath
.project
.settings
*.iml
.idea
target

View File

@ -13,7 +13,7 @@ OpenNBT is a library for reading and writing NBT files, with some extra custom t
--------------
OpenNBT uses Maven to manage dependencies. Simply run 'mvn clean install' in the source's directory.
You can also download a build <b>[here](http://build.spacebase.ch/job/OpenNBT/)</b>.
You can also download a build <b>[here](http://build.spacehq.org/job/OpenNBT/)</b>.
<b>License</b>

135
pom.xml
View File

@ -1,75 +1,76 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.spacebase</groupId>
<artifactId>opennbt</artifactId>
<version>1.3-SNAPSHOT</version>
<packaging>jar</packaging>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.spacehq</groupId>
<artifactId>opennbt</artifactId>
<version>1.3</version>
<packaging>jar</packaging>
<name>OpenNBT</name>
<description>A library for reading and writing NBT files, written in Java.</description>
<url>http://github.com/Steveice10/OpenNBT/</url>
<name>OpenNBT</name>
<description>A library for reading and writing NBT files, written in Java.</description>
<url>http://github.com/Steveice10/OpenNBT/</url>
<licenses>
<license>
<name>MIT</name>
<url>http://www.opensource.org/licenses/mit-license.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<licenses>
<license>
<name>MIT</name>
<url>http://www.opensource.org/licenses/mit-license.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<connection>scm:git:git@github.com:Steveice10/OpenNBT.git</connection>
<developerConnection>scm:git:git@github.com:Steveice10/OpenNBT.git</developerConnection>
<url>http://github.com/Steveice10/OpenNBT/</url>
</scm>
<scm>
<connection>scm:git:git@github.com:Steveice10/OpenNBT.git</connection>
<developerConnection>scm:git:git@github.com:Steveice10/OpenNBT.git</developerConnection>
<url>http://github.com/Steveice10/OpenNBT/</url>
</scm>
<distributionManagement>
<repository>
<id>spacebase</id>
<name>spacebase-releases</name>
<url>http://repo.spacebase.ch/content/repositories/release/</url>
</repository>
<snapshotRepository>
<id>spacebase</id>
<name>spacebase-snapshots</name>
<url>http://repo.spacebase.ch/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<distributionManagement>
<repository>
<id>spacehq</id>
<name>spacehq-releases</name>
<url>http://repo.spacehq.org/content/repositories/release/</url>
</repository>
<snapshotRepository>
<id>spacehq</id>
<name>spacehq-snapshots</name>
<url>http://repo.spacehq.org/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<developers>
<developer>
<id>steveice10</id>
<name>Steveice10</name>
<email>Steveice10@gmail.com</email>
</developer>
</developers>
<developers>
<developer>
<id>steveice10</id>
<name>Steveice10</name>
<email>Steveice10@gmail.com</email>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<defaultGoal>clean install</defaultGoal>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<!-- Resources -->
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</build>
<build>
<defaultGoal>clean install</defaultGoal>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<!-- Resources -->
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,26 +1,20 @@
package ch.spacebase.opennbt;
package org.spacehq.opennbt;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.spacehq.opennbt.tag.CompoundTag;
import org.spacehq.opennbt.tag.Tag;
import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import ch.spacebase.opennbt.tag.CompoundTag;
import ch.spacebase.opennbt.tag.Tag;
public class NBTFileIO {
/**
* Reads the root CompoundTag from the given file.
*
* @param path Path of the file.
* @return The read compound tag.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public static CompoundTag readFile(String path) throws IOException {
return readFile(new File(path));
@ -28,9 +22,10 @@ public class NBTFileIO {
/**
* Reads the root CompoundTag from the given file.
*
* @param file File to read from.
* @return The read compound tag.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public static CompoundTag readFile(File file) throws IOException {
return readFile(file, true);
@ -38,10 +33,11 @@ public class NBTFileIO {
/**
* Reads the root CompoundTag from the given file.
* @param path Path of the file.
*
* @param path Path of the file.
* @param compressed Whether the NBT file is compressed.
* @return The read compound tag.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public static CompoundTag readFile(String path, boolean compressed) throws IOException {
return readFile(new File(path), compressed);
@ -49,10 +45,11 @@ public class NBTFileIO {
/**
* Reads the root CompoundTag from the given file.
* @param file File to read from.
*
* @param file File to read from.
* @param compressed Whether the NBT file is compressed.
* @return The read compound tag.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public static CompoundTag readFile(File file, boolean compressed) throws IOException {
InputStream in = new FileInputStream(file);
@ -70,9 +67,10 @@ public class NBTFileIO {
/**
* Writes the given root CompoundTag to the given file.
* @param tag Tag to write.
*
* @param tag Tag to write.
* @param path Path to write to.
* @throws IOException If an I/O error occurs.
* @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));
@ -80,9 +78,10 @@ public class NBTFileIO {
/**
* Writes the given root CompoundTag to the given file.
* @param tag Tag to write.
*
* @param tag Tag to write.
* @param file File to write to.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public static void writeFile(CompoundTag tag, File file) throws IOException {
writeFile(tag, file, true);
@ -90,10 +89,11 @@ public class NBTFileIO {
/**
* Writes the given root CompoundTag to the given file.
* @param tag Tag to write.
* @param path Path to write to.
*
* @param tag Tag to write.
* @param path Path to write to.
* @param compressed Whether the NBT file should be compressed.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public static void writeFile(CompoundTag tag, String path, boolean compressed) throws IOException {
writeFile(tag, new File(path), compressed);
@ -101,10 +101,11 @@ public class NBTFileIO {
/**
* Writes the given root CompoundTag to the given file.
* @param tag Tag to write.
* @param file File to write to.
*
* @param tag Tag to write.
* @param file File to write to.
* @param compressed Whether the NBT file should be compressed.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public static void writeFile(CompoundTag tag, File file, boolean compressed) throws IOException {
if(!file.exists()) {

View File

@ -1,4 +1,6 @@
package ch.spacebase.opennbt;
package org.spacehq.opennbt;
import org.spacehq.opennbt.tag.Tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -9,8 +11,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import ch.spacebase.opennbt.tag.Tag;
/**
* A class containing methods for reading/writing NBT tags.
*/
@ -20,9 +20,10 @@ public class NBTIO {
/**
* Reads NBT tags until an end tag is reached.
*
* @param in Input stream to read from.
* @return The read tags.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public static List<Tag> readUntilEndTag(DataInputStream in) throws IOException {
List<Tag> ret = new ArrayList<Tag>();
@ -40,9 +41,10 @@ public class NBTIO {
/**
* Reads an NBT tag.
*
* @param in Input stream to read from.
* @return The read tag, or null if the tag is an end tag.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public static Tag readTag(DataInputStream in) throws IOException {
int id = in.readByte() & 0xFF;
@ -64,9 +66,10 @@ public class NBTIO {
/**
* Writes a collection of tags to an output stream.
* @param out Output stream to write to.
*
* @param out Output stream to write to.
* @param tags Tags to write.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public static void writeTags(DataOutputStream out, Collection<Tag> tags) throws IOException {
for(Tag tag : tags) {
@ -76,9 +79,10 @@ public class NBTIO {
/**
* Writes a tag to an output stream.
*
* @param out Output stream to write to.
* @param tag Tag to write.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public static void writeTag(DataOutputStream out, Tag tag) throws IOException {
byte[] nameBytes = tag.getName().getBytes(CHARSET);

View File

@ -1,4 +1,4 @@
package ch.spacebase.opennbt;
package org.spacehq.opennbt;
/**
* An exception thrown when an error occurs while registering a tag class.

View File

@ -1,74 +1,48 @@
package ch.spacebase.opennbt;
package org.spacehq.opennbt;
import org.spacehq.opennbt.tag.*;
import org.spacehq.opennbt.tag.custom.*;
import java.util.HashMap;
import java.util.Map;
import ch.spacebase.opennbt.tag.ByteArrayTag;
import ch.spacebase.opennbt.tag.ByteTag;
import ch.spacebase.opennbt.tag.CompoundTag;
import ch.spacebase.opennbt.tag.DoubleTag;
import ch.spacebase.opennbt.tag.FloatTag;
import ch.spacebase.opennbt.tag.IntArrayTag;
import ch.spacebase.opennbt.tag.IntTag;
import ch.spacebase.opennbt.tag.ListTag;
import ch.spacebase.opennbt.tag.LongTag;
import ch.spacebase.opennbt.tag.ShortTag;
import ch.spacebase.opennbt.tag.StringTag;
import ch.spacebase.opennbt.tag.Tag;
import ch.spacebase.opennbt.tag.custom.DoubleArrayTag;
import ch.spacebase.opennbt.tag.custom.FloatArrayTag;
import ch.spacebase.opennbt.tag.custom.LongArrayTag;
import ch.spacebase.opennbt.tag.custom.SerializableArrayTag;
import ch.spacebase.opennbt.tag.custom.SerializableTag;
import ch.spacebase.opennbt.tag.custom.ShortArrayTag;
import ch.spacebase.opennbt.tag.custom.StringArrayTag;
/**
* A registry containing different tag classes.
*/
public class TagRegistry {
private static final Map<Integer, Class<? extends Tag>> tags = new HashMap<Integer, Class<? extends Tag>>();
private static boolean registered = false;
static {
try {
registerDefaultTags();
register(CompoundTag.class);
register(ListTag.class);
register(SerializableTag.class);
register(StringTag.class);
register(ByteTag.class);
register(DoubleTag.class);
register(FloatTag.class);
register(IntTag.class);
register(LongTag.class);
register(ShortTag.class);
register(SerializableArrayTag.class);
register(StringArrayTag.class);
register(ByteArrayTag.class);
register(DoubleArrayTag.class);
register(FloatArrayTag.class);
register(IntArrayTag.class);
register(LongArrayTag.class);
register(ShortArrayTag.class);
} catch(TagRegisterException e) {
throw new RuntimeException("Failed to register default tags.", e);
}
}
protected static void registerDefaultTags() throws TagRegisterException {
if(registered) {
return;
}
registered = true;
register(CompoundTag.class);
register(ListTag.class);
register(SerializableTag.class);
register(StringTag.class);
register(ByteTag.class);
register(DoubleTag.class);
register(FloatTag.class);
register(IntTag.class);
register(LongTag.class);
register(ShortTag.class);
register(SerializableArrayTag.class);
register(StringArrayTag.class);
register(ByteArrayTag.class);
register(DoubleArrayTag.class);
register(FloatArrayTag.class);
register(IntArrayTag.class);
register(LongArrayTag.class);
register(ShortArrayTag.class);
}
/**
* Registers a tag class.
*
* @param tag Tag class to register.
* @throws TagRegisterException If an error occurs while registering the tag.
*/
@ -83,6 +57,7 @@ public class TagRegistry {
/**
* Gets the tag class with the given id.
*
* @param id Id of the tag.
* @return The tag class with the given id.
*/
@ -92,6 +67,7 @@ public class TagRegistry {
/**
* Gets the id of the given tag class.
*
* @param clazz The tag class to get the id for.
* @return The id of the given tag class, or -1 if it cannot be found.
*/
@ -107,7 +83,8 @@ public class TagRegistry {
/**
* Creates an instance of the tag with the given id, using the String constructor.
* @param id Id of the tag.
*
* @param id Id of the tag.
* @param tagName Name to give the tag.
* @return The created tag, or null if it could not be created or the type does not exist.
*/

View File

@ -1,4 +1,4 @@
package ch.spacebase.opennbt.tag;
package org.spacehq.opennbt.tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class ByteArrayTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public ByteArrayTag(String name) {
@ -21,7 +22,8 @@ public class ByteArrayTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public ByteArrayTag(String name, byte[] value) {
@ -36,6 +38,7 @@ public class ByteArrayTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(byte[] value) {
@ -48,6 +51,7 @@ public class ByteArrayTag extends Tag {
/**
* Gets a value in this tag's array.
*
* @param index Index of the value.
* @return The value at the given index.
*/
@ -57,6 +61,7 @@ public class ByteArrayTag extends Tag {
/**
* Sets a value in this tag's array.
*
* @param index Index of the value.
* @param value Value to set.
*/
@ -66,6 +71,7 @@ public class ByteArrayTag extends Tag {
/**
* Gets the length of this tag's array.
*
* @return This tag's array length.
*/
public int length() {

View File

@ -1,4 +1,4 @@
package ch.spacebase.opennbt.tag;
package org.spacehq.opennbt.tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class ByteTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public ByteTag(String name) {
@ -21,7 +22,8 @@ public class ByteTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public ByteTag(String name, byte value) {
@ -36,6 +38,7 @@ public class ByteTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(byte value) {

View File

@ -1,17 +1,13 @@
package ch.spacebase.opennbt.tag;
package org.spacehq.opennbt.tag;
import org.spacehq.opennbt.NBTIO;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.Map.Entry;
import ch.spacebase.opennbt.NBTIO;
/**
* A compound tag containing other tags.
*/
@ -21,6 +17,7 @@ public class CompoundTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public CompoundTag(String name) {
@ -29,7 +26,8 @@ public class CompoundTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public CompoundTag(String name, Map<String, Tag> value) {
@ -44,6 +42,7 @@ public class CompoundTag extends Tag {
/**
* Gets the tag with the specified name.
*
* @param tagName Name of the tag.
* @return The tag with the specified name.
*/
@ -53,6 +52,7 @@ public class CompoundTag extends Tag {
/**
* Puts the tag into this compound tag.
*
* @param tag Tag to put into this compound tag.
* @return The previous tag associated with its name, or null if there wasn't one.
*/
@ -62,6 +62,7 @@ public class CompoundTag extends Tag {
/**
* Removes a tag from this compound tag.
*
* @param tagName Name of the tag to remove.
* @return The removed tag.
*/
@ -71,6 +72,7 @@ public class CompoundTag extends Tag {
/**
* Gets a set of keys in this compound tag.
*
* @return The compound tag's key set.
*/
public Set<String> keySet() {
@ -79,6 +81,7 @@ public class CompoundTag extends Tag {
/**
* Gets a collection of tags in this compound tag.
*
* @return This compound tag's tags.
*/
public Collection<Tag> values() {
@ -87,6 +90,7 @@ public class CompoundTag extends Tag {
/**
* Gets the number of tags in this compound tag.
*
* @return This compound tag's size.
*/
public int size() {

View File

@ -1,4 +1,4 @@
package ch.spacebase.opennbt.tag;
package org.spacehq.opennbt.tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class DoubleTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public DoubleTag(String name) {
@ -21,7 +22,8 @@ public class DoubleTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public DoubleTag(String name, double value) {
@ -51,6 +53,7 @@ public class DoubleTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(double value) {

View File

@ -1,4 +1,4 @@
package ch.spacebase.opennbt.tag;
package org.spacehq.opennbt.tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class FloatTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public FloatTag(String name) {
@ -21,7 +22,8 @@ public class FloatTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public FloatTag(String name, float value) {
@ -51,6 +53,7 @@ public class FloatTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(float value) {

View File

@ -1,4 +1,4 @@
package ch.spacebase.opennbt.tag;
package org.spacehq.opennbt.tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class IntArrayTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public IntArrayTag(String name) {
@ -21,7 +22,8 @@ public class IntArrayTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public IntArrayTag(String name, int[] value) {
@ -42,9 +44,9 @@ public class IntArrayTag extends Tag {
@Override
public void read(DataInputStream in) throws IOException {
this.value = new int[in.readInt()];
for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readInt();
}
for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readInt();
}
}
@Override
@ -57,6 +59,7 @@ public class IntArrayTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(int[] value) {
@ -69,6 +72,7 @@ public class IntArrayTag extends Tag {
/**
* Gets a value in this tag's array.
*
* @param index Index of the value.
* @return The value at the given index.
*/
@ -78,6 +82,7 @@ public class IntArrayTag extends Tag {
/**
* Sets a value in this tag's array.
*
* @param index Index of the value.
* @param value Value to set.
*/
@ -87,6 +92,7 @@ public class IntArrayTag extends Tag {
/**
* Gets the length of this tag's array.
*
* @return This tag's array length.
*/
public int length() {

View File

@ -1,4 +1,4 @@
package ch.spacebase.opennbt.tag;
package org.spacehq.opennbt.tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class IntTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public IntTag(String name) {
@ -21,7 +22,8 @@ public class IntTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public IntTag(String name, int value) {
@ -36,6 +38,7 @@ public class IntTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(int value) {

View File

@ -1,4 +1,6 @@
package ch.spacebase.opennbt.tag;
package org.spacehq.opennbt.tag;
import org.spacehq.opennbt.TagRegistry;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -7,8 +9,6 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import ch.spacebase.opennbt.TagRegistry;
/**
* A tag containing a list of tags.
*/
@ -19,6 +19,7 @@ public class ListTag<T extends Tag> extends Tag implements Iterable<T> {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public ListTag(String name) {
@ -28,6 +29,7 @@ public class ListTag<T extends Tag> extends Tag implements Iterable<T> {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
* @param type Tag type of the list.
*/
@ -37,8 +39,9 @@ public class ListTag<T extends Tag> extends Tag implements Iterable<T> {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
* @param type Tag type of the list.
*
* @param name The name of the tag.
* @param type Tag type of the list.
* @param value The value of the tag.
*/
public ListTag(String name, Class<T> type, List<T> value) {
@ -54,6 +57,7 @@ public class ListTag<T extends Tag> extends Tag implements Iterable<T> {
/**
* Adds a tag to this list tag.
*
* @param tag Tag to add.
* @return If the list was changed as a result.
*/
@ -63,6 +67,7 @@ public class ListTag<T extends Tag> extends Tag implements Iterable<T> {
/**
* Removes a tag from this list tag.
*
* @param tag Tag to remove.
* @return If the list contained the tag.
*/
@ -72,6 +77,7 @@ public class ListTag<T extends Tag> extends Tag implements Iterable<T> {
/**
* Gets the tag at the given index of this list tag.
*
* @param index Index of the tag.
* @return The tag at the given index.
*/
@ -81,6 +87,7 @@ public class ListTag<T extends Tag> extends Tag implements Iterable<T> {
/**
* Gets the number of tags in this list tag.
*
* @return The size of this list tag.
*/
public int size() {

View File

@ -1,4 +1,4 @@
package ch.spacebase.opennbt.tag;
package org.spacehq.opennbt.tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class LongTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public LongTag(String name) {
@ -21,7 +22,8 @@ public class LongTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public LongTag(String name, long value) {
@ -36,6 +38,7 @@ public class LongTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(long value) {

View File

@ -1,4 +1,4 @@
package ch.spacebase.opennbt.tag;
package org.spacehq.opennbt.tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class ShortTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public ShortTag(String name) {
@ -21,7 +22,8 @@ public class ShortTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public ShortTag(String name, short value) {
@ -36,6 +38,7 @@ public class ShortTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(short value) {

View File

@ -1,11 +1,11 @@
package ch.spacebase.opennbt.tag;
package org.spacehq.opennbt.tag;
import org.spacehq.opennbt.NBTIO;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import ch.spacebase.opennbt.NBTIO;
/**
* A tag containing a string.
*/
@ -15,6 +15,7 @@ public class StringTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public StringTag(String name) {
@ -23,7 +24,8 @@ public class StringTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public StringTag(String name, String value) {
@ -38,6 +40,7 @@ public class StringTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(String value) {
@ -58,7 +61,7 @@ public class StringTag extends Tag {
@Override
public void write(DataOutputStream out) throws IOException {
byte[] bytes = this.value.getBytes(NBTIO.CHARSET);
byte[] bytes = this.value.getBytes(NBTIO.CHARSET);
out.writeShort(bytes.length);
out.write(bytes);
}

View File

@ -1,4 +1,4 @@
package ch.spacebase.opennbt.tag;
package org.spacehq.opennbt.tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -7,7 +7,7 @@ import java.lang.reflect.Array;
/**
* Represents an NBT tag.
*
* <p/>
* All tags must have a constructor with a single string parameter for reading tags.
* Tags should also have setter methods specific to their value types.
*/
@ -17,6 +17,7 @@ public abstract class Tag implements Cloneable {
/**
* Creates a tag with the specified name.
*
* @param name The name.
*/
public Tag(String name) {
@ -25,6 +26,7 @@ public abstract class Tag implements Cloneable {
/**
* Gets the name of this tag.
*
* @return The name of this tag.
*/
public final String getName() {
@ -33,27 +35,31 @@ public abstract class Tag implements Cloneable {
/**
* Gets the value of this tag.
*
* @return The value of this tag.
*/
public abstract Object getValue();
/**
* Gets the type id of this tag.
*
* @return The tag's id.
*/
public abstract int getId();
/**
* Reads this tag from an input stream.
*
* @param in Stream to write to.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public abstract void read(DataInputStream in) throws IOException;
/**
* Writes this tag to an output stream.
*
* @param out Stream to write to.
* @throws IOException If an I/O error occurs.
* @throws java.io.IOException If an I/O error occurs.
*/
public abstract void write(DataOutputStream out) throws IOException;

View File

@ -1,11 +1,11 @@
package ch.spacebase.opennbt.tag.custom;
package org.spacehq.opennbt.tag.custom;
import org.spacehq.opennbt.tag.Tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import ch.spacebase.opennbt.tag.Tag;
/**
* A tag containing a double array.
*/
@ -15,6 +15,7 @@ public class DoubleArrayTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public DoubleArrayTag(String name) {
@ -23,7 +24,8 @@ public class DoubleArrayTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public DoubleArrayTag(String name, double[] value) {
@ -38,6 +40,7 @@ public class DoubleArrayTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(double[] value) {
@ -50,6 +53,7 @@ public class DoubleArrayTag extends Tag {
/**
* Gets a value in this tag's array.
*
* @param index Index of the value.
* @return The value at the given index.
*/
@ -59,6 +63,7 @@ public class DoubleArrayTag extends Tag {
/**
* Sets a value in this tag's array.
*
* @param index Index of the value.
* @param value Value to set.
*/
@ -68,6 +73,7 @@ public class DoubleArrayTag extends Tag {
/**
* Gets the length of this tag's array.
*
* @return This tag's array length.
*/
public int length() {
@ -82,9 +88,9 @@ public class DoubleArrayTag extends Tag {
@Override
public void read(DataInputStream in) throws IOException {
this.value = new double[in.readInt()];
for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readDouble();
}
for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readDouble();
}
}
@Override

View File

@ -1,11 +1,11 @@
package ch.spacebase.opennbt.tag.custom;
package org.spacehq.opennbt.tag.custom;
import org.spacehq.opennbt.tag.Tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import ch.spacebase.opennbt.tag.Tag;
/**
* A tag containing a float array.
*/
@ -15,6 +15,7 @@ public class FloatArrayTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public FloatArrayTag(String name) {
@ -23,7 +24,8 @@ public class FloatArrayTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public FloatArrayTag(String name, float[] value) {
@ -38,6 +40,7 @@ public class FloatArrayTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(float[] value) {
@ -50,6 +53,7 @@ public class FloatArrayTag extends Tag {
/**
* Gets a value in this tag's array.
*
* @param index Index of the value.
* @return The value at the given index.
*/
@ -59,6 +63,7 @@ public class FloatArrayTag extends Tag {
/**
* Sets a value in this tag's array.
*
* @param index Index of the value.
* @param value Value to set.
*/
@ -68,6 +73,7 @@ public class FloatArrayTag extends Tag {
/**
* Gets the length of this tag's array.
*
* @return This tag's array length.
*/
public int length() {
@ -82,9 +88,9 @@ public class FloatArrayTag extends Tag {
@Override
public void read(DataInputStream in) throws IOException {
this.value = new float[in.readInt()];
for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readFloat();
}
for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readFloat();
}
}
@Override

View File

@ -1,11 +1,11 @@
package ch.spacebase.opennbt.tag.custom;
package org.spacehq.opennbt.tag.custom;
import org.spacehq.opennbt.tag.Tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import ch.spacebase.opennbt.tag.Tag;
/**
* A tag containing a long array.
*/
@ -15,6 +15,7 @@ public class LongArrayTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public LongArrayTag(String name) {
@ -23,7 +24,8 @@ public class LongArrayTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public LongArrayTag(String name, long[] value) {
@ -38,6 +40,7 @@ public class LongArrayTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(long[] value) {
@ -50,6 +53,7 @@ public class LongArrayTag extends Tag {
/**
* Gets a value in this tag's array.
*
* @param index Index of the value.
* @return The value at the given index.
*/
@ -59,6 +63,7 @@ public class LongArrayTag extends Tag {
/**
* Sets a value in this tag's array.
*
* @param index Index of the value.
* @param value Value to set.
*/
@ -68,6 +73,7 @@ public class LongArrayTag extends Tag {
/**
* Gets the length of this tag's array.
*
* @return This tag's array length.
*/
public int length() {
@ -82,9 +88,9 @@ public class LongArrayTag extends Tag {
@Override
public void read(DataInputStream in) throws IOException {
this.value = new long[in.readInt()];
for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readLong();
}
for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readLong();
}
}
@Override

View File

@ -1,13 +1,8 @@
package ch.spacebase.opennbt.tag.custom;
package org.spacehq.opennbt.tag.custom;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.spacehq.opennbt.tag.Tag;
import ch.spacebase.opennbt.tag.Tag;
import java.io.*;
/**
* A tag containing an array of serializable objects.
@ -18,6 +13,7 @@ public class SerializableArrayTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public SerializableArrayTag(String name) {
@ -26,7 +22,8 @@ public class SerializableArrayTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public SerializableArrayTag(String name, Serializable[] value) {
@ -41,6 +38,7 @@ public class SerializableArrayTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(Serializable[] value) {
@ -53,6 +51,7 @@ public class SerializableArrayTag extends Tag {
/**
* Gets a value in this tag's array.
*
* @param index Index of the value.
* @return The value at the given index.
*/
@ -62,6 +61,7 @@ public class SerializableArrayTag extends Tag {
/**
* Sets a value in this tag's array.
*
* @param index Index of the value.
* @param value Value to set.
*/
@ -71,6 +71,7 @@ public class SerializableArrayTag extends Tag {
/**
* Gets the length of this tag's array.
*
* @return This tag's array length.
*/
public int length() {
@ -84,24 +85,24 @@ public class SerializableArrayTag extends Tag {
@Override
public void read(DataInputStream in) throws IOException {
this.value = new Serializable[in.readInt()];
ObjectInputStream str = new ObjectInputStream(in);
for(int index = 0; index < this.value.length; index++) {
try {
this.value = new Serializable[in.readInt()];
ObjectInputStream str = new ObjectInputStream(in);
for(int index = 0; index < this.value.length; index++) {
try {
this.value[index] = (Serializable) str.readObject();
} catch (ClassNotFoundException e) {
} catch(ClassNotFoundException e) {
throw new IOException("Class not found while reading SerializableArrayTag!", e);
}
}
}
}
@Override
public void write(DataOutputStream out) throws IOException {
out.writeInt(this.value.length);
ObjectOutputStream str = new ObjectOutputStream(out);
for(int index = 0; index < this.value.length; index++) {
str.writeObject(this.value[index]);
}
out.writeInt(this.value.length);
ObjectOutputStream str = new ObjectOutputStream(out);
for(int index = 0; index < this.value.length; index++) {
str.writeObject(this.value[index]);
}
}
@Override

View File

@ -1,13 +1,8 @@
package ch.spacebase.opennbt.tag.custom;
package org.spacehq.opennbt.tag.custom;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.spacehq.opennbt.tag.Tag;
import ch.spacebase.opennbt.tag.Tag;
import java.io.*;
/**
* A tag containing a serializable object.
@ -18,6 +13,7 @@ public class SerializableTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public SerializableTag(String name) {
@ -26,7 +22,8 @@ public class SerializableTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public SerializableTag(String name, Serializable value) {
@ -41,6 +38,7 @@ public class SerializableTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(Serializable value) {
@ -54,18 +52,18 @@ public class SerializableTag extends Tag {
@Override
public void read(DataInputStream in) throws IOException {
ObjectInputStream str = new ObjectInputStream(in);
try {
ObjectInputStream str = new ObjectInputStream(in);
try {
this.value = (Serializable) str.readObject();
} catch (ClassNotFoundException e) {
} catch(ClassNotFoundException e) {
throw new IOException("Class not found while reading SerializableTag!", e);
}
}
@Override
public void write(DataOutputStream out) throws IOException {
ObjectOutputStream str = new ObjectOutputStream(out);
str.writeObject(this.value);
ObjectOutputStream str = new ObjectOutputStream(out);
str.writeObject(this.value);
}
@Override

View File

@ -1,11 +1,11 @@
package ch.spacebase.opennbt.tag.custom;
package org.spacehq.opennbt.tag.custom;
import org.spacehq.opennbt.tag.Tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import ch.spacebase.opennbt.tag.Tag;
/**
* A tag containing a short array.
*/
@ -15,6 +15,7 @@ public class ShortArrayTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public ShortArrayTag(String name) {
@ -23,7 +24,8 @@ public class ShortArrayTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public ShortArrayTag(String name, short[] value) {
@ -38,6 +40,7 @@ public class ShortArrayTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(short[] value) {
@ -50,6 +53,7 @@ public class ShortArrayTag extends Tag {
/**
* Gets a value in this tag's array.
*
* @param index Index of the value.
* @return The value at the given index.
*/
@ -59,6 +63,7 @@ public class ShortArrayTag extends Tag {
/**
* Sets a value in this tag's array.
*
* @param index Index of the value.
* @param value Value to set.
*/
@ -68,6 +73,7 @@ public class ShortArrayTag extends Tag {
/**
* Gets the length of this tag's array.
*
* @return This tag's array length.
*/
public int length() {
@ -82,9 +88,9 @@ public class ShortArrayTag extends Tag {
@Override
public void read(DataInputStream in) throws IOException {
this.value = new short[in.readInt()];
for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readShort();
}
for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readShort();
}
}
@Override

View File

@ -1,12 +1,12 @@
package ch.spacebase.opennbt.tag.custom;
package org.spacehq.opennbt.tag.custom;
import org.spacehq.opennbt.NBTIO;
import org.spacehq.opennbt.tag.Tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import ch.spacebase.opennbt.NBTIO;
import ch.spacebase.opennbt.tag.Tag;
/**
* A tag containing a string array.
*/
@ -16,6 +16,7 @@ public class StringArrayTag extends Tag {
/**
* Creates a tag with the specified name.
*
* @param name The name of the tag.
*/
public StringArrayTag(String name) {
@ -24,7 +25,8 @@ public class StringArrayTag extends Tag {
/**
* Creates a tag with the specified name.
* @param name The name of the tag.
*
* @param name The name of the tag.
* @param value The value of the tag.
*/
public StringArrayTag(String name, String[] value) {
@ -39,6 +41,7 @@ public class StringArrayTag extends Tag {
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
*/
public void setValue(String[] value) {
@ -51,6 +54,7 @@ public class StringArrayTag extends Tag {
/**
* Gets a value in this tag's array.
*
* @param index Index of the value.
* @return The value at the given index.
*/
@ -60,6 +64,7 @@ public class StringArrayTag extends Tag {
/**
* Sets a value in this tag's array.
*
* @param index Index of the value.
* @param value Value to set.
*/
@ -69,6 +74,7 @@ public class StringArrayTag extends Tag {
/**
* Gets the length of this tag's array.
*
* @return This tag's array length.
*/
public int length() {
@ -92,12 +98,12 @@ public class StringArrayTag extends Tag {
@Override
public void write(DataOutputStream out) throws IOException {
out.writeInt(this.value.length);
for(int index = 0; index < this.value.length; index++) {
byte[] bytes = this.value[index].getBytes(NBTIO.CHARSET);
out.writeShort(bytes.length);
out.write(bytes);
}
out.writeInt(this.value.length);
for(int index = 0; index < this.value.length; index++) {
byte[] bytes = this.value[index].getBytes(NBTIO.CHARSET);
out.writeShort(bytes.length);
out.write(bytes);
}
}
@Override