java tarentry_Java TarEntry類代碼示例

本文汇总了Java中org.apache.tools.tar.TarEntry类的典型用法代码示例,共展示31个示例,默认按受欢迎程度排序。示例涵盖获取输入流、提取文件、设置条目信息等操作,开发者可参考这些示例解决TarEntry类使用问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文整理匯總了Java中org.apache.tools.tar.TarEntry類的典型用法代碼示例。如果您正苦於以下問題:Java TarEntry類的具體用法?Java TarEntry怎麽用?Java TarEntry使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。

TarEntry類屬於org.apache.tools.tar包,在下文中一共展示了TarEntry類的31個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: getInputStream

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

/**

* Return an InputStream for reading the contents of this Resource.

* @return an InputStream object.

* @throws IOException if the tar file cannot be opened,

* or the entry cannot be read.

*/

@Override

public InputStream getInputStream() throws IOException {

if (isReference()) {

return getCheckedRef().getInputStream();

}

Resource archive = getArchive();

final TarInputStream i = new TarInputStream(archive.getInputStream());

TarEntry te;

while ((te = i.getNextEntry()) != null) {

if (te.getName().equals(getName())) {

return i;

}

}

FileUtils.close(i);

throw new BuildException("no entry " + getName() + " in "

+ getArchive());

}

開發者ID:apache,項目名稱:ant,代碼行數:25,

示例2: extractBzip

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

private void extractBzip(File downloadFile)

throws IOException

{

try (FileInputStream inputSkipTwo = new FileInputStream(downloadFile)) {

// see javadoc for CBZip2InputStream

// first two bits need to be skipped

inputSkipTwo.read();

inputSkipTwo.read();

LOG.debug("Extract tar...");

try (TarInputStream tarIn = new TarInputStream(new CBZip2InputStream(inputSkipTwo))) {

for (TarEntry entry = tarIn.getNextEntry(); entry != null; entry = tarIn.getNextEntry()) {

LOG.debug("Extracting {}", entry.getName());

File extractedFile = new File(downloadFile.getParent() + File.separator + entry.getName());

extractEntry(extractedFile, entry.isDirectory(), tarIn);

}

}

}

}

開發者ID:partnet,項目名稱:seauto,代碼行數:21,

示例3: setup

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

/**

* @throws IOException

*/

@Before

public void setup() throws IOException {

hadoopCommand = "-i %s -om %s -ro %s";

final TarInputStream tin = new TarInputStream(new GZIPInputStream(

CorrelationModeTest.class.getResourceAsStream("/org/openimaj/hadoop/tools/twitter/dfidf.out.tar.gz")));

TarEntry entry = null;

output = folder.newFile("results.out");

output.delete();

output.mkdir();

dest = folder.newFile("DFIDF.out");

dest.delete();

dest.mkdir();

while ((entry = tin.getNextEntry()) != null) {

final File tdst = new File(dest.toString(), entry.getName());

if (entry.isDirectory()) {

tdst.mkdir();

} else {

final FileOutputStream fout = new FileOutputStream(tdst);

tin.copyEntryContents(fout);

fout.close();

}

}

tin.close();

}

開發者ID:openimaj,項目名稱:openimaj,代碼行數:29,

示例4: fetchEntry

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

/**

* fetches information from the named entry inside the archive.

*/

@Override

protected void fetchEntry() {

Resource archive = getArchive();

try (TarInputStream i = new TarInputStream(archive.getInputStream())) {

TarEntry te = null;

while ((te = i.getNextEntry()) != null) {

if (te.getName().equals(getName())) {

setEntry(te);

return;

}

}

} catch (IOException e) {

log(e.getMessage(), Project.MSG_DEBUG);

throw new BuildException(e);

}

setEntry(null);

}

開發者ID:apache,項目名稱:ant,代碼行數:21,

示例5: setEntry

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

private void setEntry(TarEntry e) {

if (e == null) {

setExists(false);

return;

}

setName(e.getName());

setExists(true);

setLastModified(e.getModTime().getTime());

setDirectory(e.isDirectory());

setSize(e.getSize());

setMode(e.getMode());

userName = e.getUserName();

groupName = e.getGroupName();

uid = e.getUserId();

gid = e.getGroupId();

}

開發者ID:apache,項目名稱:ant,代碼行數:17,

示例6: expandStream

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

/**

* @since Ant 1.7

*/

private void expandStream(String name, InputStream stream, File dir)

