Search in sources :

Example 76 with ZipException

use of java.util.zip.ZipException in project Payara by payara.

the class Assembler method transferFile.

void transferFile(File file, JarOutputStream jos, String entryName) throws IOException {
    if (file == null || jos == null || entryName == null) {
        return;
    }
    ZipEntry entry = new ZipEntry(entryName);
    try {
        jos.putNextEntry(entry);
    } catch (ZipException ex) {
        return;
    }
    try (FileInputStream fin = new FileInputStream(file)) {
        transferContents(fin, jos);
        jos.closeEntry();
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException) FileInputStream(java.io.FileInputStream)

Example 77 with ZipException

use of java.util.zip.ZipException in project Payara by payara.

the class AppClientDeployerHelper method copy.

/**
 * copy the entryName element from the source abstract archive into
 * the target abstract archive
 */
static void copy(ReadableArchive source, WritableArchive target, String entryName) throws IOException {
    InputStream is = null;
    OutputStream os = null;
    try {
        is = source.getEntry(entryName);
        if (is != null) {
            try {
                os = target.putNextEntry(entryName);
            } catch (ZipException ze) {
                // this is a duplicate...
                return;
            }
            ArchivistUtils.copyWithoutClose(is, os);
        } else {
            // entryName as a prefix.
            for (Enumeration e = source.entries(entryName); e.hasMoreElements(); ) {
                copy(source, target, (String) e.nextElement());
            }
        }
    } catch (IOException ioe) {
        throw ioe;
    } finally {
        IOException closeEntryIOException = null;
        if (os != null) {
            try {
                target.closeEntry();
            } catch (IOException ioe) {
                closeEntryIOException = ioe;
            }
        }
        if (is != null) {
            is.close();
        }
        if (closeEntryIOException != null) {
            throw closeEntryIOException;
        }
    }
}
Also used : Enumeration(java.util.Enumeration) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ZipException(java.util.zip.ZipException) IOException(java.io.IOException)

Example 78 with ZipException

use of java.util.zip.ZipException in project MyPet by xXKeyleXx.

the class MySqlRepository method resultSetToMyPet.

// Pets ------------------------------------------------------------------------------------------------------------
private List<StoredMyPet> resultSetToMyPet(MyPetPlayer owner, ResultSet resultSet) {
    List<StoredMyPet> pets = new ArrayList<>();
    try {
        while (resultSet.next()) {
            InactiveMyPet pet = new InactiveMyPet(owner);
            pet.setUUID(UUID.fromString(resultSet.getString("uuid")));
            pet.setWorldGroup(resultSet.getString("world_group"));
            pet.setExp(resultSet.getDouble("exp"));
            pet.setHealth(resultSet.getDouble("health"));
            pet.setRespawnTime(resultSet.getInt("respawn_time"));
            pet.setPetName(Util.toString(resultSet.getBinaryStream("name"), StandardCharsets.UTF_8));
            pet.setPetType(MyPetType.valueOf(resultSet.getString("type")));
            pet.setLastUsed(resultSet.getLong("last_used"));
            pet.setSaturation(resultSet.getDouble("hunger"));
            pet.wantsToRespawn = resultSet.getBoolean("wants_to_spawn");
            String skillTreeName = resultSet.getString("skilltree");
            if (skillTreeName != null) {
                Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skillTreeName);
                if (skilltree != null) {
                    pet.setSkilltree(skilltree);
                }
            }
            try {
                pet.setSkills(TagStream.readTag(resultSet.getBlob("skills").getBinaryStream(), true));
            } catch (ZipException exception) {
                MyPetApi.getMyPetLogger().warning("Pet skills of player \"" + pet.getOwner().getName() + "\" (" + pet.getPetName() + ") could not be loaded!");
            }
            try {
                pet.setInfo(TagStream.readTag(resultSet.getBlob("info").getBinaryStream(), true));
            } catch (ZipException exception) {
                MyPetApi.getMyPetLogger().warning("Pet info of player \"" + pet.getOwner().getName() + "\" (" + pet.getPetName() + ") could not be loaded!");
            }
            List<RepositoryMyPetConverterService> converters = MyPetApi.getServiceManager().getServices(RepositoryMyPetConverterService.class);
            for (RepositoryMyPetConverterService converter : converters) {
                converter.convert(pet);
            }
            pets.add(pet);
        }
    } catch (SQLException | IOException e) {
        e.printStackTrace();
    }
    return pets;
}
Also used : Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) RepositoryMyPetConverterService(de.Keyle.MyPet.api.util.service.types.RepositoryMyPetConverterService) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) ZipException(java.util.zip.ZipException) TagString(de.keyle.knbt.TagString) IOException(java.io.IOException) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet)

Example 79 with ZipException

use of java.util.zip.ZipException in project MyPet by xXKeyleXx.

the class MongoDbRepository method documentToPlayer.

