ArchiveUtils

Utility methods for archive handling. For example, to create a ZIP or JAR. 

Methods

createZip

Description:

MethodReturn valuesDescription

createZip(File path, OutputStream os)

void

Create ZIP archive from file.

path: The file to compress.

os: The output stream of the file.

Example:

package com.openkm;

import java.io.ByteArrayOutputStream;
import java.io.File;

import com.openkm.util.ArchiveUtils;

public class Test {
	public static void main(String[] args) {
		try {
			File file = new File("/home/openkm/test.pdf");
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			ArchiveUtils.createZip(file, baos);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}/code>

createJar

Description:

MethodReturn valuesDescription

createJar(File path, String root, OutputStream os)

void

Recursively create JAR archive from directory.

path: The file to compress.

root: A text with destiny of the file.

os: The output stream of the file.

Example:

package com.openkm;

import java.io.File;
import java.io.FileOutputStream;
import java.io.StringWriter;

import com.openkm.util.ArchiveUtils;
import com.openkm.util.FileUtils;
import com.openkm.util.PathUtils;
import com.openkm.util.impexp.RepositoryExporter;
import com.openkm.util.impexp.TextInfoDecorator;

public class Test {
	public static void main(String[] args) {
		try {
			StringWriter out = new StringWriter();

			final File tmpFile = File.createTempFile("/home/openkm/test", ".jar");
			FileOutputStream os = new FileOutputStream(tmpFile);

			File tmp = FileUtils.createTempDir();
			// Export files
			RepositoryExporter.exportDocuments(null, "/home/openkm", tmp, false, false, out,
					new TextInfoDecorator("/home/openkm"));

			// Jar files
			ArchiveUtils.createJar(tmp, PathUtils.getName("/home/openkm"), os);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}