throws IOException {

try (TarInputStream tis = new TarInputStream(

compression.decompress(name, new BufferedInputStream(stream)),

getEncoding())) {

log("Expanding: " + name + " into " + dir, Project.MSG_INFO);

boolean empty = true;

FileNameMapper mapper = getMapper();

TarEntry te;

while ((te = tis.getNextEntry()) != null) {

empty = false;

extractFile(FileUtils.getFileUtils(), null, dir, tis,

te.getName(), te.getModTime(),

te.isDirectory(), mapper);

}

if (empty && getFailOnEmptyArchive()) {

throw new BuildException("archive '%s' is empty", name);

}

log("expand complete", Project.MSG_VERBOSE);

}

}

開發者ID:apache,項目名稱:ant,代碼行數:25,

示例7: getSetPermissionsWorksForTarResources

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

@Test

public void getSetPermissionsWorksForTarResources() throws IOException {

File f = File.createTempFile("ant", ".zip");

f.deleteOnExit();

try (TarOutputStream os = new TarOutputStream(new FileOutputStream(f))) {

TarEntry e = new TarEntry("foo");

os.putNextEntry(e);

os.closeEntry();

}

TarResource r = new TarResource();

r.setName("foo");

r.setArchive(f);

Set s =

EnumSet.of(PosixFilePermission.OWNER_READ,

PosixFilePermission.OWNER_WRITE,

PosixFilePermission.OWNER_EXECUTE,

PosixFilePermission.GROUP_READ);

PermissionUtils.setPermissions(r, s, null);

assertEquals(s, PermissionUtils.getPermissions(r, null));

}

開發者ID:apache,項目名稱:ant,代碼行數:22,

示例8: testPackageSignature

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

@Test

public void testPackageSignature() throws IOException, PackagingException, PGPException, SignatureException, org.bouncycastle.openpgp.PGPException, NoSuchProviderException {

final File debFile = createPackage(ImmutableList.of(

new StringResource("hello world", true, "/tmp/test.txt", USER, USER, TarEntry.DEFAULT_FILE_MODE)

));

final File packageDir = temporaryFolder.newFolder();

ArchiveUtils.extractAr(debFile, packageDir);

final File pgpSignatureFile = new File(packageDir, "_gpgorigin");

assertTrue(pgpSignatureFile.exists());

try (final InputStream keyringIn = PGPUtil.getDecoderStream(PackageBuilderTest.class.getResourceAsStream("public.asc"))) {

try (final InputStream signatureIn = PGPUtil.getDecoderStream(new FileInputStream(pgpSignatureFile))) {

final PGPPublicKey publicKey = ((PGPPublicKeyRing) new BcPGPPublicKeyRingCollection(keyringIn).getKeyRings().next()).getPublicKey();

final PGPSignature signature = ((PGPSignatureList) new BcPGPObjectFactory(signatureIn).nextObject()).get(0);

signature.init(new BcPGPContentVerifierBuilderProvider(), publicKey);

signature.update(Files.asByteSource(new File(packageDir, "debian-binary")).read());

signature.update(Files.asByteSource(new File(packageDir, "control.tar.gz")).read());

signature.update(Files.asByteSource(new File(packageDir, "data.tar.gz")).read());

assertTrue(signature.verify());

}

}

}

開發者ID:reines,項目名稱:dropwizard-debpkg-maven-plugin,代碼行數:27,

示例9: testExpectedControlFiles

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

@Test

public void testExpectedControlFiles() throws IOException, PackagingException {

final File debFile = createPackage(ImmutableList.of(

new StringResource("hello world", true, "/tmp/test.txt", USER, USER, TarEntry.DEFAULT_FILE_MODE)

));

final File packageDir = temporaryFolder.newFolder();

ArchiveUtils.extractAr(debFile, packageDir);

final File controlDir = temporaryFolder.newFolder();

ArchiveUtils.extractTarGzip(new File(packageDir, "control.tar.gz"), controlDir);

for (final String file : ImmutableSet.of(

"control", "conffiles", "preinst", "postinst", "prerm", "postrm")) {

assertTrue(new File(controlDir, file).exists());

}

}

開發者ID:reines,項目名稱:dropwizard-debpkg-maven-plugin,代碼行數:18,

示例10: testTemplatesCorrectlyExecuted

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

@Test

