376
public void testWriteLongDirectoryNameErrorMode() throws Exception {
377
String n = "01234567890123456789012345678901234567890123456789"
378
+ "01234567890123456789012345678901234567890123456789"
379
+ "01234567890123456789012345678901234567890123456789/";
382
TarArchiveEntry t = new TarArchiveEntry(n);
383
ByteArrayOutputStream bos = new ByteArrayOutputStream();
384
TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, "ASCII");
385
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_ERROR);
386
tos.putArchiveEntry(t);
387
tos.closeArchiveEntry();
390
fail("Truncated name didn't throw an exception");
391
} catch (RuntimeException e) {
396
public void testWriteLongDirectoryNameTruncateMode() throws Exception {
397
String n = "01234567890123456789012345678901234567890123456789"
398
+ "01234567890123456789012345678901234567890123456789"
399
+ "01234567890123456789012345678901234567890123456789/";
400
TarArchiveEntry t = new TarArchiveEntry(n);
401
ByteArrayOutputStream bos = new ByteArrayOutputStream();
402
TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, "ASCII");
403
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_TRUNCATE);
404
tos.putArchiveEntry(t);
405
tos.closeArchiveEntry();
407
byte[] data = bos.toByteArray();
408
TarArchiveInputStream tin =
409
new TarArchiveInputStream(new ByteArrayInputStream(data));
410
TarArchiveEntry e = tin.getNextTarEntry();
411
assertEquals("Entry name", n.substring(0, TarConstants.NAMELEN) + "/", e.getName());
412
assertTrue("The entry is not a directory", e.isDirectory());
376
417
* @see "https://issues.apache.org/jira/browse/COMPRESS-203"
472
* @see "https://issues.apache.org/jira/browse/COMPRESS-237"
474
public void testWriteLongLinkNameErrorMode() throws Exception {
475
String linkname = "01234567890123456789012345678901234567890123456789"
476
+ "01234567890123456789012345678901234567890123456789"
477
+ "01234567890123456789012345678901234567890123456789/test";
478
TarArchiveEntry entry = new TarArchiveEntry("test", TarArchiveEntry.LF_SYMLINK);
479
entry.setLinkName(linkname);
482
ByteArrayOutputStream bos = new ByteArrayOutputStream();
483
TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, "ASCII");
484
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_ERROR);
485
tos.putArchiveEntry(entry);
486
tos.closeArchiveEntry();
489
fail("Truncated link name didn't throw an exception");
490
} catch (RuntimeException e) {
495
public void testWriteLongLinkNameTruncateMode() throws Exception {
496
String linkname = "01234567890123456789012345678901234567890123456789"
497
+ "01234567890123456789012345678901234567890123456789"
498
+ "01234567890123456789012345678901234567890123456789/";
499
TarArchiveEntry entry = new TarArchiveEntry("test" , TarArchiveEntry.LF_SYMLINK);
500
entry.setLinkName(linkname);
502
ByteArrayOutputStream bos = new ByteArrayOutputStream();
503
TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, "ASCII");
504
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_TRUNCATE);
505
tos.putArchiveEntry(entry);
506
tos.closeArchiveEntry();
509
byte[] data = bos.toByteArray();
510
TarArchiveInputStream tin = new TarArchiveInputStream(new ByteArrayInputStream(data));
511
TarArchiveEntry e = tin.getNextTarEntry();
512
assertEquals("Link name", linkname.substring(0, TarConstants.NAMELEN), e.getLinkName());
517
* @see "https://issues.apache.org/jira/browse/COMPRESS-237"
519
public void testWriteLongLinkNameGnuMode() throws Exception {
520
testWriteLongLinkName(TarArchiveOutputStream.LONGFILE_GNU);
524
* @see "https://issues.apache.org/jira/browse/COMPRESS-237"
526
public void testWriteLongLinkNamePosixMode() throws Exception {
527
testWriteLongLinkName(TarArchiveOutputStream.LONGFILE_POSIX);
531
* @see "https://issues.apache.org/jira/browse/COMPRESS-237"
533
public void testWriteLongLinkName(int mode) throws Exception {
534
String linkname = "01234567890123456789012345678901234567890123456789"
535
+ "01234567890123456789012345678901234567890123456789"
536
+ "01234567890123456789012345678901234567890123456789/test";
537
TarArchiveEntry entry = new TarArchiveEntry("test", TarArchiveEntry.LF_SYMLINK);
538
entry.setLinkName(linkname);
540
ByteArrayOutputStream bos = new ByteArrayOutputStream();
541
TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, "ASCII");
542
tos.setLongFileMode(mode);
543
tos.putArchiveEntry(entry);
544
tos.closeArchiveEntry();
547
byte[] data = bos.toByteArray();
548
TarArchiveInputStream tin = new TarArchiveInputStream(new ByteArrayInputStream(data));
549
TarArchiveEntry e = tin.getNextTarEntry();
550
assertEquals("Entry name", "test", e.getName());
551
assertEquals("Link name", linkname, e.getLinkName());
552
assertTrue("The entry is not a symbolic link", e.isSymbolicLink());
556
public void testPadsOutputToFullBlockLength() throws Exception {
557
File f = File.createTempFile("commons-compress-padding", ".tar");
559
FileOutputStream fos = new FileOutputStream(f);
560
TarArchiveOutputStream tos = new TarArchiveOutputStream(fos);
561
File file1 = getFile("test1.xml");
562
TarArchiveEntry sEntry = new TarArchiveEntry(file1);
563
tos.putArchiveEntry(sEntry);
564
FileInputStream in = new FileInputStream(file1);
565
IOUtils.copy(in, tos);
567
tos.closeArchiveEntry();
569
// test1.xml is small enough to fit into the default blockv size
570
assertEquals(TarConstants.DEFAULT_BLKSIZE, f.length());