1 19 20 package org.openide.filesystems; 21 22 import java.io.*; 23 import java.util.jar.JarOutputStream ; 24 import java.util.zip.ZipEntry ; 25 26 27 public class PrepareData { 28 29 private static void prepareLocalFilesystem( File root, String name, int count, String prefix ) throws IOException { 30 File subRoot = new File( root, name ); 31 subRoot.mkdir(); 32 for( int i=0; i<count; i++ ) { 33 new File( subRoot, prefix + i ).createNewFile(); 34 } 35 } 36 37 private static void prepareJarFilesystem( File root, String name, int count, String prefix ) throws IOException { 38 File jar = new File( root, name ); 39 FileOutputStream stream = new FileOutputStream( jar ); 40 JarOutputStream jarStream = new JarOutputStream ( stream ); 41 for( int i=0; i<count; i++ ) { 42 jarStream.putNextEntry( new ZipEntry ( prefix + i ) ); 43 jarStream.closeEntry(); 44 } 45 jarStream.close(); 46 } 47 48 private static void prepareXmlFilesystem( File root, String name, int count, String prefix ) throws IOException { 49 File jar = new File( root, name ); 50 FileOutputStream stream = new FileOutputStream( jar ); 51 OutputStreamWriter writer = new OutputStreamWriter( stream, "UTF8" ); 52 PrintWriter print = new PrintWriter( writer ); 53 print.println( 54 "<?xml version=\"1.0\"?>" + 55 "<!DOCTYPE filesystem PUBLIC " + 56 "\"-//NetBeans//DTD Filesystem 1.0//EN\" " + 57 "\"http://www.netbeans.org/dtds/filesystem-1_0.dtd\">\n" + 58 "<filesystem>" 59 ); 60 61 for( int i=0; i<count; i++ ) { 62 print.println( "<file name=\"" + prefix + i + "\"/>" ); 63 } 64 print.println( "</filesystem>" ); 65 print.flush(); 66 print.close(); 67 } 68 69 70 public static void main( String [] args ) throws IOException { 71 File data = new File( "data" ); 72 prepareLocalFilesystem( data, "10", 10, "f" ); 73 prepareLocalFilesystem( data, "100", 100, "f" ); 74 prepareLocalFilesystem( data, "1000", 1000, "f" ); 75 prepareJarFilesystem( data, "flat-10.jar", 10, "f" ); 76 prepareJarFilesystem( data, "flat-100.jar", 100, "f" ); 77 prepareJarFilesystem( data, "flat-1000.jar", 1000, "f" ); 78 prepareXmlFilesystem( data, "flat-10.xml", 10, "f" ); 79 prepareXmlFilesystem( data, "flat-100.xml", 100, "f" ); 80 prepareXmlFilesystem( data, "flat-1000.xml", 1000, "f" ); 81 } 82 83 } | Popular Tags |