public void testTemplatesCorrectlyExecuted() throws IOException, PackagingException {

final File debFile = createPackage(ImmutableList.of(

new StringResource("hello {{{deb.name}}}", true, "/tmp/test.txt", USER, USER, TarEntry.DEFAULT_FILE_MODE)

));

final File packageDir = temporaryFolder.newFolder();

ArchiveUtils.extractAr(debFile, packageDir);

final File dataDir = temporaryFolder.newFolder();

ArchiveUtils.extractTarGzip(new File(packageDir, "data.tar.gz"), dataDir);

final File testFile = new File(dataDir, "/tmp/test.txt");

assertTrue(testFile.exists());

assertEquals("hello test", Files.asCharSource(testFile, StandardCharsets.UTF_8).read().trim());

}

開發者ID:reines,項目名稱:dropwizard-debpkg-maven-plugin,代碼行數:17,

示例11: testTemplatesNotExecutedWhenNotFiltered

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

@Test

public void testTemplatesNotExecutedWhenNotFiltered() throws IOException, PackagingException {

final File debFile = createPackage(ImmutableList.of(

new StringResource("hello {{{deb.name}}}", false, "/tmp/test.txt", USER, USER, TarEntry.DEFAULT_FILE_MODE)

));

final File packageDir = temporaryFolder.newFolder();

ArchiveUtils.extractAr(debFile, packageDir);

final File dataDir = temporaryFolder.newFolder();

ArchiveUtils.extractTarGzip(new File(packageDir, "data.tar.gz"), dataDir);

final File testFile = new File(dataDir, "/tmp/test.txt");

assertTrue(testFile.exists());

assertEquals("hello {{{deb.name}}}", Files.asCharSource(testFile, StandardCharsets.UTF_8).read().trim());

}

開發者ID:reines,項目名稱:dropwizard-debpkg-maven-plugin,代碼行數:17,

示例12: addControlFile

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

/**

* Add the control file to the tar file.

*/

private void addControlFile (TarOutputStream tar, PackageInfo info, PackageTarFile dataTar)

throws IOException

{

// setup the RFC822 formatted header used for package metadata.

final InternetHeaders headers = info.getControlHeaders();

// add the "Installed-Size" field.

headers.addHeader(INSTALLED_SIZE, String.valueOf(dataTar.getTotalDataSize()));

final StringBuilder controlFile = new StringBuilder();

@SuppressWarnings("unchecked")

final

Enumeration en = headers.getAllHeaderLines();

while (en.hasMoreElements())

{

controlFile.append(en.nextElement()).append('\n');

}

final TarEntry entry = standardEntry(DEB_CONTROL_FILE, UnixStandardPermissions.STANDARD_FILE_MODE, controlFile.length());

tar.putNextEntry(entry);

IOUtils.write(controlFile.toString(), tar);

tar.closeEntry();

}

開發者ID:leplastrier,項目名稱:jpkg-library,代碼行數:27,

示例13: addMaintainerScripts

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

/**

* Add the maintainer scripts to the tar file.

*/

private void addMaintainerScripts (TarOutputStream tar, PackageInfo info)

throws IOException, ScriptDataTooLargeException

{

for (final MaintainerScript script : info.getMaintainerScripts().values()) {

if (script.getSize() > Integer.MAX_VALUE) {

throw new ScriptDataTooLargeException(

"The script data is too large for the tar file. script=[" + script.getType().getFilename() + "].");

}

final TarEntry entry = standardEntry(script.getType().getFilename(), UnixStandardPermissions.EXECUTABLE_FILE_MODE, (int)script.getSize());

tar.putNextEntry(entry);

IOUtils.copy(script.getStream(), tar);

tar.closeEntry();

}

}

開發者ID:leplastrier,項目名稱:jpkg-library,代碼行數:19,

示例14: testAddFileNoStrip

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

@Test

public void testAddFileNoStrip ()

throws Exception

{

final PackageTarFile tar = new PackageTarFile(TestData.TEMP_DIR);

TarInputStream input = null;

try {

tar.addFile(TEST_FILE);

tar.close();

input = getTarInput(tar);

final TarEntry entry = input.getNextEntry();

// verify the header looks correct

assertEquals(PathUtils.stripLeadingSeparators(TEST_FILE.getAbsolutePath()), entry.getName());

// verify there are no more entries in the tar file.

assertNull(input.getNextEntry());

} finally {

tar.delete();

IOUtils.closeQuietly(input);

}

}

