svn commit: r750313 - /commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java
Author: bodewig Date: Thu Mar 5 04:49:10 2009 New Revision: 750313 URL: http://svn.apache.org/viewvc?rev=750313&view=rev Log: make tests pass on Linux Modified: commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java Modified: commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java?rev=750313&r1=750312&r2=750313&view=diff == --- commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java (original) +++ commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java Thu Mar 5 04:49:10 2009 @@ -23,8 +23,10 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; +import java.io.IOException; import java.io.OutputStream; import java.lang.reflect.Method; +import java.net.URI; import java.net.URL; import java.net.URLClassLoader; import java.util.Iterator; @@ -51,8 +53,17 @@ addURL(new File("src/test/resources").toURL()); } -protected File getFile(String path) { -return new File(getClass().getClassLoader().getResource(path).getFile()); +protected File getFile(String path) throws IOException { +URL url = getClass().getResource(path); +if (url == null) { +throw new java.io.FileNotFoundException(path + " doesn't exist"); +} +try { +return new File(new URI(url.toString())); +} catch (java.net.URISyntaxException ex) { +// impossible since URL.toString() should always yield a valid URI +throw new IOException(ex.getMessage(), ex); +} } protected void tearDown() throws Exception { @@ -71,11 +82,11 @@ */ public void addURL(URL url) throws Exception { URLClassLoader classLoader = (URLClassLoader) ClassLoader -.getSystemClassLoader(); +.getSystemClassLoader(); Class clazz = URLClassLoader.class; Method method = clazz.getDeclaredMethod("addURL", -new Class[] { URL.class }); +new Class[] { URL.class }); method.setAccessible(true); method.invoke(classLoader, new Object[] { url }); } @@ -109,7 +120,7 @@ final OutputStream stream = new FileOutputStream(temp); out = new ArchiveStreamFactory().createArchiveOutputStream( -archivename, stream); + archivename, stream); final File file1 = getFile("test1.xml"); final File file2 = getFile("test2.xml"); @@ -189,16 +200,16 @@ * @throws Exception */ protected void checkArchiveContent(File archive, List expected) -throws Exception { +throws Exception { final InputStream is = new FileInputStream(archive); final BufferedInputStream buf = new BufferedInputStream(is); final ArchiveInputStream in = new ArchiveStreamFactory() -.createArchiveInputStream(buf); +.createArchiveInputStream(buf); this.checkArchiveContent(in, expected); } protected void checkArchiveContent(ArchiveInputStream in, List expected) -throws Exception { +throws Exception { File result = File.createTempFile("dir-result", ""); result.delete(); result.mkdir(); @@ -206,7 +217,7 @@ ArchiveEntry entry = null; while ((entry = in.getNextEntry()) != null) { File outfile = new File(result.getCanonicalPath() + "/result/" -+ entry.getName()); ++ entry.getName()); outfile.getParentFile().mkdirs(); OutputStream out = new FileOutputStream(outfile); IOUtils.copy(in, out);
svn commit: r750310 - /commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Author: bodewig Date: Thu Mar 5 04:35:32 2009 New Revision: 750310 URL: http://svn.apache.org/viewvc?rev=750310&view=rev Log: ensure the same encoding is used for name and comment in all places. Submitted by Wolfgang Glas Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=750310&r1=750309&r2=750310&view=diff == --- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java (original) +++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java Thu Mar 5 04:35:32 2009 @@ -629,12 +629,16 @@ protected void writeLocalFileHeader(ZipArchiveEntry ze) throws IOException { boolean encodable = zipEncoding.canEncode(ze.getName()); -ByteBuffer name; + +final ZipEncoding entryEncoding; + if (!encodable && fallbackToUTF8) { -name = ZipEncodingHelper.UTF8_ZIP_ENCODING.encode(ze.getName()); +entryEncoding = ZipEncodingHelper.UTF8_ZIP_ENCODING; } else { -name = zipEncoding.encode(ze.getName()); +entryEncoding = zipEncoding; } + +ByteBuffer name = entryEncoding.encode(ze.getName()); if (createUnicodeExtraFields != UnicodeExtraFieldPolicy.NEVER) { @@ -653,7 +657,7 @@ if (createUnicodeExtraFields == UnicodeExtraFieldPolicy.ALWAYS || !commentEncodable) { -ByteBuffer commentB = this.zipEncoding.encode(comm); +ByteBuffer commentB = entryEncoding.encode(comm); ze.addExtraField(new UnicodeCommentExtraField(comm, commentB.array(), commentB.arrayOffset(), @@ -779,12 +783,16 @@ // CheckStyle:MagicNumber ON // file name length -ByteBuffer name; +final ZipEncoding entryEncoding; + if (!encodable && fallbackToUTF8) { -name = ZipEncodingHelper.UTF8_ZIP_ENCODING.encode(ze.getName()); +entryEncoding = ZipEncodingHelper.UTF8_ZIP_ENCODING; } else { -name = zipEncoding.encode(ze.getName()); +entryEncoding = zipEncoding; } + +ByteBuffer name = entryEncoding.encode(ze.getName()); + writeOut(ZipShort.getBytes(name.limit())); written += SHORT; @@ -798,12 +806,9 @@ if (comm == null) { comm = ""; } -ByteBuffer commentB; -if (!encodable && fallbackToUTF8) { -commentB = ZipEncodingHelper.UTF8_ZIP_ENCODING.encode(comm); -} else { -commentB = zipEncoding.encode(comm); -} + +ByteBuffer commentB = entryEncoding.encode(comm); + writeOut(ZipShort.getBytes(commentB.limit())); written += SHORT;
svn commit: r750055 - /commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Author: bodewig Date: Wed Mar 4 15:51:12 2009 New Revision: 750055 URL: http://svn.apache.org/viewvc?rev=750055&view=rev Log: typo Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=750055&r1=750054&r2=750055&view=diff == --- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java (original) +++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java Wed Mar 4 15:51:12 2009 @@ -990,8 +990,8 @@ * Create Unicode extra fields for filenames that cannot be * encoded using the specified encoding. */ -public static final UnicodeExtraFieldPolicy NOT_ENCODABLE = -new UnicodeExtraFieldPolicy("not encodable"); +public static final UnicodeExtraFieldPolicy NOT_ENCODEABLE = +new UnicodeExtraFieldPolicy("not encodeable"); private final String name; private UnicodeExtraFieldPolicy(String n) {