Solved Zip Exception: Not in GZIP Format

Discussion in 'Plugin Development' started by mrkirby153, Mar 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    mrkirby153

    So I was following this: https://forums.bukkit.org/threads/pasting-loading-schematics.87129/ so I can load schematics, and I'm getting this error
    Code:
    [19:52:02 WARN]: java.util.zip.ZipException: Not in GZIP format
    [19:52:02 WARN]:        at java.util.zip.GZIPInputStream.readHeader(Unknown Sour
    ce)
    [19:52:02 WARN]:        at java.util.zip.GZIPInputStream.<init>(Unknown Source)
    [19:52:02 WARN]:        at java.util.zip.GZIPInputStream.<init>(Unknown Source)
    [19:52:02 WARN]:        at org.jnbt.NBTInputStream.<init>(NBTInputStream.java:71
    )
    [19:52:02 WARN]:        at me.mrkirby153.plugins.simplegames.lobby.Lobbies.loadS
    chematic(Lobbies.java:53)
    [19:52:02 WARN]:        at me.mrkirby153.plugins.simplegames.game.Game.<init>(Ga
    me.java:13)
    [19:52:02 WARN]:        at me.mrkirby153.plugins.simplegames.SimpleGames.onEnabl
    e(SimpleGames.java:50)
    [19:52:02 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
    in.java:218)
    [19:52:02 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(
    JavaPluginLoader.java:457)
    [19:52:02 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(Si
    mplePluginManager.java:384)
    [19:52:02 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin
    (CraftServer.java:298)
    [19:52:02 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlug
    ins(CraftServer.java:280)
    [19:52:02 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.reload(Cra
    ftServer.java:630)
    [19:52:02 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:279)
    [19:52:02 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    oadCommand.java:23)
    [19:52:02 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:196)
    [19:52:02 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCo
    mmand(CraftServer.java:542)
    [19:52:02 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchSe
    rverCommand(CraftServer.java:529)
    [19:52:02 WARN]:        at net.minecraft.server.v1_7_R1.DedicatedServer.aw(Dedic
    atedServer.java:286)
    [19:52:02 WARN]:        at net.minecraft.server.v1_7_R1.DedicatedServer.u(Dedica
    tedServer.java:251)
    [19:52:02 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.t(Minecr
    aftServer.java:545)
    [19:52:02 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.run(Mine
    craftServer.java:457)
    [19:52:02 WARN]:        at net.minecraft.server.v1_7_R1.ThreadServerApplication.
    run(SourceFile:617)
    This happens when I'm trying to load a schematic created by mcedit.

    Code:java
    1. public static Schematic loadSchematic(File file) throws IOException
    2. {
    3. FileInputStream stream = new FileInputStream(file);
    4. NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(stream));
    5.  
    6. CompoundTag schematicTag = (CompoundTag) nbtStream.readTag();
    7. if (!schematicTag.getName().equals("Schematic")) {
    8. throw new IllegalArgumentException("Tag \"Schematic\" does not exist or is not first");
    9. }
    10.  
    11. Map<String, Tag> schematic = schematicTag.getValue();
    12. if (!schematic.containsKey("Blocks")) {
    13. throw new IllegalArgumentException("Schematic file is missing a \"Blocks\" tag");
    14. }
    15.  
    16. short width = getChildTag(schematic, "Width", ShortTag.class).getValue();
    17. short length = getChildTag(schematic, "Length", ShortTag.class).getValue();
    18. short height = getChildTag(schematic, "Height", ShortTag.class).getValue();
    19.  
    20. String materials = getChildTag(schematic, "Materials", StringTag.class).getValue();
    21. if (!materials.equals("Alpha")) {
    22. throw new IllegalArgumentException("Schematic file is not an Alpha schematic");
    23. }
    24.  
    25. byte[] blocks = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
    26. byte[] blockData = getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
    27. return new Schematic(blocks, blockData, width, length, height);
    28. }
    29.  
    30. private static <T extends Tag> T getChildTag(Map<String, Tag> items, String key, Class<T> expected) throws IllegalArgumentException
    31. {
    32. if (!items.containsKey(key)) {
    33. throw new IllegalArgumentException("Schematic file is missing a \"" + key + "\" tag");
    34. }
    35. Tag tag = items.get(key);
    36. if (!expected.isInstance(tag)) {
    37. throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName());
    38. }
    39. return expected.cast(tag);
    40. }
    41.  
    42. public static void pasteLobby(World world, Location loc, Schematic schematic)
    43. {
    44. byte[] blocks = schematic.getBlocks();
    45. byte[] blockData = schematic.getData();
    46.  
    47. short length = schematic.getLenght();
    48. short width = schematic.getWidth();
    49. short height = schematic.getHeight();
    50.  
    51. for (int x = 0; x < width; ++x) {
    52. for (int y = 0; y < height; ++y) {
    53. for (int z = 0; z < length; ++z) {
    54. int index = y * width * length + z * width + x;
    55. Block block = new Location(world, x + loc.getX(), y + loc.getY(), z + loc.getZ()).getBlock();
    56. block.setTypeIdAndData(blocks[index], blockData[index], true);
    57. }
    58. }
    59. }
    60. }
    61.  

    Part of Lobbies.java ^^^
     
  2. Offline

    MrGermanrain

  3. Offline

    mrkirby153

    MrGermanrain

    That's not it. It goes away if I don't call loadSchematic(); second of all, that link was for general bukkit help. Not plugin development
     
  4. Offline

    xTrollxDudex

    mrkirby153
    Show method call. Most likely your file is not a valid compression.
     
  5. Offline

    mrkirby153

    xTrollxDudex

    I'm not at my computer right now but the way I'm calling it is something along Lobbies.loadSchematic(new File(plugin.getDataFolder()+File.seperator+"lobbies"+File.seperator+name+".schematic")); and the schematic file is a file exported from MCEDIT
     
  6. Offline

    xTrollxDudex

    mrkirby153
    I can't read binary files, but I'm pretty sure that your FILE.schematic is not a compressed file encoding, or does not have a zipped magic header on the file... Refer to GZipInputStream src, it throws the exception after checking the header.
     
  7. Offline

    mrkirby153

    xTrollxDudex

    Okay, now do you know of any tutorials that can allow me to successfully paste schematics?
     
  8. Offline

    xTrollxDudex

    mrkirby153
    Don't wrap InputStream with GZip, just use it raw
     
  9. Offline

    mrkirby153

Thread Status:
Not open for further replies.

Share This Page