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

View File

@ -1,26 +1,20 @@
package ch.spacebase.opennbt; package org.spacehq.opennbt;
import java.io.DataInputStream; import org.spacehq.opennbt.tag.CompoundTag;
import java.io.DataOutputStream; import org.spacehq.opennbt.tag.Tag;
import java.io.File;
import java.io.FileInputStream; import java.io.*;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import ch.spacebase.opennbt.tag.CompoundTag;
import ch.spacebase.opennbt.tag.Tag;
public class NBTFileIO { public class NBTFileIO {
/** /**
* Reads the root CompoundTag from the given file. * Reads the root CompoundTag from the given file.
*
* @param path Path of the file. * @param path Path of the file.
* @return The read compound tag. * @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 { public static CompoundTag readFile(String path) throws IOException {
return readFile(new File(path)); return readFile(new File(path));
@ -28,9 +22,10 @@ public class NBTFileIO {
/** /**
* Reads the root CompoundTag from the given file. * Reads the root CompoundTag from the given file.
*
* @param file File to read from. * @param file File to read from.
* @return The read compound tag. * @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 { public static CompoundTag readFile(File file) throws IOException {
return readFile(file, true); return readFile(file, true);
@ -38,10 +33,11 @@ public class NBTFileIO {
/** /**
* Reads the root CompoundTag from the given file. * 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. * @param compressed Whether the NBT file is compressed.
* @return The read compound tag. * @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 { public static CompoundTag readFile(String path, boolean compressed) throws IOException {
return readFile(new File(path), compressed); return readFile(new File(path), compressed);
@ -49,10 +45,11 @@ public class NBTFileIO {
/** /**
* Reads the root CompoundTag from the given file. * 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. * @param compressed Whether the NBT file is compressed.
* @return The read compound tag. * @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 { public static CompoundTag readFile(File file, boolean compressed) throws IOException {
InputStream in = new FileInputStream(file); InputStream in = new FileInputStream(file);
@ -70,9 +67,10 @@ public class NBTFileIO {
/** /**
* Writes the given root CompoundTag to the given file. * 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. * @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 { public static void writeFile(CompoundTag tag, String path) throws IOException {
writeFile(tag, new File(path)); writeFile(tag, new File(path));
@ -80,9 +78,10 @@ public class NBTFileIO {
/** /**
* Writes the given root CompoundTag to the given file. * 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. * @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 { public static void writeFile(CompoundTag tag, File file) throws IOException {
writeFile(tag, file, true); writeFile(tag, file, true);
@ -90,10 +89,11 @@ public class NBTFileIO {
/** /**
* Writes the given root CompoundTag to the given file. * 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. * @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 { public static void writeFile(CompoundTag tag, String path, boolean compressed) throws IOException {
writeFile(tag, new File(path), compressed); writeFile(tag, new File(path), compressed);
@ -101,10 +101,11 @@ public class NBTFileIO {
/** /**
* Writes the given root CompoundTag to the given file. * 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. * @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 { public static void writeFile(CompoundTag tag, File file, boolean compressed) throws IOException {
if(!file.exists()) { 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -9,8 +11,6 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import ch.spacebase.opennbt.tag.Tag;
/** /**
* A class containing methods for reading/writing NBT tags. * 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. * Reads NBT tags until an end tag is reached.
*
* @param in Input stream to read from. * @param in Input stream to read from.
* @return The read tags. * @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 { public static List<Tag> readUntilEndTag(DataInputStream in) throws IOException {
List<Tag> ret = new ArrayList<Tag>(); List<Tag> ret = new ArrayList<Tag>();
@ -40,9 +41,10 @@ public class NBTIO {
/** /**
* Reads an NBT tag. * Reads an NBT tag.
*
* @param in Input stream to read from. * @param in Input stream to read from.
* @return The read tag, or null if the tag is an end tag. * @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 { public static Tag readTag(DataInputStream in) throws IOException {
int id = in.readByte() & 0xFF; int id = in.readByte() & 0xFF;
@ -64,9 +66,10 @@ public class NBTIO {
/** /**
* Writes a collection of tags to an output stream. * 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. * @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 { public static void writeTags(DataOutputStream out, Collection<Tag> tags) throws IOException {
for(Tag tag : tags) { for(Tag tag : tags) {
@ -76,9 +79,10 @@ public class NBTIO {
/** /**
* Writes a tag to an output stream. * Writes a tag to an output stream.
*
* @param out Output stream to write to. * @param out Output stream to write to.
* @param tag Tag to write. * @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 { public static void writeTag(DataOutputStream out, Tag tag) throws IOException {
byte[] nameBytes = tag.getName().getBytes(CHARSET); 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. * 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.HashMap;
import java.util.Map; 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. * A registry containing different tag classes.
*/ */
public class TagRegistry { public class TagRegistry {
private static final Map<Integer, Class<? extends Tag>> tags = new HashMap<Integer, Class<? extends Tag>>(); private static final Map<Integer, Class<? extends Tag>> tags = new HashMap<Integer, Class<? extends Tag>>();
private static boolean registered = false;
static { static {
try { 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) { } catch(TagRegisterException e) {
throw new RuntimeException("Failed to register default tags.", 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. * Registers a tag class.
*
* @param tag Tag class to register. * @param tag Tag class to register.
* @throws TagRegisterException If an error occurs while registering the tag. * @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. * Gets the tag class with the given id.
*
* @param id Id of the tag. * @param id Id of the tag.
* @return The tag class with the given id. * @return The tag class with the given id.
*/ */
@ -92,6 +67,7 @@ public class TagRegistry {
/** /**
* Gets the id of the given tag class. * Gets the id of the given tag class.
*
* @param clazz The tag class to get the id for. * @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. * @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. * 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. * @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. * @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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class ByteArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public ByteArrayTag(String name) { public ByteArrayTag(String name) {
@ -21,7 +22,8 @@ public class ByteArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public ByteArrayTag(String name, byte[] value) { public ByteArrayTag(String name, byte[] value) {
@ -36,6 +38,7 @@ public class ByteArrayTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(byte[] value) { public void setValue(byte[] value) {
@ -48,6 +51,7 @@ public class ByteArrayTag extends Tag {
/** /**
* Gets a value in this tag's array. * Gets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @return The value at the given index. * @return The value at the given index.
*/ */
@ -57,6 +61,7 @@ public class ByteArrayTag extends Tag {
/** /**
* Sets a value in this tag's array. * Sets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @param value Value to set. * @param value Value to set.
*/ */
@ -66,6 +71,7 @@ public class ByteArrayTag extends Tag {
/** /**
* Gets the length of this tag's array. * Gets the length of this tag's array.
*
* @return This tag's array length. * @return This tag's array length.
*/ */
public int 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class ByteTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public ByteTag(String name) { public ByteTag(String name) {
@ -21,7 +22,8 @@ public class ByteTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public ByteTag(String name, byte value) { public ByteTag(String name, byte value) {
@ -36,6 +38,7 @@ public class ByteTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(byte value) { 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry; import java.util.Map.Entry;
import ch.spacebase.opennbt.NBTIO;
/** /**
* A compound tag containing other tags. * A compound tag containing other tags.
*/ */
@ -21,6 +17,7 @@ public class CompoundTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public CompoundTag(String name) { public CompoundTag(String name) {
@ -29,7 +26,8 @@ public class CompoundTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public CompoundTag(String name, Map<String, Tag> value) { public CompoundTag(String name, Map<String, Tag> value) {
@ -44,6 +42,7 @@ public class CompoundTag extends Tag {
/** /**
* Gets the tag with the specified name. * Gets the tag with the specified name.
*
* @param tagName Name of the tag. * @param tagName Name of the tag.
* @return The tag with the specified name. * @return The tag with the specified name.
*/ */
@ -53,6 +52,7 @@ public class CompoundTag extends Tag {
/** /**
* Puts the tag into this compound tag. * Puts the tag into this compound tag.
*
* @param tag Tag to put 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. * @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. * Removes a tag from this compound tag.
*
* @param tagName Name of the tag to remove. * @param tagName Name of the tag to remove.
* @return The removed tag. * @return The removed tag.
*/ */
@ -71,6 +72,7 @@ public class CompoundTag extends Tag {
/** /**
* Gets a set of keys in this compound tag. * Gets a set of keys in this compound tag.
*
* @return The compound tag's key set. * @return The compound tag's key set.
*/ */
public Set<String> keySet() { public Set<String> keySet() {
@ -79,6 +81,7 @@ public class CompoundTag extends Tag {
/** /**
* Gets a collection of tags in this compound tag. * Gets a collection of tags in this compound tag.
*
* @return This compound tag's tags. * @return This compound tag's tags.
*/ */
public Collection<Tag> values() { public Collection<Tag> values() {
@ -87,6 +90,7 @@ public class CompoundTag extends Tag {
/** /**
* Gets the number of tags in this compound tag. * Gets the number of tags in this compound tag.
*
* @return This compound tag's size. * @return This compound tag's size.
*/ */
public int 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class DoubleTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public DoubleTag(String name) { public DoubleTag(String name) {
@ -21,7 +22,8 @@ public class DoubleTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public DoubleTag(String name, double value) { public DoubleTag(String name, double value) {
@ -51,6 +53,7 @@ public class DoubleTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(double value) { 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class FloatTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public FloatTag(String name) { public FloatTag(String name) {
@ -21,7 +22,8 @@ public class FloatTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public FloatTag(String name, float value) { public FloatTag(String name, float value) {
@ -51,6 +53,7 @@ public class FloatTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(float value) { 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class IntArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public IntArrayTag(String name) { public IntArrayTag(String name) {
@ -21,7 +22,8 @@ public class IntArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public IntArrayTag(String name, int[] value) { public IntArrayTag(String name, int[] value) {
@ -42,9 +44,9 @@ public class IntArrayTag extends Tag {
@Override @Override
public void read(DataInputStream in) throws IOException { public void read(DataInputStream in) throws IOException {
this.value = new int[in.readInt()]; this.value = new int[in.readInt()];
for(int index = 0; index < this.value.length; index++) { for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readInt(); this.value[index] = in.readInt();
} }
} }
@Override @Override
@ -57,6 +59,7 @@ public class IntArrayTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(int[] value) { public void setValue(int[] value) {
@ -69,6 +72,7 @@ public class IntArrayTag extends Tag {
/** /**
* Gets a value in this tag's array. * Gets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @return The value at the given index. * @return The value at the given index.
*/ */
@ -78,6 +82,7 @@ public class IntArrayTag extends Tag {
/** /**
* Sets a value in this tag's array. * Sets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @param value Value to set. * @param value Value to set.
*/ */
@ -87,6 +92,7 @@ public class IntArrayTag extends Tag {
/** /**
* Gets the length of this tag's array. * Gets the length of this tag's array.
*
* @return This tag's array length. * @return This tag's array length.
*/ */
public int 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class IntTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public IntTag(String name) { public IntTag(String name) {
@ -21,7 +22,8 @@ public class IntTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public IntTag(String name, int value) { public IntTag(String name, int value) {
@ -36,6 +38,7 @@ public class IntTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(int value) { 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -7,8 +9,6 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import ch.spacebase.opennbt.TagRegistry;
/** /**
* A tag containing a list of tags. * 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. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public ListTag(String name) { 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. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
* @param type Tag type of the list. * @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. * 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. * @param value The value of the tag.
*/ */
public ListTag(String name, Class<T> type, List<T> value) { 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. * Adds a tag to this list tag.
*
* @param tag Tag to add. * @param tag Tag to add.
* @return If the list was changed as a result. * @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. * Removes a tag from this list tag.
*
* @param tag Tag to remove. * @param tag Tag to remove.
* @return If the list contained the tag. * @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. * Gets the tag at the given index of this list tag.
*
* @param index Index of the tag. * @param index Index of the tag.
* @return The tag at the given index. * @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. * Gets the number of tags in this list tag.
*
* @return The size of this list tag. * @return The size of this list tag.
*/ */
public int 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class LongTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public LongTag(String name) { public LongTag(String name) {
@ -21,7 +22,8 @@ public class LongTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public LongTag(String name, long value) { public LongTag(String name, long value) {
@ -36,6 +38,7 @@ public class LongTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(long value) { 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -13,6 +13,7 @@ public class ShortTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public ShortTag(String name) { public ShortTag(String name) {
@ -21,7 +22,8 @@ public class ShortTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public ShortTag(String name, short value) { public ShortTag(String name, short value) {
@ -36,6 +38,7 @@ public class ShortTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(short value) { 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import ch.spacebase.opennbt.NBTIO;
/** /**
* A tag containing a string. * A tag containing a string.
*/ */
@ -15,6 +15,7 @@ public class StringTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public StringTag(String name) { public StringTag(String name) {
@ -23,7 +24,8 @@ public class StringTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public StringTag(String name, String value) { public StringTag(String name, String value) {
@ -38,6 +40,7 @@ public class StringTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(String value) { public void setValue(String value) {
@ -58,7 +61,7 @@ public class StringTag extends Tag {
@Override @Override
public void write(DataOutputStream out) throws IOException { 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.writeShort(bytes.length);
out.write(bytes); 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -7,7 +7,7 @@ import java.lang.reflect.Array;
/** /**
* Represents an NBT tag. * Represents an NBT tag.
* * <p/>
* All tags must have a constructor with a single string parameter for reading tags. * 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. * 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. * Creates a tag with the specified name.
*
* @param name The name. * @param name The name.
*/ */
public Tag(String name) { public Tag(String name) {
@ -25,6 +26,7 @@ public abstract class Tag implements Cloneable {
/** /**
* Gets the name of this tag. * Gets the name of this tag.
*
* @return The name of this tag. * @return The name of this tag.
*/ */
public final String getName() { public final String getName() {
@ -33,27 +35,31 @@ public abstract class Tag implements Cloneable {
/** /**
* Gets the value of this tag. * Gets the value of this tag.
*
* @return The value of this tag. * @return The value of this tag.
*/ */
public abstract Object getValue(); public abstract Object getValue();
/** /**
* Gets the type id of this tag. * Gets the type id of this tag.
*
* @return The tag's id. * @return The tag's id.
*/ */
public abstract int getId(); public abstract int getId();
/** /**
* Reads this tag from an input stream. * Reads this tag from an input stream.
*
* @param in Stream to write to. * @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; public abstract void read(DataInputStream in) throws IOException;
/** /**
* Writes this tag to an output stream. * Writes this tag to an output stream.
*
* @param out Stream to write to. * @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; 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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import ch.spacebase.opennbt.tag.Tag;
/** /**
* A tag containing a double array. * A tag containing a double array.
*/ */
@ -15,6 +15,7 @@ public class DoubleArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public DoubleArrayTag(String name) { public DoubleArrayTag(String name) {
@ -23,7 +24,8 @@ public class DoubleArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public DoubleArrayTag(String name, double[] value) { public DoubleArrayTag(String name, double[] value) {
@ -38,6 +40,7 @@ public class DoubleArrayTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(double[] value) { public void setValue(double[] value) {
@ -50,6 +53,7 @@ public class DoubleArrayTag extends Tag {
/** /**
* Gets a value in this tag's array. * Gets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @return The value at the given index. * @return The value at the given index.
*/ */
@ -59,6 +63,7 @@ public class DoubleArrayTag extends Tag {
/** /**
* Sets a value in this tag's array. * Sets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @param value Value to set. * @param value Value to set.
*/ */
@ -68,6 +73,7 @@ public class DoubleArrayTag extends Tag {
/** /**
* Gets the length of this tag's array. * Gets the length of this tag's array.
*
* @return This tag's array length. * @return This tag's array length.
*/ */
public int length() { public int length() {
@ -82,9 +88,9 @@ public class DoubleArrayTag extends Tag {
@Override @Override
public void read(DataInputStream in) throws IOException { public void read(DataInputStream in) throws IOException {
this.value = new double[in.readInt()]; this.value = new double[in.readInt()];
for(int index = 0; index < this.value.length; index++) { for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readDouble(); this.value[index] = in.readDouble();
} }
} }
@Override @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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import ch.spacebase.opennbt.tag.Tag;
/** /**
* A tag containing a float array. * A tag containing a float array.
*/ */
@ -15,6 +15,7 @@ public class FloatArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public FloatArrayTag(String name) { public FloatArrayTag(String name) {
@ -23,7 +24,8 @@ public class FloatArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public FloatArrayTag(String name, float[] value) { public FloatArrayTag(String name, float[] value) {
@ -38,6 +40,7 @@ public class FloatArrayTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(float[] value) { public void setValue(float[] value) {
@ -50,6 +53,7 @@ public class FloatArrayTag extends Tag {
/** /**
* Gets a value in this tag's array. * Gets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @return The value at the given index. * @return The value at the given index.
*/ */
@ -59,6 +63,7 @@ public class FloatArrayTag extends Tag {
/** /**
* Sets a value in this tag's array. * Sets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @param value Value to set. * @param value Value to set.
*/ */
@ -68,6 +73,7 @@ public class FloatArrayTag extends Tag {
/** /**
* Gets the length of this tag's array. * Gets the length of this tag's array.
*
* @return This tag's array length. * @return This tag's array length.
*/ */
public int length() { public int length() {
@ -82,9 +88,9 @@ public class FloatArrayTag extends Tag {
@Override @Override
public void read(DataInputStream in) throws IOException { public void read(DataInputStream in) throws IOException {
this.value = new float[in.readInt()]; this.value = new float[in.readInt()];
for(int index = 0; index < this.value.length; index++) { for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readFloat(); this.value[index] = in.readFloat();
} }
} }
@Override @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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import ch.spacebase.opennbt.tag.Tag;
/** /**
* A tag containing a long array. * A tag containing a long array.
*/ */
@ -15,6 +15,7 @@ public class LongArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public LongArrayTag(String name) { public LongArrayTag(String name) {
@ -23,7 +24,8 @@ public class LongArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public LongArrayTag(String name, long[] value) { public LongArrayTag(String name, long[] value) {
@ -38,6 +40,7 @@ public class LongArrayTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(long[] value) { public void setValue(long[] value) {
@ -50,6 +53,7 @@ public class LongArrayTag extends Tag {
/** /**
* Gets a value in this tag's array. * Gets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @return The value at the given index. * @return The value at the given index.
*/ */
@ -59,6 +63,7 @@ public class LongArrayTag extends Tag {
/** /**
* Sets a value in this tag's array. * Sets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @param value Value to set. * @param value Value to set.
*/ */
@ -68,6 +73,7 @@ public class LongArrayTag extends Tag {
/** /**
* Gets the length of this tag's array. * Gets the length of this tag's array.
*
* @return This tag's array length. * @return This tag's array length.
*/ */
public int length() { public int length() {
@ -82,9 +88,9 @@ public class LongArrayTag extends Tag {
@Override @Override
public void read(DataInputStream in) throws IOException { public void read(DataInputStream in) throws IOException {
this.value = new long[in.readInt()]; this.value = new long[in.readInt()];
for(int index = 0; index < this.value.length; index++) { for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readLong(); this.value[index] = in.readLong();
} }
} }
@Override @Override

View File

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

View File

@ -1,13 +1,8 @@
package ch.spacebase.opennbt.tag.custom; package org.spacehq.opennbt.tag.custom;
import java.io.DataInputStream; import org.spacehq.opennbt.tag.Tag;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import ch.spacebase.opennbt.tag.Tag; import java.io.*;
/** /**
* A tag containing a serializable object. * A tag containing a serializable object.
@ -18,6 +13,7 @@ public class SerializableTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public SerializableTag(String name) { public SerializableTag(String name) {
@ -26,7 +22,8 @@ public class SerializableTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public SerializableTag(String name, Serializable value) { public SerializableTag(String name, Serializable value) {
@ -41,6 +38,7 @@ public class SerializableTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(Serializable value) { public void setValue(Serializable value) {
@ -54,18 +52,18 @@ public class SerializableTag extends Tag {
@Override @Override
public void read(DataInputStream in) throws IOException { public void read(DataInputStream in) throws IOException {
ObjectInputStream str = new ObjectInputStream(in); ObjectInputStream str = new ObjectInputStream(in);
try { try {
this.value = (Serializable) str.readObject(); this.value = (Serializable) str.readObject();
} catch (ClassNotFoundException e) { } catch(ClassNotFoundException e) {
throw new IOException("Class not found while reading SerializableTag!", e); throw new IOException("Class not found while reading SerializableTag!", e);
} }
} }
@Override @Override
public void write(DataOutputStream out) throws IOException { public void write(DataOutputStream out) throws IOException {
ObjectOutputStream str = new ObjectOutputStream(out); ObjectOutputStream str = new ObjectOutputStream(out);
str.writeObject(this.value); str.writeObject(this.value);
} }
@Override @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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import ch.spacebase.opennbt.tag.Tag;
/** /**
* A tag containing a short array. * A tag containing a short array.
*/ */
@ -15,6 +15,7 @@ public class ShortArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public ShortArrayTag(String name) { public ShortArrayTag(String name) {
@ -23,7 +24,8 @@ public class ShortArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public ShortArrayTag(String name, short[] value) { public ShortArrayTag(String name, short[] value) {
@ -38,6 +40,7 @@ public class ShortArrayTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(short[] value) { public void setValue(short[] value) {
@ -50,6 +53,7 @@ public class ShortArrayTag extends Tag {
/** /**
* Gets a value in this tag's array. * Gets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @return The value at the given index. * @return The value at the given index.
*/ */
@ -59,6 +63,7 @@ public class ShortArrayTag extends Tag {
/** /**
* Sets a value in this tag's array. * Sets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @param value Value to set. * @param value Value to set.
*/ */
@ -68,6 +73,7 @@ public class ShortArrayTag extends Tag {
/** /**
* Gets the length of this tag's array. * Gets the length of this tag's array.
*
* @return This tag's array length. * @return This tag's array length.
*/ */
public int length() { public int length() {
@ -82,9 +88,9 @@ public class ShortArrayTag extends Tag {
@Override @Override
public void read(DataInputStream in) throws IOException { public void read(DataInputStream in) throws IOException {
this.value = new short[in.readInt()]; this.value = new short[in.readInt()];
for(int index = 0; index < this.value.length; index++) { for(int index = 0; index < this.value.length; index++) {
this.value[index] = in.readShort(); this.value[index] = in.readShort();
} }
} }
@Override @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.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import ch.spacebase.opennbt.NBTIO;
import ch.spacebase.opennbt.tag.Tag;
/** /**
* A tag containing a string array. * A tag containing a string array.
*/ */
@ -16,6 +16,7 @@ public class StringArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * Creates a tag with the specified name.
*
* @param name The name of the tag. * @param name The name of the tag.
*/ */
public StringArrayTag(String name) { public StringArrayTag(String name) {
@ -24,7 +25,8 @@ public class StringArrayTag extends Tag {
/** /**
* Creates a tag with the specified name. * 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. * @param value The value of the tag.
*/ */
public StringArrayTag(String name, String[] value) { public StringArrayTag(String name, String[] value) {
@ -39,6 +41,7 @@ public class StringArrayTag extends Tag {
/** /**
* Sets the value of this tag. * Sets the value of this tag.
*
* @param value New value of this tag. * @param value New value of this tag.
*/ */
public void setValue(String[] value) { public void setValue(String[] value) {
@ -51,6 +54,7 @@ public class StringArrayTag extends Tag {
/** /**
* Gets a value in this tag's array. * Gets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @return The value at the given index. * @return The value at the given index.
*/ */
@ -60,6 +64,7 @@ public class StringArrayTag extends Tag {
/** /**
* Sets a value in this tag's array. * Sets a value in this tag's array.
*
* @param index Index of the value. * @param index Index of the value.
* @param value Value to set. * @param value Value to set.
*/ */
@ -69,6 +74,7 @@ public class StringArrayTag extends Tag {
/** /**
* Gets the length of this tag's array. * Gets the length of this tag's array.
*
* @return This tag's array length. * @return This tag's array length.
*/ */
public int length() { public int length() {
@ -92,12 +98,12 @@ public class StringArrayTag extends Tag {
@Override @Override
public void write(DataOutputStream out) throws IOException { public void write(DataOutputStream out) throws IOException {
out.writeInt(this.value.length); out.writeInt(this.value.length);
for(int index = 0; index < this.value.length; index++) { for(int index = 0; index < this.value.length; index++) {
byte[] bytes = this.value[index].getBytes(NBTIO.CHARSET); byte[] bytes = this.value[index].getBytes(NBTIO.CHARSET);
out.writeShort(bytes.length); out.writeShort(bytes.length);
out.write(bytes); out.write(bytes);
} }
} }
@Override @Override