// Path: src/nbt/read/NBTReader.java
// public class NBTReader extends PushBackReader {
// 
//   /**
//    * Creates a reader for a nbt file.
//    * 
//    * @param file The nbt file.
//    * @throws IOException I/O Exception.
//    */
//   public NBTReader(final File file) throws IOException {
//     this(file, true);
//   }
// 
//   /**
//    * Creates a reader for a maybe zipped nbt file.
//    * 
//    * @param file The nbt file.
//    * @param wrapZip Whether the file is zipped or not.
//    * @throws IOException I/O Exception.
//    */
//   public NBTReader(final File file, final boolean wrapZip) throws IOException {
//     this(new BufferedInputStream(new FileInputStream(file)), wrapZip);
//   }
// 
//   /**
//    * Creates a reader for a maybe zipped nbt stream.
//    * 
//    * @param is The input stream.
//    * @param wrapZip Whether the file is zipped or not.
//    * @throws IOException I/O Exception.
//    */
//   public NBTReader(final InputStream is, final boolean wrapZip)
//       throws IOException {
//     super(wrapZip ? new GZIPInputStream(is) : is);
//   }
// 
//   /**
//    * Reads the nbt stream.
//    * 
//    * @param exp Expected type, {@code null} for no check.
//    * @param <T> The type.
//    * @return The root record.
//    * @throws IOException I/O Exception.
//    */
//   @SuppressWarnings("unchecked")
//   public <T extends NBTRecord> T read(final NBTType exp) throws IOException {
//     final NBTRecord read = NBTType.readRecord(this);
//     if(exp != null && read.getType() != exp) throw new IllegalStateException(
//         "Expected: " + exp + " Got: " + read.getType());
//     return (T) read;
//   }
// 
// }
// 
// Path: src/nbt/write/NBTWriter.java
// public class NBTWriter extends ByteWriter {
// 
//   /**
//    * Creates a writer for a zipped nbt file.
//    * 
//    * @param file The output file.
//    * @throws IOException I/O Exception.
//    */
//   public NBTWriter(final File file) throws IOException {
//     this(file, true);
//   }
// 
//   /**
//    * Creates a writer for a maybe zipped nbt file.
//    * 
//    * @param file The output file.
//    * @param wrapZip Whether the file is zipped or not.
//    * @throws IOException I/O Exception.
//    */
//   public NBTWriter(final File file, final boolean wrapZip) throws IOException {
//     this(new BufferedOutputStream(new FileOutputStream(file)), wrapZip);
//   }
// 
//   /**
//    * Creates a writer for a maybe zipped nbt stream.
//    * 
//    * @param out The output stream.
//    * @param wrapZip Whether the file is zipped or not.
//    * @throws IOException I/O Exception.
//    */
//   public NBTWriter(final OutputStream out, final boolean wrapZip)
//       throws IOException {
//     super(wrapZip ? new GZIPOutputStream(out) : out);
//   }
// 
//   /**
//    * Writes the nbt content.
//    * 
//    * @param record The root element.
//    * @throws IOException I/O Exception.
//    */
//   public void write(final NBTRecord record) throws IOException {
//     record.write(this);
//   }
// 
// }


import java.io.File;
import java.io.IOException;
import nbt.read.NBTReader;
import nbt.write.NBTWriter;
package nbt.record;



/**
 * Handles the loading and saving of nbt files.
 * 
 * @author Joschi <josua.krause@googlemail.com>
 */
public class NBTHandler {

  private final File nbtFile;

  private final boolean wrapZip;

  private final NBTCompound root;

