本文整理匯總了Java中org.apache.commons.compress.archivers.tar.TarArchiveInputStream類的典型用法代碼示例。如果您正苦於以下問題:Java TarArchiveInputStream類的具體用法?Java TarArchiveInputStream怎麽用?Java TarArchiveInputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TarArchiveInputStream類屬於org.apache.commons.compress.archivers.tar包,在下文中一共展示了TarArchiveInputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addDirectory
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
/**
* @deprecated see {@link PLP5ProjectParser#parse(File)}
*/
private static void addDirectory(TarArchiveInputStream plpInputStream,
TarArchiveEntry entry, File assembleFile, List<ASMFile> projectFiles)
throws IOException
{
for (TarArchiveEntry subEntry : entry.getDirectoryEntries())
{
if (!subEntry.isDirectory())
{
addFile(plpInputStream, subEntry, assembleFile, projectFiles);
}
else
{
addDirectory(plpInputStream, subEntry, assembleFile, projectFiles);
}
}
}
示例2: addFile
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的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);
}
}
示例3: readFileFromContainer
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
@Nullable
private byte[] readFileFromContainer(@NonNull final DockerClient _dockerClient,
@NonNull final CreateContainerResponse _container,
@NonNull final String _outputFile) {
final InputStream fileStream =_dockerClient
.copyArchiveFromContainerCmd(_container.getId(), _outputFile)
.exec();
final TarArchiveInputStream tarIn = new TarArchiveInputStream(fileStream);
try {
if (tarIn.getNextEntry() == null) {
log.error("No entry in tar archive");
return null;
}
return IOUtils.toByteArray(tarIn);
} catch (IOException _e) {
log.error("Could not read file from container", _e);
return null;
}
}
示例4: untar
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
public static void untar(InputStream in, File targetDir) throws IOException {
final TarArchiveInputStream tarIn = new TarArchiveInputStream(in);
byte[] b = new byte[BUF_SIZE];
TarArchiveEntry tarEntry;
while ((tarEntry = tarIn.getNextTarEntry()) != null) {
final File file = new File(targetDir, tarEntry.getName());
if (tarEntry.isDirectory()) {
if (!file.mkdirs()) {
throw new IOException("Unable to create folder " + file.getAbsolutePath());
}
} else {
final File parent = file.getParentFile();
if (!parent.exists()) {
if (!parent.mkdirs()) {
throw new IOException("Unable to create folder " + parent.getAbsolutePath());
}
}
try (FileOutputStream fos = new FileOutputStream(file)) {
int r;
while ((r = tarIn.read(b)) != -1) {
fos.write(b, 0, r);
}
}
}
}
}
示例5: extractTar
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
private static void extractTar(String dataIn, String dataOut) throws IOException {
try (TarArchiveInputStream inStream = new TarArchiveInputStream(
new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(dataIn))))) {
TarArchiveEntry tarFile;
while ((tarFile = (TarArchiveEntry) inStream.getNextEntry()) != null) {
if (tarFile.isDirectory()) {
new File(dataOut + tarFile.getName()).mkdirs();
} else {
int count;
byte data[] = new byte[BUFFER_SIZE];
FileOutputStream fileInStream = new FileOutputStream(dataOut + tarFile.getName());
BufferedOutputStream outStream= new BufferedOutputStream(fileInStream, BUFFER_SIZE);
while ((count = inStream.read(data, 0, BUFFER_SIZE)) != -1) {
outStream.write(data, 0, count);
}
}
}
}
}
開發者ID:PacktPublishing,項目名稱:Machine-Learning-End-to-Endguide-for-Java-developers,代碼行數:22,代碼來源:DL4JSentimentAnalysisExample.java
示例6: testToBlob_withCompression
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
@Test
public void testToBlob_withCompression() throws IOException {
Blob blob = testTarStreamBuilder.toBlob();
// Writes the BLOB and captures the output.
ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream();
OutputStream compressorStream = new GZIPOutputStream(tarByteOutputStream);
blob.writeTo(compressorStream);
// Rearrange the output into input for verification.
ByteArrayInputStream byteArrayInputStream =
new ByteArrayInputStream(tarByteOutputStream.toByteArray());
InputStream tarByteInputStream = new GZIPInputStream(byteArrayInputStream);
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(tarByteInputStream);
verifyTarArchive(tarArchiveInputStream);
}
示例7: verifyTarArchive
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
/**
* Helper method to verify that the files were archived correctly by reading {@code
* tarArchiveInputStream}.
*/
private void verifyTarArchive(TarArchiveInputStream tarArchiveInputStream) throws IOException {
// Verifies fileA was archived correctly.
TarArchiveEntry headerFileA = tarArchiveInputStream.getNextTarEntry();
Assert.assertEquals("some/path/to/resourceFileA", headerFileA.getName());
String fileAString =
CharStreams.toString(new InputStreamReader(tarArchiveInputStream, StandardCharsets.UTF_8));
Assert.assertEquals(expectedFileAString, fileAString);
// Verifies fileB was archived correctly.
TarArchiveEntry headerFileB = tarArchiveInputStream.getNextTarEntry();
Assert.assertEquals("crepecake", headerFileB.getName());
String fileBString =
CharStreams.toString(new InputStreamReader(tarArchiveInputStream, StandardCharsets.UTF_8));
Assert.assertEquals(expectedFileBString, fileBString);
// Verifies directoryA was archived correctly.
TarArchiveEntry headerDirectoryA = tarArchiveInputStream.getNextTarEntry();
Assert.assertEquals("some/path/to/", headerDirectoryA.getName());
Assert.assertNull(tarArchiveInputStream.getNextTarEntry());
}
示例8: unTar
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
private boolean unTar(TarArchiveInputStream tarIn, String outputDir) throws IOException {
ArchiveEntry entry;
boolean newFile = false;
while ((entry = tarIn.getNextEntry()) != null) {
File tmpFile = new File(outputDir + "/" + entry.getName());
newFile = tmpFile.createNewFile();
OutputStream out = new FileOutputStream(tmpFile);
int length;
byte[] b = new byte[2048];
while ((length = tarIn.read(b)) != -1)
out.write(b, 0, length);
out.close();
}
tarIn.close();
return newFile;
}
示例9: addTarGzipToArchive
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
/**
* given tar.gz file will be copied to this tar.gz file.
* all files will be transferred to new tar.gz file one by one.
* original directory structure will be kept intact
*
* @param tarGzipFile the archive file to be copied to the new archive
*/
public boolean addTarGzipToArchive(String tarGzipFile) {
try {
// construct input stream
InputStream fin = Files.newInputStream(Paths.get(tarGzipFile));
BufferedInputStream in = new BufferedInputStream(fin);
GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
TarArchiveInputStream tarInputStream = new TarArchiveInputStream(gzIn);
// copy the existing entries from source gzip file
ArchiveEntry nextEntry;
while ((nextEntry = tarInputStream.getNextEntry()) != null) {
tarOutputStream.putArchiveEntry(nextEntry);
IOUtils.copy(tarInputStream, tarOutputStream);
tarOutputStream.closeArchiveEntry();
}
tarInputStream.close();
return true;
} catch (IOException ioe) {
LOG.log(Level.SEVERE, "Archive File can not be added: " + tarGzipFile, ioe);
return false;
}
}
示例10: extract
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
private void extract(File projectFile) throws IOException
{
try (FileInputStream fileStream = new FileInputStream(projectFile);
TarArchiveInputStream inputStream = new TarArchiveInputStream(fileStream))
{
this.inputStream = inputStream;
// TODO: verify the first entry is not relevant
TarArchiveEntry entry = inputStream.getNextTarEntry();
while ((entry = inputStream.getNextTarEntry()) != null)
{
if (!entry.isDirectory())
{
addFile(entry);
}
else
{
addDirectory(entry);
}
}
}
catch (IOException exception)
{
throw exception;
}
}
示例11: initialize
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
@Override
public void initialize(UimaContext context)
throws ResourceInitializationException
{
super.initialize(context);
try {
tarArchiveInputStream = new TarArchiveInputStream(
new GZIPInputStream(new FileInputStream(sourceLocation)));
fastForwardToNextValidEntry();
}
catch (IOException ex) {
throw new ResourceInitializationException(ex);
}
}
示例12: untar
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
public static List<String> untar(FileInputStream input, String targetPath) throws IOException {
TarArchiveInputStream tarInput = new TarArchiveInputStream(input);
ArrayList<String> result = new ArrayList<String>();
ArchiveEntry entry;
while ((entry = tarInput.getNextEntry()) != null) {
File destPath=new File(targetPath,entry.getName());
result.add(destPath.getPath());
if (!entry.isDirectory()) {
FileOutputStream fout=new FileOutputStream(destPath);
final byte[] buffer=new byte[8192];
int n=0;
while (-1 != (n=tarInput.read(buffer))) {
fout.write(buffer,0,n);
}
fout.close();
}
else {
destPath.mkdir();
}
}
tarInput.close();
return result;
}
示例13: dearchive
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
/**
* 文件 解歸檔
*
* @param destFile
* 目標文件
* @param tais
* ZipInputStream
* @throws Exception
*/
private static void dearchive(File destFile, TarArchiveInputStream tais)
throws Exception {
TarArchiveEntry entry = null;
while ((entry = tais.getNextTarEntry()) != null) {
// 文件
String dir = destFile.getPath() + File.separator + entry.getName();
File dirFile = new File(dir);
// 文件檢查
fileProber(dirFile);
if (entry.isDirectory()) {
dirFile.mkdirs();
} else {
dearchiveFile(dirFile, tais);
}
}
}
示例14: unpackTarArchiveEntry
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
public static void unpackTarArchiveEntry(TarArchiveInputStream tarStream, TarArchiveEntry entry, File outputDirectory) throws IOException {
String fileName = entry.getName().substring(entry.getName().indexOf("/"), entry.getName().length());
File outputFile = new File(outputDirectory,fileName);
if (entry.isDirectory()) {
if (!outputFile.exists()) {
if (!outputFile.mkdirs()) {
throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
}
}
unpackTar(tarStream, entry.getDirectoryEntries(), outputFile);
return;
}
OutputStream outputFileStream = new FileOutputStream(outputFile);
IOUtils.copy(tarStream, outputFileStream);
outputFileStream.close();
}
示例15: assertEntry
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; //導入依賴的package包/類
private static void assertEntry(File file, String name) {
boolean exist = false;
try (TarArchiveInputStream tar = new TarArchiveInputStream(
new GzipCompressorInputStream(
new FileInputStream(file)))) {
ArchiveEntry entry;
while ((entry = tar.getNextEntry()) != null) {
if (entry.getName().equals(name)) {
exist = true;
break;
}
}
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
if (!exist) {
fail("zip entry " + name + " not exist!");
}
}