開發者ID:leplastrier,項目名稱:jpkg-library,代碼行數:26,

示例15: testTrailingDirectorySlashAdded

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

@Test

public void testTrailingDirectorySlashAdded ()

throws Exception

{

final PackageTarFile tar = new PackageTarFile(TestData.TEMP_DIR);

TarInputStream input = null;

try {

tar.addFile(TEST_DIR, DESTROOT);

tar.close();

input = getTarInput(tar);

final TarEntry entry = input.getNextEntry();

// verify the name has a trailing /

assertEquals("directory/", entry.getName());

// verify there are no more entries in the tar file.

assertNull(input.getNextEntry());

} finally {

tar.delete();

IOUtils.closeQuietly(input);

}

}

開發者ID:leplastrier,項目名稱:jpkg-library,代碼行數:26,

示例16: untar

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

protected void untar (File destDir, InputStream inputStream) throws IOException {

TarInputStream tin = new TarInputStream (inputStream);

TarEntry tarEntry = null;

while ((tarEntry = tin.getNextEntry ()) != null) {

File destEntry = new File (destDir, tarEntry.getName ());

File parent = destEntry.getParentFile ();

if (!parent.exists ()) {

parent.mkdirs ();

}

if (tarEntry.isDirectory ()) {

destEntry.mkdirs ();

} else {

FileOutputStream fout = new FileOutputStream (destEntry);

try {

tin.copyEntryContents (fout);

} finally {

fout.close ();

}

}

}

tin.close ();

}

開發者ID:dfci-cccb,項目名稱:mev,代碼行數:27,

示例17: tarDir

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

protected void tarDir (String relative, File dir, TarOutputStream tos) throws IOException {

File[] files = dir.listFiles ();

for (File file : files) {

if (!file.isHidden ()) {

String path = relative + file.getName ();

if (file.isDirectory ()) {

tarDir (path + File.separator, file, tos);

} else {

TarEntry entry = new TarEntry (path);

entry.setMode (TarEntry.DEFAULT_FILE_MODE);

entry.setSize (file.length ());

entry.setModTime (file.lastModified ());

tos.putNextEntry (entry);

copyFile (file, tos);

tos.closeEntry ();

}

}

}

}

開發者ID:dfci-cccb,項目名稱:mev,代碼行數:25,

示例18: addFile

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

/**

* Adds a file to a tar archive:

* Tar.addFile(filePath, fileName, tarFile);

*

* @param filePath

* @param fileName

* @param tarFile

* @throws IOException

*/

public static void addFile(String filePath, String fileName, org.apache.tools.tar.TarOutputStream tarFile) throws IOException {

// change to the path

// File f = new File(filePath + ".");

// Create a buffer for reading the files

byte[] buf = new byte[2048];

// Compress the file

FileInputStream in = new FileInputStream(filePath + fileName);

// Add tar entry to output stream.

File f = new File(filePath + fileName);

TarEntry entry = new TarEntry(f);

entry.setName(f.getName());

//tarFile.writeEntry(entry, false);

//tarFile.writeEntry(entry, false);

tarFile.putNextEntry(entry);

// Transfer bytes from the file to the tar file

int len;

while ((len = in.read(buf)) > -1) {

//log.debug("len: " + len + " buf: " + buf.toString());

tarFile.write(buf, 0, len);

}

// Complete the entry

tarFile.closeEntry();

in.close();

}

開發者ID:chrisekelley,項目名稱:zeprs,代碼行數:34,

示例19: extractTar

​點讚 3

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

public boolean extractTar() throws IOException {

logger.info("Extract prism archive: "+prismArchive);

InputStream gzStream = prismArchive.openStream();

TarInputStream tarStream = new TarInputStream(new GZIPInputStream(gzStream));

TarEntry tarEntry;

while((tarEntry=tarStream.getNextEntry()) != null) {

File destPath = new File(prismDestinationDir,tarEntry.getName());

if (tarEntry.isDirectory()) {

destPath.mkdir();

continue;

}

FileOutputStream fout = new FileOutputStream(destPath);

tarStream.copyEntryContents(fout);

fout.close();

if(tarEntry.getName().endsWith("install.sh"))

destPath.setExecutable(true);

}

tarStream.close();

gzStream.close();

return true;

}

開發者ID:aciancone,項目名稱:klapersuite,代碼行數:22,

示例20: packMetadata

​點讚 2

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

