01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.tools.tar;
19:
20: import java.io.IOException;
21: import java.io.ByteArrayInputStream;
22: import java.io.ByteArrayOutputStream;
23: import junit.framework.TestCase;
24:
25: public class TarRoundTripTest extends TestCase {
26:
27: private static final String LONG_NAME = "this/path/name/contains/more/than/one/hundred/characters/in/order/"
28: + "to/test/the/GNU/long/file/name/capability/round/tripped";
29:
30: public TarRoundTripTest(String name) {
31: super (name);
32: }
33:
34: /**
35: * test round-tripping long (GNU) entries
36: */
37: public void testLongRoundTripping() throws IOException {
38: TarEntry original = new TarEntry(LONG_NAME);
39: assertTrue("over 100 chars", LONG_NAME.length() > 100);
40: assertEquals("original name", LONG_NAME, original.getName());
41:
42: ByteArrayOutputStream buff = new ByteArrayOutputStream();
43: TarOutputStream tos = new TarOutputStream(buff);
44: tos.setLongFileMode(TarOutputStream.LONGFILE_GNU);
45: tos.putNextEntry(original);
46: tos.closeEntry();
47: tos.close();
48:
49: TarInputStream tis = new TarInputStream(
50: new ByteArrayInputStream(buff.toByteArray()));
51: TarEntry tripped = tis.getNextEntry();
52: assertEquals("round-tripped name", LONG_NAME, tripped.getName());
53: assertNull("no more entries", tis.getNextEntry());
54: tis.close();
55: }
56: }
|