use of riskyken.armourersWorkshop.common.exception.InvalidCubeTypeException in project Armourers-Workshop by RiskyKen.
the class SkinIOUtils method loadSkinFromStream.
public static Skin loadSkinFromStream(InputStream inputStream) {
DataInputStream stream = null;
Skin skin = null;
try {
stream = new DataInputStream(new BufferedInputStream(inputStream));
skin = SkinSerializer.readSkinFromStream(stream);
} catch (FileNotFoundException e) {
ModLogger.log(Level.WARN, "Skin file not found.");
e.printStackTrace();
} catch (IOException e) {
ModLogger.log(Level.ERROR, "Skin file load failed.");
e.printStackTrace();
} catch (NewerFileVersionException e) {
ModLogger.log(Level.ERROR, "Can not load skin file it was saved in newer version.");
e.printStackTrace();
} catch (InvalidCubeTypeException e) {
ModLogger.log(Level.ERROR, "Unable to load skin. Unknown cube types found.");
e.printStackTrace();
} finally {
IOUtils.closeQuietly(stream);
IOUtils.closeQuietly(inputStream);
}
return skin;
}
use of riskyken.armourersWorkshop.common.exception.InvalidCubeTypeException in project Armourers-Workshop by RiskyKen.
the class SkinIOUtils method loadSkinFromFile.
public static Skin loadSkinFromFile(File file) {
DataInputStream stream = null;
Skin skin = null;
try {
stream = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
skin = SkinSerializer.readSkinFromStream(stream);
} catch (FileNotFoundException e) {
ModLogger.log(Level.WARN, "Skin file not found.");
ModLogger.log(Level.WARN, file);
} catch (IOException e) {
ModLogger.log(Level.ERROR, "Skin file load failed.");
e.printStackTrace();
} catch (NewerFileVersionException e) {
ModLogger.log(Level.ERROR, "Can not load skin file it was saved in newer version.");
e.printStackTrace();
} catch (InvalidCubeTypeException e) {
ModLogger.log(Level.ERROR, "Unable to load skin. Unknown cube types found.");
e.printStackTrace();
} catch (Exception e) {
ModLogger.log(Level.ERROR, "Unable to load skin. Unknown error.");
e.printStackTrace();
} finally {
IOUtils.closeQuietly(stream);
}
return skin;
}
use of riskyken.armourersWorkshop.common.exception.InvalidCubeTypeException in project Armourers-Workshop by RiskyKen.
the class SkinSerializer method readSkinFromStream.
public static Skin readSkinFromStream(DataInputStream stream) throws IOException, NewerFileVersionException, InvalidCubeTypeException {
int fileVersion = stream.readInt();
if (fileVersion > Skin.FILE_VERSION) {
throw new NewerFileVersionException();
}
if (fileVersion > 12) {
String header = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!header.equals(TAG_SKIN_HEADER)) {
ModLogger.log(Level.ERROR, "Error loading skin header.");
}
String propsHeader = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!propsHeader.equals(TAG_SKIN_PROPS_HEADER)) {
ModLogger.log(Level.ERROR, "Error loading skin props header.");
}
}
SkinProperties properties = new SkinProperties();
boolean loadedProps = true;
IOException e = null;
if (fileVersion < 12) {
String authorName = stream.readUTF();
String customName = stream.readUTF();
String tags = "";
if (!(fileVersion < 4)) {
tags = stream.readUTF();
} else {
tags = "";
}
properties.setProperty(Skin.KEY_AUTHOR_NAME, authorName);
properties.setProperty(Skin.KEY_CUSTOM_NAME, customName);
if (tags != null && !tags.equalsIgnoreCase("")) {
properties.setProperty(KEY_TAGS, tags);
}
} else {
try {
properties.readFromStream(stream, fileVersion);
} catch (IOException propE) {
ModLogger.log(Level.ERROR, "prop load failed");
e = propE;
loadedProps = false;
}
}
if (fileVersion > 12) {
String propsFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!propsFooter.equals(TAG_SKIN_PROPS_FOOTER)) {
ModLogger.log(Level.ERROR, "Error loading skin props footer.");
}
String typeHeader = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!typeHeader.equals(TAG_SKIN_TYPE_HEADER)) {
ModLogger.log(Level.ERROR, "Error loading skin type header.");
}
}
ISkinType equipmentSkinType = null;
if (fileVersion < 5) {
if (loadedProps) {
equipmentSkinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromLegacyId(stream.readByte() - 1);
} else {
throw e;
}
} else {
if (loadedProps) {
String regName = stream.readUTF();
if (regName.equals(SkinTypeRegistry.skinSkirt.getRegistryName())) {
regName = SkinTypeRegistry.skinLegs.getRegistryName();
}
equipmentSkinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(regName);
} else {
StringBuilder sb = new StringBuilder();
while (true) {
sb.append(new String(new byte[] { stream.readByte() }, "UTF-8"));
if (sb.toString().endsWith("armourers:")) {
break;
}
}
ModLogger.log("Got armourers");
sb = new StringBuilder();
sb.append("armourers:");
while (SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(sb.toString()) == null) {
sb.append(new String(new byte[] { stream.readByte() }, "UTF-8"));
}
ModLogger.log(sb.toString());
equipmentSkinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(sb.toString());
ModLogger.log("got failed type " + equipmentSkinType);
}
}
if (fileVersion > 12) {
String typeFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!typeFooter.equals(TAG_SKIN_TYPE_FOOTER)) {
ModLogger.log(Level.ERROR, "Error loading skin type footer.");
}
}
if (equipmentSkinType == null) {
throw new InvalidCubeTypeException();
}
if (fileVersion > 12) {
String typeFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!typeFooter.equals(TAG_SKIN_PAINT_HEADER)) {
ModLogger.log(Level.ERROR, "Error loading skin paint header.");
}
}
int[] paintData = null;
if (fileVersion > 7) {
boolean hasPaintData = stream.readBoolean();
if (hasPaintData) {
paintData = new int[SkinTexture.TEXTURE_SIZE];
for (int i = 0; i < SkinTexture.TEXTURE_SIZE; i++) {
paintData[i] = stream.readInt();
}
}
}
if (fileVersion > 12) {
String typeFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!typeFooter.equals(TAG_SKIN_PAINT_FOOTER)) {
ModLogger.log(Level.ERROR, "Error loading skin paint footer.");
}
}
int size = stream.readByte();
ArrayList<SkinPart> parts = new ArrayList<SkinPart>();
for (int i = 0; i < size; i++) {
if (fileVersion > 12) {
String partHeader = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!partHeader.equals(TAG_SKIN_PART_HEADER)) {
ModLogger.log(Level.ERROR, "Error loading skin part header.");
}
}
SkinPart part = SkinPartSerializer.loadSkinPart(stream, fileVersion);
if (fileVersion > 12) {
String partFooter = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!partFooter.equals(TAG_SKIN_PART_FOOTER)) {
ModLogger.log(Level.ERROR, "Error loading skin part footer.");
}
}
parts.add(part);
}
if (fileVersion > 12) {
String footer = StreamUtils.readString(stream, Charsets.US_ASCII);
if (!footer.equals(TAG_SKIN_FOOTER)) {
ModLogger.log(Level.ERROR, "Error loading skin footer.");
}
}
return new Skin(properties, equipmentSkinType, paintData, parts);
}
Aggregations