net.sourceforge.plantuml.code.CompressionZip Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-mit Show documentation
Show all versions of plantuml-mit Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml.code;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class CompressionZip implements Compression {
// ::remove file when __CORE__
public byte[] compress(byte[] in) {
throw new UnsupportedOperationException();
}
public ByteArray decompress(byte[] input) throws NoPlantumlCompressionException {
try {
try (final ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(input))) {
final ZipEntry ent = zis.getNextEntry();
final String name = ent.getName();
final byte[] buffer = new byte[10_000];
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
int len;
while ((len = zis.read(buffer)) > 0) {
baos.write(buffer, 0, len);
if (baos.size() > 200_000)
throw new NoPlantumlCompressionException("Zip error");
}
return ByteArray.from(baos.toByteArray());
}
}
} catch (IOException e) {
throw new NoPlantumlCompressionException(e);
}
}
}