List of usage examples for org.apache.commons.compress.archivers.tar TarConstants MAGIC_OFFSET
int MAGIC_OFFSET
To view the source code for org.apache.commons.compress.archivers.tar TarConstants MAGIC_OFFSET.
Click Source Link
From source file:org.jwifisd.eyefi.EyeFiServer.java
/** * eyefi sends the files tarred w will have to untar it first. * /*from w w w.ja v a 2 s.c om*/ * @param tarFile * the tar file * @param out * output stream to write the untarred contents. * @return true if successful * @throws Exception * if the file could not be untarred. */ private boolean extractTarFile(File tarFile, OutputStream out) throws Exception { boolean result = false; byte[] tarBytes = IOUtils.toByteArray(new FileInputStream(tarFile)); // This is stangege but posix was not correctly detected by the apache // lib, so we change some bytes so the detection will work. System.arraycopy(TarConstants.MAGIC_POSIX.getBytes("US-ASCII"), 0, tarBytes, TarConstants.MAGIC_OFFSET, TarConstants.MAGICLEN); TarArchiveInputStream tar = new TarArchiveInputStream(new ByteArrayInputStream(tarBytes)); final byte[] buffer = new byte[BUFFER_SIZE]; try { ArchiveEntry tarEntry = tar.getNextEntry(); if (tarEntry != null) { int n = 0; while ((n = tar.read(buffer)) >= 0) { out.write(buffer, 0, n); } result = true; } } finally { tar.close(); out.close(); } return result; }