On 5 November 2010 19:32, Ralph Goers <ralph.go...@dslextreme.com> wrote: > I added the 3MB file to the test-data directory, so createLargeFile normally > won't run.
Someone complained about adding that amount of test data, so I thought I'd fix it another way. Still safer though not to create a 3GB file ... > Are there any more changes? I'm ready to try the release again. I suggest you wait for the next Continuum build to complete at least. Also, should the code still depend on commons-httpclient 3.0? The current version in the 3.x line is 3.1 Perhaps some other versions need to be adjusted. Certainly JUnit could be updated now we are using 1.5. > > Ralph > > On Nov 5, 2010, at 12:26 PM, s...@apache.org wrote: > >> Author: sebb >> Date: Fri Nov 5 19:26:06 2010 >> New Revision: 1031735 >> >> URL: http://svn.apache.org/viewvc?rev=1031735&view=rev >> Log: >> Eliminate 3GB data file by using PipedI/O Streams >> >> Modified: >> >> commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/tar/test/LargeTarTestCase.java >> >> Modified: >> commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/tar/test/LargeTarTestCase.java >> URL: >> http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/tar/test/LargeTarTestCase.java?rev=1031735&r1=1031734&r2=1031735&view=diff >> ============================================================================== >> --- >> commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/tar/test/LargeTarTestCase.java >> (original) >> +++ >> commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/tar/test/LargeTarTestCase.java >> Fri Nov 5 19:26:06 2010 >> @@ -17,15 +17,16 @@ >> package org.apache.commons.vfs.provider.tar.test; >> >> import java.io.File; >> -import java.io.FileInputStream; >> import java.io.FileOutputStream; >> -import java.io.InputStream; >> import java.io.OutputStream; >> +import java.io.PipedInputStream; >> +import java.io.PipedOutputStream; >> import java.util.Arrays; >> import java.util.Iterator; >> import java.util.List; >> >> import junit.framework.TestCase; >> + >> import org.apache.commons.compress.archivers.ArchiveStreamFactory; >> import org.apache.commons.compress.archivers.tar.TarArchiveEntry; >> import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; >> @@ -58,6 +59,7 @@ public class LargeTarTestCase extends Te >> manager.addProvider("tgz", new TarFileProvider()); >> manager.addProvider("tar", new TarFileProvider()); >> >> + new File(baseDir).mkdir(); // if test is run standalone >> createLargeFile(largeFilePath, largeFileName); >> } >> >> @@ -140,61 +142,66 @@ public class LargeTarTestCase extends Te >> } >> >> //@SuppressWarnings("unused") >> - protected void createLargeFile(String path, String name) throws Exception >> { >> - long _1K = 1024; >> - long _1M = 1024 * _1K; >> - long _256M = 256 * _1M; >> - long _512M = 512 * _1M; >> - long _1G = 1024 * _1M; >> + protected void createLargeFile(String path, final String name) throws >> Exception { >> + final long _1K = 1024; >> + final long _1M = 1024 * _1K; >> +// long _256M = 256 * _1M; >> +// long _512M = 512 * _1M; >> + final long _1G = 1024 * _1M; >> >> // File size of 3 GB >> - long fileSize = 3 * _1G; >> + final long fileSize = 3 * _1G; >> >> File tarGzFile = new File(path + name + ".tar.gz"); >> >> if(!tarGzFile.exists()) { >> - System.out.println("This test is a bit slow. It needs to write a 3GB >> file to your hard drive"); >> - >> - // Create archive >> - OutputStream outTarFileStream = new FileOutputStream(path + name + >> ".tar"); >> - >> - TarArchiveOutputStream outTarStream = (TarArchiveOutputStream)new >> ArchiveStreamFactory() >> - .createArchiveOutputStream(ArchiveStreamFactory.TAR, >> outTarFileStream); >> - >> - // Create archive contents >> - TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(name + ".txt"); >> - tarArchiveEntry.setSize(fileSize); >> - >> - outTarStream.putArchiveEntry(tarArchiveEntry); >> - for(long i = 0; i < fileSize; i++) { >> - outTarStream.write('a'); >> - } >> - >> - outTarStream.closeArchiveEntry(); >> - outTarStream.close(); >> - >> - outTarFileStream.close(); >> + System.out.println("This test is a bit slow. It needs to write 3GB of >> data as a compressed file (approx. 3MB) to your hard drive"); >> >> + final PipedOutputStream outTarFileStream = new PipedOutputStream(); >> + PipedInputStream inTarFileStream = new >> PipedInputStream(outTarFileStream); >> + >> + Thread source = new Thread(){ >> + >> + public void run() { >> + byte ba_1k[] = new byte[(int) _1K]; >> + for(int i=0; i < ba_1k.length; i++){ >> + ba_1k[i]='a'; >> + } >> + try { >> + TarArchiveOutputStream outTarStream = >> + (TarArchiveOutputStream)new ArchiveStreamFactory() >> + .createArchiveOutputStream(ArchiveStreamFactory.TAR, >> outTarFileStream); >> + // Create archive contents >> + TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(name >> + ".txt"); >> + tarArchiveEntry.setSize(fileSize); >> + >> + outTarStream.putArchiveEntry(tarArchiveEntry); >> + for(long i = 0; i < fileSize; i+= ba_1k.length) { >> + outTarStream.write(ba_1k); >> + } >> + outTarStream.closeArchiveEntry(); >> + outTarStream.close(); >> + outTarFileStream.close(); >> + } catch (Exception e) { >> + e.printStackTrace(); >> + } >> + } >> + >> + }; >> + source.start(); >> + >> // Create compressed archive >> OutputStream outGzipFileStream = new FileOutputStream(path + name + >> ".tar.gz"); >> >> GzipCompressorOutputStream outGzipStream = >> (GzipCompressorOutputStream)new CompressorStreamFactory() >> .createCompressorOutputStream(CompressorStreamFactory.GZIP, >> outGzipFileStream); >> >> - // Compress archive >> - InputStream inTarFileStream = new FileInputStream(path + name + >> ".tar"); >> - // TODO: Change to a Piped Stream to conserve disk space >> IOUtils.copy(inTarFileStream, outGzipStream); >> inTarFileStream.close(); >> >> outGzipStream.close(); >> outGzipFileStream.close(); >> >> - // Cleanup original tar >> - File tarFile = new File(path + name + ".tar"); >> - if(tarFile.exists()) { >> - tarFile.delete(); >> - } >> } >> } >> } >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org