private void packMetadata(TaskOutputOriginWriter writeMetadata, TarOutputStream outputStream) throws IOException {

TarEntry entry = new TarEntry(METADATA_PATH);

entry.setMode(UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM);

ByteArrayOutputStream baos = new ByteArrayOutputStream();

writeMetadata.execute(baos);

entry.setSize(baos.size());

outputStream.putNextEntry(entry);

try {

outputStream.write(baos.toByteArray());

} finally {

outputStream.closeEntry();

}

}

開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:14,

示例21: storeDirectoryEntry

​點讚 2

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

private void storeDirectoryEntry(FileVisitDetails dirDetails, String propertyRoot, TarOutputStream outputStream) throws IOException {

String path = dirDetails.getRelativePath().getPathString();

TarEntry entry = new TarEntry(propertyRoot + path + "/");

storeModificationTime(entry, dirDetails.getLastModified());

entry.setMode(UnixStat.DIR_FLAG | dirDetails.getMode());

outputStream.putNextEntry(entry);

outputStream.closeEntry();

}

開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:9,

示例22: storeFileEntry

​點讚 2

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

private void storeFileEntry(File file, String path, long lastModified, long size, int mode, TarOutputStream outputStream) throws IOException {

TarEntry entry = new TarEntry(path);

storeModificationTime(entry, lastModified);

entry.setSize(size);

entry.setMode(UnixStat.FILE_FLAG | mode);

outputStream.putNextEntry(entry);

try {

Files.copy(file, outputStream);

} finally {

outputStream.closeEntry();

}

}

開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:13,

示例23: storeModificationTime

​點讚 2

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

private static void storeModificationTime(TarEntry entry, long lastModified) {

// This will be divided by 1000 internally

entry.setModTime(lastModified);

// Store excess nanoseconds in group ID

long excessNanos = TimeUnit.MILLISECONDS.toNanos(lastModified % 1000);

// Store excess nanos as negative number to distinguish real group IDs

entry.setGroupId(-excessNanos);

}

開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:9,

示例24: getModificationTime

​點讚 2

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

private static long getModificationTime(TarEntry entry) {

long lastModified = entry.getModTime().getTime();

long excessNanos = -entry.getLongGroupId();

if (excessNanos < 0 || excessNanos >= NANOS_PER_SECOND) {

throw new IllegalStateException("Invalid excess nanos: " + excessNanos);

}

lastModified += TimeUnit.NANOSECONDS.toMillis(excessNanos);

return lastModified;

}

開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:10,

示例25: visitImpl

​點讚 2

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

private void visitImpl(FileVisitor visitor, InputStream inputStream) throws IOException {

AtomicBoolean stopFlag = new AtomicBoolean();

NoCloseTarInputStream tar = new NoCloseTarInputStream(inputStream);

TarEntry entry;

while (!stopFlag.get() && (entry = tar.getNextEntry()) != null) {

if (entry.isDirectory()) {

visitor.visitDir(new DetailsImpl(entry, tar, stopFlag, chmod));

} else {

visitor.visitFile(new DetailsImpl(entry, tar, stopFlag, chmod));

}

}

}

開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:13,

示例26: visitFile

​點讚 2

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

private void visitFile(FileCopyDetails fileDetails) {

try {

TarEntry archiveEntry = new TarEntry(fileDetails.getRelativePath().getPathString());

archiveEntry.setModTime(fileDetails.getLastModified());

archiveEntry.setSize(fileDetails.getSize());

archiveEntry.setMode(UnixStat.FILE_FLAG | fileDetails.getMode());

tarOutStr.putNextEntry(archiveEntry);

fileDetails.copyTo(tarOutStr);

tarOutStr.closeEntry();

} catch (Exception e) {

throw new GradleException(String.format("Could not add %s to TAR '%s'.", fileDetails, tarFile), e);

}

}

開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:14,

示例27: visitDir

​點讚 2

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

private void visitDir(FileCopyDetails dirDetails) {

try {

// Trailing slash on name indicates entry is a directory

TarEntry archiveEntry = new TarEntry(dirDetails.getRelativePath().getPathString() + '/');

archiveEntry.setModTime(dirDetails.getLastModified());

archiveEntry.setMode(UnixStat.DIR_FLAG | dirDetails.getMode());

tarOutStr.putNextEntry(archiveEntry);

tarOutStr.closeEntry();

} catch (Exception e) {

throw new GradleException(String.format("Could not add %s to TAR '%s'.", dirDetails, tarFile), e);

}

}

