本文整理汇总了Java中org.apache.commons.compress.archivers.tar.TarArchiveEntry.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java TarArchiveEntry.getSize方法的具体用法?Java TarArchiveEntry.getSize怎么用?Java TarArchiveEntry.getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.tar.TarArchiveEntry
的用法示例。
在下文中一共展示了TarArchiveEntry.getSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addFile
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* @deprecated see {@link PLP5ProjectParser#parse(File)}
*/
private static void addFile(TarArchiveInputStream plpInputStream,
TarArchiveEntry entry, File assembleFile, List<ASMFile> projectFiles)
throws IOException
{
byte[] content = new byte[(int) entry.getSize()];
int currentIndex = 0;
while (currentIndex < entry.getSize())
{
plpInputStream.read(content, currentIndex, content.length - currentIndex);
currentIndex++;
}
if (entry.getName().endsWith(".asm"))
{
ASMFile asmFile = new SimpleASMFile(null, entry.getName());
asmFile.setContent(new String(content));
projectFiles.add(asmFile);
}
}
示例2: addFile
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private void addFile(TarArchiveEntry entry) throws IOException
{
byte[] content = new byte[(int) entry.getSize()];
int currentIndex = 0;
while (currentIndex < entry.getSize())
{
inputStream.read(content, currentIndex, content.length - currentIndex);
currentIndex++;
}
if (entry.getName().endsWith(".asm"))
{
ASMFile asmFile = new SimpleASMFile(project, entry.getName());
asmFile.setContent(new String(content));
project.add(asmFile);
}
}
示例3: untarFile
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
public static void untarFile(File file) throws IOException {
FileInputStream fileInputStream = null;
String currentDir = file.getParent();
try {
fileInputStream = new FileInputStream(file);
GZIPInputStream gzipInputStream = new GZIPInputStream(fileInputStream);
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(gzipInputStream);
TarArchiveEntry tarArchiveEntry;
while (null != (tarArchiveEntry = tarArchiveInputStream.getNextTarEntry())) {
if (tarArchiveEntry.isDirectory()) {
FileUtils.forceMkdir(new File(currentDir + File.separator + tarArchiveEntry.getName()));
} else {
byte[] content = new byte[(int) tarArchiveEntry.getSize()];
int offset = 0;
tarArchiveInputStream.read(content, offset, content.length - offset);
FileOutputStream outputFile = new FileOutputStream(currentDir + File.separator + tarArchiveEntry.getName());
org.apache.commons.io.IOUtils.write(content, outputFile);
outputFile.close();
}
}
} catch (FileNotFoundException e) {
throw new IOException(e.getStackTrace().toString());
}
}
示例4: getTransferVmdK
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private ITransferVmdkFrom getTransferVmdK(final String templateFilePathStr, final String vmdkName) throws IOException {
final Path templateFilePath = Paths.get(templateFilePathStr);
if (isOva(templateFilePath)) {
final TarArchiveInputStream tar = new TarArchiveInputStream(new FileInputStream(templateFilePathStr));
TarArchiveEntry entry;
while ((entry = tar.getNextTarEntry()) != null) {
if (new File(entry.getName()).getName().startsWith(vmdkName)) {
return new TransferVmdkFromInputStream(tar, entry.getSize());
}
}
} else if (isOvf(templateFilePath)) {
final Path vmdkPath = templateFilePath.getParent().resolve(vmdkName);
return new TransferVmdkFromFile(vmdkPath.toFile());
}
throw new RuntimeException(NOT_OVA_OR_OVF);
}
示例5: consumeAsTar
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
public static String consumeAsTar ( InputStream dockerTarStream, int chunkSize, int maxSize )
throws Exception {
StringWriter logwriter = new StringWriter();
try (TarArchiveInputStream tarInputStream = new TarArchiveInputStream( dockerTarStream )) {
TarArchiveEntry tarEntry = tarInputStream.getNextTarEntry();
logger.info( "tar name: {}", tarEntry.getName() );
byte[] bufferAsByteArray = new byte[ chunkSize ];
long tarEntrySize = tarEntry.getSize();
int numReadIn = 0;
while (tarInputStream.available() > 0 && numReadIn < maxSize && numReadIn <= tarEntrySize) {
int numRead = IOUtils.read( tarInputStream, bufferAsByteArray );
numReadIn += numRead;
String stringReadIn = new String( bufferAsByteArray, 0, numRead );
logwriter.write( stringReadIn );
logger.debug( "numRead: {}, chunk: {}", numRead, stringReadIn );
}
while (IOUtils.read( dockerTarStream, bufferAsByteArray ) > 0) {
// need to read fully or stream will leak
}
// response.close();
}
return logwriter.toString();
}
示例6: extract
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
public void extract(File dir ) throws IOException {
File listDir[] = dir.listFiles();
if (listDir.length!=0){
for (File i:listDir){
/* Warning! this will try and extract all files in the directory
if other files exist, a for loop needs to go here to check that
the file (i) is an archive file before proceeding */
if (i.isDirectory()){
break;
}
String fileName = i.toString();
String tarFileName = fileName +".tar";
FileInputStream instream= new FileInputStream(fileName);
GZIPInputStream ginstream =new GZIPInputStream(instream);
FileOutputStream outstream = new FileOutputStream(tarFileName);
byte[] buf = new byte[1024];
int len;
while ((len = ginstream.read(buf)) > 0)
{
outstream.write(buf, 0, len);
}
ginstream.close();
outstream.close();
//There should now be tar files in the directory
//extract specific files from tar
TarArchiveInputStream myTarFile=new TarArchiveInputStream(new FileInputStream(tarFileName));
TarArchiveEntry entry = null;
int offset;
FileOutputStream outputFile=null;
//read every single entry in TAR file
while ((entry = myTarFile.getNextTarEntry()) != null) {
//the following two lines remove the .tar.gz extension for the folder name
fileName = i.getName().substring(0, i.getName().lastIndexOf('.'));
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
File outputDir = new File(i.getParent() + "/" + fileName + "/" + entry.getName());
if(! outputDir.getParentFile().exists()){
outputDir.getParentFile().mkdirs();
}
//if the entry in the tar is a directory, it needs to be created, only files can be extracted
if(entry.isDirectory()){
outputDir.mkdirs();
}else{
byte[] content = new byte[(int) entry.getSize()];
offset=0;
myTarFile.read(content, offset, content.length - offset);
outputFile=new FileOutputStream(outputDir);
IOUtils.write(content,outputFile);
outputFile.close();
}
}
//close and delete the tar files, leaving the original .tar.gz and the extracted folders
myTarFile.close();
File tarFile = new File(tarFileName);
tarFile.delete();
}
}
}
示例7: extractTar
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
public static void extractTar(String fileName) throws Exception {
if (!fileName.toLowerCase().endsWith(TAR)) {
return;
}
File file = new File(fileName);
if (file.isDirectory()) {
return;
}
TarArchiveInputStream myTarFile = new TarArchiveInputStream(new FileInputStream(fileName));
TarArchiveEntry entry;
int offset;
FileOutputStream outputFile;
//read every single entry in TAR file
while ((entry = myTarFile.getNextTarEntry()) != null) {
//the following two lines remove the .tar.gz extension for the folder name
String fName = file.getName().substring(0, file.getName().lastIndexOf('.'));
if (fName.lastIndexOf('.') != -1) {
fName = fName.substring(0, fName.lastIndexOf('.'));
}
File outputDir = new File(file.getParent() + File.separator + entry.getName());
if (!outputDir.getParentFile().exists()) {
outputDir.getParentFile().mkdirs();
}
//if the entry in the tar is a directory, it needs to be created, only files can be extracted
if (entry.isDirectory()) {
outputDir.mkdirs();
} else {
byte[] content = new byte[(int) entry.getSize()];
offset = 0;
myTarFile.read(content, offset, content.length - offset);
outputFile = new FileOutputStream(outputDir);
IOUtils.write(content, outputFile);
outputFile.close();
}
}
}
示例8: getNextElement
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private Message getNextElement() {
if (tarInputStream == null) {
return null;
}
try {
TarArchiveEntry current = getNextEntry();
if (current != null) {
LOGGER.debug("Reading tarEntry {}", current.getName());
Message answer = new DefaultMessage();
answer.getHeaders().putAll(inputMessage.getHeaders());
answer.setHeader(TARFILE_ENTRY_NAME_HEADER, current.getName());
answer.setHeader(Exchange.FILE_NAME, current.getName());
if (current.getSize() > 0) {
answer.setBody(new TarElementInputStreamWrapper(tarInputStream));
} else {
// Workaround for the case when the entry is zero bytes big
answer.setBody(new ByteArrayInputStream(new byte[0]));
}
return answer;
} else {
LOGGER.trace("Closed tarInputStream");
return null;
}
} catch (IOException exception) {
//Just wrap the IOException as CamelRuntimeException
throw new RuntimeCamelException(exception);
}
}
示例9: perform
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private void perform ( final Path file, final Map<String, String> metadata ) throws IOException
{
try ( final GZIPInputStream gis = new GZIPInputStream ( new FileInputStream ( file.toFile () ) );
final TarArchiveInputStream tis = new TarArchiveInputStream ( gis ) )
{
TarArchiveEntry entry;
while ( ( entry = tis.getNextTarEntry () ) != null )
{
if ( entry.getName ().equals ( "package/package.json" ) )
{
final byte[] data = new byte[(int)entry.getSize ()];
ByteStreams.read ( tis, data, 0, data.length );
final String str = StandardCharsets.UTF_8.decode ( ByteBuffer.wrap ( data ) ).toString ();
try
{
// test parse
new JsonParser ().parse ( str );
// store
metadata.put ( "package.json", str );
}
catch ( final JsonParseException e )
{
// ignore
}
break; // stop parsing the archive
}
}
}
}
示例10: validateTarEntry
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private void validateTarEntry(TarArchiveEntry entry)
{
if (entry.getSize() > ARCHIVE_FILE_SIZE_LIMIT) {
throw new IllegalArgumentException(String.format(ENGLISH,
"Size of a file in the archive exceeds limit (%d > %d bytes): %s",
entry.getSize(), ARCHIVE_FILE_SIZE_LIMIT, entry.getName()));
}
}
示例11: installWindowsPHP
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
private static File installWindowsPHP(File home, InstallProgressReporter progress){
progress.report(0.0);
try{
String link = System.getProperty("os.arch").contains("64") ? "https://bintray.com/artifact/download/pocketmine/PocketMine/PHP_7.0.3_x64_Windows.tar.gz" : "https://bintray.com/artifact/download/pocketmine/PocketMine/PHP_7.0.3_x86_Windows.tar.gz";
URL url = new URL(link);
InputStream gz = url.openStream();
GzipCompressorInputStream tar = new GzipCompressorInputStream(gz);
TarArchiveInputStream is = new TarArchiveInputStream(tar);
TarArchiveEntry entry;
while((entry = is.getNextTarEntry()) != null){
if(!entry.isDirectory()){
String name = entry.getName();
byte[] buffer = new byte[(int) entry.getSize()];
IOUtils.read(is, buffer);
File real = new File(home, name);
real.getParentFile().mkdirs();
IOUtils.write(buffer, new FileOutputStream(real));
}
}
File output = new File(home, "bin/php/php.exe");
progress.completed(output);
return output;
}catch(IOException e){
e.printStackTrace();
progress.errored();
return null;
}
}
示例12: read
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* Read from compressed file
*
* @param srcPath
* path of compressed file
* @param fileCompressor
* FileCompressor object
* @throws Exception
*/
@Override
public void read(String srcPath, FileCompressor fileCompressor)
throws Exception {
long t1 = System.currentTimeMillis();
byte[] data = FileUtil.convertFileToByte(srcPath);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
GzipCompressorInputStream cis = new GzipCompressorInputStream(bais);
TarArchiveInputStream ais = new TarArchiveInputStream(cis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
int readByte;
TarArchiveEntry entry = ais.getNextTarEntry();
while (entry != null && entry.getSize() > 0) {
long t2 = System.currentTimeMillis();
baos = new ByteArrayOutputStream();
readByte = ais.read(buffer);
while (readByte != -1) {
baos.write(buffer, 0, readByte);
readByte = ais.read(buffer);
}
BinaryFile binaryFile = new BinaryFile(entry.getName(),
baos.toByteArray());
fileCompressor.addBinaryFile(binaryFile);
LogUtil.createAddFileLog(fileCompressor, binaryFile, t2,
System.currentTimeMillis());
entry = ais.getNextTarEntry();
}
} catch (Exception e) {
FileCompressor.LOGGER.error("Error on get compressor file", e);
} finally {
baos.close();
ais.close();
cis.close();
bais.close();
}
LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1,
System.currentTimeMillis());
}
示例13: read
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* Read from compressed file
*
* @param srcPath
* path of compressed file
* @param fileCompressor
* FileCompressor object
* @throws Exception
*/
@Override
public void read(String srcPath, FileCompressor fileCompressor)
throws Exception {
long t1 = System.currentTimeMillis();
byte[] data = FileUtil.convertFileToByte(srcPath);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
BZip2CompressorInputStream cis = new BZip2CompressorInputStream(bais);
TarArchiveInputStream ais = new TarArchiveInputStream(cis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
int readByte;
TarArchiveEntry entry = ais.getNextTarEntry();
while (entry != null && entry.getSize() > 0) {
long t2 = System.currentTimeMillis();
baos = new ByteArrayOutputStream();
readByte = ais.read(buffer);
while (readByte != -1) {
baos.write(buffer, 0, readByte);
readByte = ais.read(buffer);
}
BinaryFile binaryFile = new BinaryFile(entry.getName(),
baos.toByteArray());
fileCompressor.addBinaryFile(binaryFile);
LogUtil.createAddFileLog(fileCompressor, binaryFile, t2,
System.currentTimeMillis());
entry = ais.getNextTarEntry();
}
} catch (Exception e) {
FileCompressor.LOGGER.error("Error on get compressor file", e);
} finally {
baos.close();
ais.close();
cis.close();
bais.close();
}
LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1,
System.currentTimeMillis());
}
示例14: read
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* Read from compressed file
*
* @param srcPath
* path of compressed file
* @param fileCompressor
* FileCompressor object
* @throws Exception
*/
@Override
public void read(String srcPath, FileCompressor fileCompressor)
throws Exception {
long t1 = System.currentTimeMillis();
byte[] data = FileUtil.convertFileToByte(srcPath);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
TarArchiveInputStream ais = new TarArchiveInputStream(bais);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
int readByte;
TarArchiveEntry entry = ais.getNextTarEntry();
while (entry != null && entry.getSize() > 0) {
long t2 = System.currentTimeMillis();
baos = new ByteArrayOutputStream();
readByte = ais.read(buffer);
while (readByte != -1) {
baos.write(buffer, 0, readByte);
readByte = ais.read(buffer);
}
BinaryFile binaryFile = new BinaryFile(entry.getName(),
baos.toByteArray());
fileCompressor.addBinaryFile(binaryFile);
LogUtil.createAddFileLog(fileCompressor, binaryFile, t2,
System.currentTimeMillis());
entry = ais.getNextTarEntry();
}
} catch (Exception e) {
FileCompressor.LOGGER.error("Error on get compressor file", e);
} finally {
baos.close();
ais.close();
bais.close();
}
LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1,
System.currentTimeMillis());
}
示例15: read
import org.apache.commons.compress.archivers.tar.TarArchiveEntry; //导入方法依赖的package包/类
/**
* Read from compressed file
*
* @param srcPath
* path of compressed file
* @param fileCompressor
* FileCompressor object
* @throws Exception
*/
@Override
public void read(String srcPath, FileCompressor fileCompressor)
throws Exception {
long t1 = System.currentTimeMillis();
byte[] data = FileUtil.convertFileToByte(srcPath);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
XZCompressorInputStream cis = new XZCompressorInputStream(bais);
TarArchiveInputStream ais = new TarArchiveInputStream(cis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
int readByte;
TarArchiveEntry entry = ais.getNextTarEntry();
while (entry != null && entry.getSize() > 0) {
long t2 = System.currentTimeMillis();
baos = new ByteArrayOutputStream();
readByte = ais.read(buffer);
while (readByte != -1) {
baos.write(buffer, 0, readByte);
readByte = ais.read(buffer);
}
BinaryFile binaryFile = new BinaryFile(entry.getName(),
baos.toByteArray());
fileCompressor.addBinaryFile(binaryFile);
LogUtil.createAddFileLog(fileCompressor, binaryFile, t2,
System.currentTimeMillis());
entry = ais.getNextTarEntry();
}
} catch (Exception e) {
FileCompressor.LOGGER.error("Error on get compressor file", e);
} finally {
baos.close();
ais.close();
cis.close();
bais.close();
}
LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1,
System.currentTimeMillis());
}