  /**
   * Creates a nbt handler.
   * 
   * @param nbtFile The nbt file.
   * @param wrapZip Whether this file is zipped.
   * @throws IOException I/O Exception.
   */
  public NBTHandler(final File nbtFile, final boolean wrapZip)
      throws IOException {
    this.nbtFile = nbtFile;
    this.wrapZip = wrapZip;
// Path: src/nbt/read/NBTReader.java
// public class NBTReader extends PushBackReader {
// 
//   /**
//    * Creates a reader for a nbt file.
//    * 
//    * @param file The nbt file.
//    * @throws IOException I/O Exception.
//    */
//   public NBTReader(final File file) throws IOException {
//     this(file, true);
//   }
// 
//   /**
//    * Creates a reader for a maybe zipped nbt file.
//    * 
//    * @param file The nbt file.
//    * @param wrapZip Whether the file is zipped or not.
//    * @throws IOException I/O Exception.
//    */
//   public NBTReader(final File file, final boolean wrapZip) throws IOException {
//     this(new BufferedInputStream(new FileInputStream(file)), wrapZip);
//   }
// 
//   /**
//    * Creates a reader for a maybe zipped nbt stream.
//    * 
//    * @param is The input stream.
//    * @param wrapZip Whether the file is zipped or not.
//    * @throws IOException I/O Exception.
//    */
//   public NBTReader(final InputStream is, final boolean wrapZip)
//       throws IOException {
//     super(wrapZip ? new GZIPInputStream(is) : is);
//   }
// 
//   /**
//    * Reads the nbt stream.
//    * 
//    * @param exp Expected type, {@code null} for no check.
//    * @param <T> The type.
//    * @return The root record.
//    * @throws IOException I/O Exception.
//    */
//   @SuppressWarnings("unchecked")
//   public <T extends NBTRecord> T read(final NBTType exp) throws IOException {
//     final NBTRecord read = NBTType.readRecord(this);
//     if(exp != null && read.getType() != exp) throw new IllegalStateException(
//         "Expected: " + exp + " Got: " + read.getType());
//     return (T) read;
//   }
// 
// }
// 
// Path: src/nbt/write/NBTWriter.java
// public class NBTWriter extends ByteWriter {
// 
//   /**
//    * Creates a writer for a zipped nbt file.
//    * 
//    * @param file The output file.
//    * @throws IOException I/O Exception.
//    */
//   public NBTWriter(final File file) throws IOException {
//     this(file, true);
//   }
// 
//   /**
//    * Creates a writer for a maybe zipped nbt file.
//    * 
//    * @param file The output file.
//    * @param wrapZip Whether the file is zipped or not.
//    * @throws IOException I/O Exception.
//    */
//   public NBTWriter(final File file, final boolean wrapZip) throws IOException {
//     this(new BufferedOutputStream(new FileOutputStream(file)), wrapZip);
//   }
// 
//   /**
//    * Creates a writer for a maybe zipped nbt stream.
//    * 
//    * @param out The output stream.
//    * @param wrapZip Whether the file is zipped or not.
//    * @throws IOException I/O Exception.
//    */
//   public NBTWriter(final OutputStream out, final boolean wrapZip)
//       throws IOException {
//     super(wrapZip ? new GZIPOutputStream(out) : out);
//   }
// 
//   /**
//    * Writes the nbt content.
//    * 
//    * @param record The root element.
//    * @throws IOException I/O Exception.
//    */
//   public void write(final NBTRecord record) throws IOException {
//     record.write(this);
//   }
// 
// }


// Path: src/nbt/record/NBTHandler.java
import java.io.File;
import java.io.IOException;
import nbt.read.NBTReader;
import nbt.write.NBTWriter;

package nbt.record;



/**
 * Handles the loading and saving of nbt files.
 * 
 * @author Joschi <josua.krause@googlemail.com>
 */
public class NBTHandler {

  private final File nbtFile;

  private final boolean wrapZip;

  private final NBTCompound root;

  /**
   * Creates a nbt handler.
   * 
   * @param nbtFile The nbt file.
   * @param wrapZip Whether this file is zipped.
   * @throws IOException I/O Exception.
   */
  public NBTHandler(final File nbtFile, final boolean wrapZip)
      throws IOException {
    this.nbtFile = nbtFile;
    this.wrapZip = wrapZip;
    root = new NBTReader(nbtFile).read(NBTType.COMPOUND);