開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:13,

示例28: testUnTar

​點讚 2

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

@Test (timeout = 30000)

public void testUnTar() throws IOException {

setupDirs();

// make a simple tar:

final File simpleTar = new File(del, FILE);

OutputStream os = new FileOutputStream(simpleTar);

TarOutputStream tos = new TarOutputStream(os);

try {

TarEntry te = new TarEntry("/bar/foo");

byte[] data = "some-content".getBytes("UTF-8");

te.setSize(data.length);

tos.putNextEntry(te);

tos.write(data);

tos.closeEntry();

tos.flush();

tos.finish();

} finally {

tos.close();

}

// successfully untar it into an existing dir:

FileUtil.unTar(simpleTar, tmp);

// check result:

assertTrue(new File(tmp, "/bar/foo").exists());

assertEquals(12, new File(tmp, "/bar/foo").length());

final File regularFile = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog");

regularFile.createNewFile();

assertTrue(regularFile.exists());

try {

FileUtil.unTar(simpleTar, regularFile);

assertTrue("An IOException expected.", false);

} catch (IOException ioe) {

// okay

}

}

開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:38,

示例29: putNextEntry

​點讚 2

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

/**

* Put an entry on the output stream. This writes the entry's

* header record and positions the output stream for writing

* the contents of the entry. Once this method is called, the

* stream is ready for calls to write() to write the entry's

* contents. Once the contents are written, closeEntry()

* MUST be called to ensure that all buffered data

* is completely written to the output stream.

*

* @param entry The TarEntry to be written to the archive.

* @throws IOException on error

*/

//@Override

public void putNextEntry(TarEntry entry) throws IOException {

if (entry.getName().length() >= TarConstants.NAMELEN) {

if (longFileMode == LONGFILE_GNU) {

// create a TarEntry for the LongLink, the contents

// of which are the entry's name

TarEntry longLinkEntry = new SFRMTarEntry(TarConstants.GNU_LONGLINK,

TarConstants.LF_GNUTYPE_LONGNAME);

// longLinkEntry.setSize(entry.getName().length() + 1);

byte[] nameBytes = entry.getName().getBytes(SFRMTarUtils.NAME_ENCODING);

longLinkEntry.setSize(nameBytes.length + 1);

putNextEntry(longLinkEntry);

// write(entry.getName().getBytes());

write(nameBytes);

write(0);

closeEntry();

} else if (longFileMode != LONGFILE_TRUNCATE) {

throw new RuntimeException("file name '" + entry.getName()

+ "' is too long ( > "

+ TarConstants.NAMELEN + " bytes)");

}

}

entry.writeEntryHeader(this.recordBuf);

this.buffer.writeRecord(this.recordBuf);

this.currBytes = 0;

if (entry.isDirectory()) {

this.currSize = 0;

} else {

this.currSize = entry.getSize();

}

currName = entry.getName();

}

開發者ID:cecid,項目名稱:hermes,代碼行數:51,

示例30: getArchivePath

​點讚 2

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

@Override

public String getArchivePath() {

TarEntry entry = getArchiveEntry();

if(entry==null) return null;

return entry.getName();

}

開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:8,

示例31: createInputStream

​點讚 2

import org.apache.tools.tar.TarEntry; //導入依賴的package包/類

/** Create an InputStream for a TarEntry.

*

The root TarArchiveLocation catalogs every TarEntry,

* so this method provides (very nearly) random access

* to entries.

*/

@Override

public InputStream createInputStream(TarEntry entry) throws IOException {

/* The slow way here would be to create a new TarInputStream

* and iterate over all TarEntries until we identified the

* correct entry and return that input.

*

* ... but since we cataloged this up front, we can skip all that.

*/

EntryLocation loc = archiveEntryToLocation.get(entry.getName());

if(loc==null) throw new IllegalArgumentException("unrecognized tar entry \""+entry.getName()+"\"");

InputStream in = null;

try {

in = root.createInputStream();

MeasuredInputStream measuredIn = new MeasuredInputStream(in);

IOUtils.skipFully(measuredIn, loc.startPtr);

return new GuardedInputStream(measuredIn, loc.length, true);

} catch(IOException e) {

if(in!=null) {

try {

in.close();

} catch(IOException e2) {

e2.printStackTrace();

}

}

throw e;

}

}

開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:34,

注:本文中的org.apache.tools.tar.TarEntry類示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值