use of java.util.zip.ZipEntry in project OpenGrok by OpenGrok.
the class SCCSgetTest method getRevision.
/**
* Test of getRevision method, of class SCCSget.
*/
@Test
public void getRevision() throws Exception {
if (!haveSccs) {
System.out.println("sccs not available. Skipping test");
return;
}
ZipInputStream zstream = new ZipInputStream(getClass().getResourceAsStream("sccs-revisions.zip"));
ZipEntry entry;
while ((entry = zstream.getNextEntry()) != null) {
String expected = readInput(zstream);
InputStream sccs = SCCSget.getRevision("sccs", sccsfile, entry.getName());
String got = readInput(sccs);
sccs.close();
zstream.closeEntry();
assertEquals(expected, got);
}
zstream.close();
}
use of java.util.zip.ZipEntry in project OpenGrok by OpenGrok.
the class FileUtilities method extractArchive.
public static void extractArchive(File sourceBundle, File root) throws IOException {
ZipFile zipfile = new ZipFile(sourceBundle);
Enumeration<? extends ZipEntry> e = zipfile.entries();
while (e.hasMoreElements()) {
ZipEntry ze = e.nextElement();
File file = new File(root, ze.getName());
if (ze.isDirectory()) {
file.mkdirs();
} else {
InputStream in = zipfile.getInputStream(ze);
assertNotNull(in);
FileOutputStream out = new FileOutputStream(file);
assertNotNull(out);
copyFile(in, out);
}
}
}
use of java.util.zip.ZipEntry in project OpenMEAP by OpenMEAP.
the class LocalStorageImpl method unzipImportArchive.
public void unzipImportArchive(UpdateStatus update) throws LocalStorageException {
// at this point, we've verified that:
// 1) we have enough space on the device
// 2) the archive downloaded is what was expected
ZipInputStream zis = null;
String newPrefix = "com.openmeap.storage." + update.getUpdateHeader().getHash().getValue();
File hashHolder = null;
String hashRootAbsolutePath = "";
try {
hashHolder = new File(activity.getFilesDir(), newPrefix);
hashHolder.mkdir();
hashRootAbsolutePath = hashHolder.getAbsolutePath();
} catch (Exception e) {
System.out.println("Exception thrown while creating hash folder.");
System.out.println(e);
}
try {
zis = new ZipInputStream(getImportArchiveInputStream());
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
if (ze.isDirectory()) {
// continue;
try {
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
System.out.println("Writing directory structure in phone memory.");
File directoryStructure = new File(hashRootAbsolutePath, ze.getName());
directoryStructure.mkdirs();
} catch (Exception e) {
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
System.out.println("Exception thrown while writing directory structure.");
System.out.println(e);
}
} else {
try {
String osSeperator = System.getProperty("file.separator");
int seperatorLastIndex = ze.getName().lastIndexOf(osSeperator);
String fileName = ze.getName().substring(seperatorLastIndex + 1, ze.getName().length());
String fileNameParentDirectoryPrefix = "";
String absolutePathFromPrefix = "";
if (seperatorLastIndex != -1 && seperatorLastIndex != 0) {
fileNameParentDirectoryPrefix = ze.getName().substring(0, seperatorLastIndex);
absolutePathFromPrefix = hashRootAbsolutePath + osSeperator + fileNameParentDirectoryPrefix;
} else {
absolutePathFromPrefix = hashRootAbsolutePath + osSeperator;
}
URI osResourePathForThisFile = URI.create(absolutePathFromPrefix);
File writableFileReference = new File(osResourePathForThisFile.getPath(), fileName);
OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(writableFileReference.getAbsolutePath(), true), 1024);
try {
byte[] buffer = new byte[1024];
int count;
while ((count = zis.read(buffer)) != -1) {
outputStream.write(buffer, 0, count);
}
} catch (Exception e) {
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
System.out.println("Exception while writing file contents.");
System.out.println(e);
} finally {
outputStream.close();
}
} catch (Exception e) {
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
System.out.println("Unknown exception.");
System.out.println(e);
}
}
// Commenting following code to make use of file:/// alternate to content://
// OutputStream baos = openFileOutputStream(newPrefix,ze.getName());
// try {
// byte[] buffer = new byte[1024];
// int count;
// while ((count = zis.read(buffer)) != -1) {
// baos.write(buffer, 0, count);
// }
// }
// catch( Exception e ) {
// ;// TODO: something, for the love of god.
// }
// finally {
// baos.close();
// }
}
} catch (Exception e) {
throw new LocalStorageException(e);
} finally {
if (zis != null) {
try {
zis.close();
} catch (IOException e) {
throw new GenericRuntimeException(e);
}
}
}
}
use of java.util.zip.ZipEntry in project OpenMEAP by OpenMEAP.
the class FileOperationManagerImpl method unzipFile.
@Override
public void unzipFile(ZipFile zipFile, String destinationDir) throws FileOperationException {
try {
int BUFFER = 1024;
BufferedOutputStream dest = null;
BufferedInputStream is = null;
OutputStream fos = null;
ZipEntry entry;
Enumeration e = zipFile.entries();
while (e.hasMoreElements()) {
try {
entry = (ZipEntry) e.nextElement();
is = new BufferedInputStream(zipFile.getInputStream(entry));
String newFile = destinationDir + File.separator + entry.getName();
if (entry.isDirectory()) {
// skip directories, resource manager will create for us
continue;
} else {
fos = write(newFile);
dest = new BufferedOutputStream(fos, BUFFER);
Utils.pipeInputStreamIntoOutputStream(is, dest);
}
} finally {
if (dest != null) {
dest.close();
}
if (fos != null) {
fos.close();
}
if (is != null) {
is.close();
}
}
}
} catch (IOException ioe) {
throw new FileOperationException(ioe);
}
}
use of java.util.zip.ZipEntry in project OpenMEAP by OpenMEAP.
the class ZipUtils method unzipFile.
/**
* Unzips a file into the destination directory provided.
*
* @param zipFile
* @param destinationDir
* @throws IOException
*/
public static void unzipFile(ZipFile zipFile, File destinationDir) throws IOException {
int BUFFER = 1024;
BufferedOutputStream dest = null;
BufferedInputStream is = null;
if (!destinationDir.exists()) {
destinationDir.mkdir();
}
ZipEntry entry;
Enumeration e = zipFile.entries();
while (e.hasMoreElements()) {
try {
entry = (ZipEntry) e.nextElement();
is = new BufferedInputStream(zipFile.getInputStream(entry));
File file = new File(destinationDir, entry.getName());
if (!file.exists() && entry.isDirectory()) {
file.mkdirs();
} else {
FileOutputStream fos = new FileOutputStream(file, false);
dest = new BufferedOutputStream(fos, BUFFER);
Utils.pipeInputStreamIntoOutputStream(is, fos);
}
} finally {
if (dest != null) {
dest.close();
}
if (is != null) {
is.close();
}
}
}
}
Aggregations