// Players ---------------------------------------------------------------------------------------------------------
private MyPetPlayer documentToPlayer(Document document) {
    try {
        MyPetPlayerImpl petPlayer;
        UUID internalUUID = UUID.fromString(document.getString("internal_uuid"));
        String playerName = document.getString("name");
        // raw "get" fixes wrong data type
        UUID mojangUUID = document.get("mojang_uuid") != null ? UUID.fromString("" + document.get("mojang_uuid")) : null;
        if (mojangUUID != null) {
            petPlayer = new MyPetPlayerImpl(internalUUID, mojangUUID);
            petPlayer.setLastKnownName(playerName);
        } else if (playerName != null) {
            petPlayer = new MyPetPlayerImpl(internalUUID, playerName);
        } else {
            MyPetApi.getLogger().warning("Player with no UUID or name found!");
            return null;
        }
        try {
            petPlayer.setExtendedInfo(TagStream.readTag(((Binary) document.get("extended_info")).getData(), true));
        } catch (ZipException exception) {
            MyPetApi.getMyPetLogger().warning("Extended info of player \"" + playerName + "\" (" + mojangUUID + ") could not be loaded!");
        }
        Document jsonObject = (Document) document.get("multi_world");
        for (Object o : jsonObject.keySet()) {
            String petUUID = jsonObject.get(o.toString()).toString();
            petPlayer.setMyPetForWorldGroup(o.toString(), UUID.fromString(petUUID));
        }
        if (document.containsKey("settings")) {
            document = (Document) document.get("settings");
        }
        petPlayer.setAutoRespawnEnabled(document.getBoolean("auto_respawn"));
        petPlayer.setAutoRespawnMin(document.getInteger("auto_respawn_min"));
        petPlayer.setCaptureHelperActive(document.getBoolean("capture_mode"));
        petPlayer.setHealthBarActive(document.getBoolean("health_bar"));
        petPlayer.setPetLivingSoundVolume(document.getDouble("pet_idle_volume").floatValue());
        return petPlayer;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : MyPetPlayerImpl(de.Keyle.MyPet.util.player.MyPetPlayerImpl) ZipException(java.util.zip.ZipException) Binary(org.bson.types.Binary) IOException(java.io.IOException) Document(org.bson.Document)

Example 80 with ZipException

use of java.util.zip.ZipException in project MyPet by xXKeyleXx.

the class MongoDbRepository method documentToMyPet.

// Pets ------------------------------------------------------------------------------------------------------------
private StoredMyPet documentToMyPet(MyPetPlayer owner, Document document) {
    try {
        InactiveMyPet pet = new InactiveMyPet(owner);
        pet.setUUID(UUID.fromString(document.getString("uuid")));
        pet.setWorldGroup(document.getString("world_group"));
        pet.setExp(document.getDouble("exp"));
        pet.setHealth(document.getDouble("health"));
        pet.setRespawnTime(document.getInteger("respawn_time"));
        pet.setPetName(document.getString("name"));
        pet.setPetType(MyPetType.valueOf(document.getString("type")));
        pet.setLastUsed(document.getLong("last_used"));
        pet.setSaturation(((Number) document.get("hunger")).doubleValue());
        pet.wantsToRespawn = document.getBoolean("wants_to_spawn");
        String skillTreeName = document.getString("skilltree");
        if (skillTreeName != null) {
            Skilltree skilltree = MyPetApi.getSkilltreeManager().getSkilltree(skillTreeName);
            if (skilltree != null) {
                pet.setSkilltree(skilltree);
            }
        }
        try {
            pet.setSkills(TagStream.readTag(((Binary) document.get("skills")).getData(), true));
        } catch (ZipException exception) {
            MyPetApi.getMyPetLogger().warning("Pet skills of player \"" + pet.getOwner().getName() + "\" (" + pet.getPetName() + ") could not be loaded!");
        }
        try {
            pet.setInfo(TagStream.readTag(((Binary) document.get("info")).getData(), true));
        } catch (ZipException exception) {
            MyPetApi.getMyPetLogger().warning("Pet info of player \"" + pet.getOwner().getName() + "\" (" + pet.getPetName() + ") could not be loaded!");
        }
        List<RepositoryMyPetConverterService> converters = MyPetApi.getServiceManager().getServices(RepositoryMyPetConverterService.class);
        for (RepositoryMyPetConverterService converter : converters) {
            converter.convert(pet);
        }
        return pet;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Skilltree(de.Keyle.MyPet.api.skill.skilltree.Skilltree) RepositoryMyPetConverterService(de.Keyle.MyPet.api.util.service.types.RepositoryMyPetConverterService) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) ZipException(java.util.zip.ZipException) Binary(org.bson.types.Binary) IOException(java.io.IOException)

Aggregations

ZipException (java.util.zip.ZipException)197 IOException (java.io.IOException)96 File (java.io.File)74 ZipEntry (java.util.zip.ZipEntry)67 ZipFile (java.util.zip.ZipFile)63 InputStream (java.io.InputStream)50 FileInputStream (java.io.FileInputStream)39 ZipInputStream (java.util.zip.ZipInputStream)26 FileOutputStream (java.io.FileOutputStream)23 BufferedInputStream (java.io.BufferedInputStream)22 JarFile (java.util.jar.JarFile)21 FileNotFoundException (java.io.FileNotFoundException)19 JarEntry (java.util.jar.JarEntry)19 ArrayList (java.util.ArrayList)18 ByteArrayInputStream (java.io.ByteArrayInputStream)15 ZipOutputStream (java.util.zip.ZipOutputStream)15 URL (java.net.URL)14 GZIPInputStream (java.util.zip.GZIPInputStream)12 BufferedOutputStream (java.io.BufferedOutputStream)8 RandomAccessFile (java.io.RandomAccessFile)8