use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project nifi by apache.
the class FlowFileUnpackagerV1 method unpackageFlowFile.
@Override
public Map<String, String> unpackageFlowFile(final InputStream in, final OutputStream out) throws IOException {
flowFilesRead++;
final TarArchiveInputStream tarIn = new TarArchiveInputStream(in);
final TarArchiveEntry attribEntry = tarIn.getNextTarEntry();
if (attribEntry == null) {
return null;
}
final Map<String, String> attributes;
if (attribEntry.getName().equals(FlowFilePackagerV1.FILENAME_ATTRIBUTES)) {
attributes = getAttributes(tarIn);
} else {
throw new IOException("Expected two tar entries: " + FlowFilePackagerV1.FILENAME_CONTENT + " and " + FlowFilePackagerV1.FILENAME_ATTRIBUTES);
}
final TarArchiveEntry contentEntry = tarIn.getNextTarEntry();
if (contentEntry != null && contentEntry.getName().equals(FlowFilePackagerV1.FILENAME_CONTENT)) {
// 512KB
final byte[] buffer = new byte[512 << 10];
int bytesRead = 0;
while ((bytesRead = tarIn.read(buffer)) != -1) {
// still more data to read
if (bytesRead > 0) {
out.write(buffer, 0, bytesRead);
}
}
out.flush();
} else {
throw new IOException("Expected two tar entries: " + FlowFilePackagerV1.FILENAME_CONTENT + " and " + FlowFilePackagerV1.FILENAME_ATTRIBUTES);
}
return attributes;
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project coprhd-controller by CoprHD.
the class WorkflowHelper method makeArchiveEntry.
private static TarArchiveEntry makeArchiveEntry(final String name, final Date modTime, final byte[] bytes) throws IOException {
final TarArchiveEntry entry = new TarArchiveEntry(name);
entry.setSize(bytes.length);
entry.setMode(0444);
entry.setModTime(modTime);
entry.setUserName("storageos");
entry.setGroupName("storageos");
return entry;
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project incubator-systemml by apache.
the class ValidateLicAndNotice method extractFileFromTGZ.
/**
* This will return the file from tgz file and store it in specified location.
*
* @param tgzFileName is the name of tgz file from which file to be extracted.
* @param fileName is the name of the file to be extracted.
* @param strDestLoc is the location where file will be extracted.
* @param bFirstDirLevel to indicate to get file from first directory level.
* @return Sucess or Failure
*/
public static boolean extractFileFromTGZ(String tgzFileName, String fileName, String strDestLoc, boolean bFirstDirLevel) {
boolean bRetCode = Constants.bFAILURE;
TarArchiveInputStream tarIn = null;
try {
tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(tgzFileName))));
} catch (Exception e) {
Utility.debugPrint(Constants.DEBUG_ERROR, "Exception in unzipping tar file: " + e);
return bRetCode;
}
try {
BufferedOutputStream bufOut = null;
BufferedInputStream bufIn = null;
TarArchiveEntry tarEntry = null;
while ((tarEntry = tarIn.getNextTarEntry()) != null) {
if (!tarEntry.getName().endsWith(fileName))
continue;
// Get file at root (in single directory) level. This is for License in root location.
if (bFirstDirLevel && (tarEntry.getName().indexOf('/') != tarEntry.getName().lastIndexOf('/')))
continue;
bufIn = new BufferedInputStream(tarIn);
int count;
byte[] data = new byte[Constants.BUFFER];
String strOutFileName = strDestLoc == null ? tarEntry.getName() : strDestLoc + "/" + fileName;
FileOutputStream fos = new FileOutputStream(strOutFileName);
bufOut = new BufferedOutputStream(fos, Constants.BUFFER);
while ((count = bufIn.read(data, 0, Constants.BUFFER)) != -1) {
bufOut.write(data, 0, count);
}
bufOut.flush();
bufOut.close();
bufIn.close();
bRetCode = Constants.bSUCCESS;
break;
}
} catch (Exception e) {
e.printStackTrace();
}
return bRetCode;
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project incubator-systemml by apache.
the class ValidateLicAndNotice method getFilesFromTGZ.
/**
* This will return the list of files from tgz file.
*
* @param tgzFileName is the name of tgz file from which list of files with specified file extension will be returned.
* @param fileExt is the file extension to be used to get list of files to be returned.
* @return Returns list of files having specified extension from tgz file.
*/
public static List<String> getFilesFromTGZ(String tgzFileName, String fileExt) {
TarArchiveInputStream tarIn = null;
try {
tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(tgzFileName))));
} catch (Exception e) {
Utility.debugPrint(Constants.DEBUG_ERROR, "Exception in unzipping tar file: " + e);
return null;
}
List<String> files = new ArrayList<String>();
try {
TarArchiveEntry tarEntry = null;
while ((tarEntry = tarIn.getNextTarEntry()) != null) {
if (tarEntry.getName().endsWith("." + fileExt)) {
int iPos = tarEntry.getName().lastIndexOf("/");
if (iPos == 0)
--iPos;
String strFileName = tarEntry.getName().substring(iPos + 1);
files.add(strFileName);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return (files);
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project gradle by gradle.
the class TarTaskOutputPacker method createTarEntry.
private static void createTarEntry(String path, long size, int mode, TarArchiveOutputStream tarOutput) throws IOException {
TarArchiveEntry entry = new TarArchiveEntry(path, true);
entry.setSize(size);
entry.setMode(mode);
tarOutput.putArchiveEntry(entry);
}
Aggregations