KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > filesystems > PrepareData


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.filesystems;
21
22 import java.io.*;
23 import java.util.jar.JarOutputStream JavaDoc;
24 import java.util.zip.ZipEntry JavaDoc;
25
26
27 public class PrepareData {
28
29     private static void prepareLocalFilesystem( File root, String JavaDoc name, int count, String JavaDoc 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 JavaDoc name, int count, String JavaDoc prefix ) throws IOException {
38         File jar = new File( root, name );
39         FileOutputStream stream = new FileOutputStream( jar );
40         JarOutputStream JavaDoc jarStream = new JarOutputStream JavaDoc( stream );
41         for( int i=0; i<count; i++ ) {
42             jarStream.putNextEntry( new ZipEntry JavaDoc( prefix + i ) );
43             jarStream.closeEntry();
44         }
45         jarStream.close();
46     }
47
48     private static void prepareXmlFilesystem( File root, String JavaDoc name, int count, String JavaDoc 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 JavaDoc[] 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