All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.plantuml.code.CompressionZip Maven / Gradle / Ivy

There is a newer version: 1.2024.8
Show newest version
// 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);
		}

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy