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();
}
}
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;
}
}
}
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;
}
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;
}
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;
}
Aggregations