KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > retouche > source > parsing > FileObjects


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.netbeans.modules.retouche.source.parsing;
21
22
23 import java.io.ByteArrayInputStream JavaDoc;
24 import java.io.ByteArrayOutputStream JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.FileInputStream JavaDoc;
27 import java.io.FileOutputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.io.InputStreamReader JavaDoc;
31 import java.io.OutputStream JavaDoc;
32 import java.io.OutputStreamWriter JavaDoc;
33 import java.io.Reader JavaDoc;
34 import java.io.Writer JavaDoc;
35 import java.net.MalformedURLException JavaDoc;
36 import java.net.URI JavaDoc;
37 import java.net.URL JavaDoc;
38 import java.nio.CharBuffer JavaDoc;
39 import java.util.Comparator JavaDoc;
40 import java.util.zip.ZipEntry JavaDoc;
41 import java.util.zip.ZipFile JavaDoc;
42 import org.netbeans.api.gsf.ParserFile;
43 import org.netbeans.api.gsf.ParserFile;
44 import org.openide.filesystems.FileObject;
45 import org.openide.filesystems.FileUtil;
46 import org.openide.filesystems.FileUtil;
47 import org.openide.util.NbBundle;
48 import org.openide.util.Utilities;
49
50 /** Creates various kinds of file objects
51  * This file is originally from Retouche, the Java Support
52  * infrastructure in NetBeans. I have modified the file as little
53  * as possible to make merging Retouche fixes back as simple as
54  * possible.
55  *
56 * I've ripped out a bunch of stuff here
57  *
58  * XXX - Rename to JavaFileObjects
59  *
60  * @author Petr Hrebejk
61  */

62 public class FileObjects {
63     
64     public static final Comparator JavaDoc<String JavaDoc> SIMPLE_NAME_STRING_COMPARATOR = new SimpleNameStringComparator();
65     public static final Comparator JavaDoc<FileObject> SIMPLE_NAME_FILEOBJECT_COMPARATOR = new SimpleNameFileObjectComparator();
66     
67     
68 // public static final String JAVA = JavaDataLoader.JAVA_EXTENSION;
69
// public static final String CLASS = ClassDataLoader.CLASS_EXTENSION;
70
// public static final String JAR = "jar"; //NOI18N
71
// public static final String ZIP = "zip"; //NOI18N
72
public static final String JavaDoc HTML = "html"; //NOI18N
73
public static final String JavaDoc SIG = "sig"; //NOI18N
74
public static final String JavaDoc RS = "rs"; //NOI18N
75

76     
77     /** Creates a new instance of FileObjects */
78     private FileObjects() {
79     }
80     
81     // Public methods ----------------------------------------------------------
82

83     
84     
85 // /**
86
// * Creates {@link JavaFileObject} for a ZIP entry of given name
87
// * @param zip a zip file
88
// * @param name the name of entry, the '/' char is a separator
89
// * @return {@link JavaFileObject}, never returns null
90
// */
91
// public static JavaFileObject zipFileObject( File zipFile, String folder, String baseName, long mtime) {
92
// assert zipFile != null;
93
// return new ZipFileObject( zipFile, folder, baseName, mtime);
94
// }
95
//
96
// public static JavaFileObject zipFileObject(ZipFile zipFile, String folder, String baseName, long mtime) {
97
// assert zipFile != null;
98
// return new CachedZipFileObject (zipFile, folder, baseName, mtime);
99
// }
100
//
101
// /**
102
// * Creates {@link JavaFileObject} for a regular {@link File}
103
// * @param file for which the {@link JavaFileObject} should be created
104
// * @pram root - the classpath root owning the file
105
// * @return {@link JavaFileObject}, never returns null
106
// */
107
// public static JavaFileObject fileFileObject( final File file, final File root, final JavaFileFilterImplementation filter) {
108
// assert file != null;
109
// assert root != null;
110
// String[] pkgNamePair = getFolderAndBaseName(getRelativePath(root,file),File.separatorChar);
111
// return new RegularFileObject( file, convertFolder2Package(pkgNamePair[0], File.separatorChar), pkgNamePair[1], filter);
112
// }
113
// public static /*Java*/FileObject fileFileObject( final File file, final File root, Object/* final JavaFileFilterImplementation*/ filter) {
114
// assert file != null;
115
// assert root != null;
116
// // Ugh this is a performance KILLER
117
// return FileUtil.toFileObject(file); // XXX consider root?
118
// }
119

120     public static ParserFile fileFileObject( final File JavaDoc file, final File JavaDoc root, boolean platform, Object JavaDoc/* final JavaFileFilterImplementation*/ filter) {
121         assert file != null;
122         assert root != null;
123         return new FileParserFile(file, root, platform);
124     }
125     
126     private static class FileParserFile implements ParserFile {
127         private File JavaDoc file;
128         private File JavaDoc root;
129         private FileObject fileObject;
130         private String JavaDoc relative;
131         private boolean platform;
132         
133         private FileParserFile(File JavaDoc file, File JavaDoc root, boolean platform) {
134             this.file = file;
135             this.root = root;
136             this.platform = platform;
137         }
138         
139         public FileObject getFileObject() {
140             if (fileObject == null) {
141                 fileObject = FileUtil.toFileObject(file);
142             }
143             return fileObject;
144         }
145
146         public String JavaDoc getRelativePath() {
147             if (relative == null) {
148                 relative = FileObjects.getRelativePath(root, file);
149             }
150             
151             return relative;
152         }
153     
154         public String JavaDoc getNameExt() {
155             return file.getName();
156         }
157
158         public String JavaDoc getExtension() {
159             String JavaDoc name = file.getName();
160             int index = name.lastIndexOf('.');
161             if (index != -1) {
162                 return name.substring(index+1);
163             } else {
164                 return "";
165             }
166         }
167         
168         public String JavaDoc toString() {
169             return "FileParserFile(" + getNameExt() + ")";
170         }
171     
172         public boolean isPlatform() {
173             return platform;
174         }
175 }
176     
177     //
178
// /**
179
// * Creates {@link JavaFileObject} for a NetBeans {@link FileObject}
180
// * Any client which needs to create {@link JavaFileObject} for java
181
// * source file should use this factory method.
182
// * @param {@link FileObject} for which the {@link JavaFileObject} should be created
183
// * @return {@link JavaFileObject}, never returns null
184
// * @exception {@link IOException} may be thrown
185
// */
186
// public static /*Java*/FileObject nbFileObject (final FileObject file) throws IOException {
187
// return nbFileObject (file, null, false);
188
// }
189
//
190
// /**
191
// * Creates {@link JavaFileObject} for a NetBeans {@link FileObject}
192
// * Any client which needs to create {@link JavaFileObject} for java
193
// * source file should use this factory method.
194
// * @param {@link FileObject} for which the {@link JavaFileObject} should be created
195
// * @param renderNow if true the snap shot of the file is taken immediately
196
// * @return {@link JavaFileObject}, never returns null
197
// * @exception {@link IOException} may be thrown
198
// */
199
// public static /*Java*/FileObject nbFileObject (final FileObject file, JavaFileFilterImplementation filter, boolean renderNow) throws IOException {
200
// assert file != null;
201
// if (!file.isValid() || file.isVirtual()) {
202
// throw new InvalidFileException (file);
203
// }
204
// return new SourceFileObject (file, filter, renderNow);
205
// }
206
//
207
// /**
208
// * Creates virtual {@link JavaFileObject} with given name and content.
209
// * This method should be used only by tests, regular client should never
210
// * use this method.
211
// * @param content the content of the {@link JavaFileObject}
212
// * @param name the name of the {@link JavaFileObject}
213
// * @return {@link JavaFileObject}, never returns null
214
// */
215
// public static JavaFileObject memoryFileObject( CharSequence content, CharSequence name ) {
216
// final String nameStr = name.toString();
217
// if (!nameStr.equals(getBaseName(nameStr))) {
218
// throw new IllegalArgumentException ("Memory is flat"); //NOI18N
219
// }
220
// int length = content.length();
221
// if ( length != 0 && Character.isWhitespace( content.charAt( length - 1 ) ) ) {
222
// return new MemoryFileObject( nameStr, CharBuffer.wrap( content ) );
223
// }
224
// else {
225
// return new MemoryFileObject( nameStr, (CharBuffer)CharBuffer.allocate( length + 1 ).append( content ).append( ' ' ).flip() );
226
// }
227
//
228
// }
229

230     public static String JavaDoc stripExtension( String JavaDoc fileName ) {
231         int dot = fileName.lastIndexOf(".");
232         return (dot == -1 ? fileName : fileName.substring(0, dot));
233     }
234     
235     
236 // /**
237
// * Returns the name of JavaFileObject, similar to
238
// * {@link java.io.File#getName}
239
// */
240
// public static String getName (final JavaFileObject fo, final boolean noExt) {
241
// assert fo != null;
242
// if (fo instanceof Base) {
243
// Base baseFileObject = (Base) fo;
244
// if (noExt) {
245
// return baseFileObject.getName();
246
// }
247
// else {
248
// StringBuilder sb = new StringBuilder ();
249
// sb.append (baseFileObject.getName());
250
// sb.append('.'); //NOI18N
251
// sb.append(baseFileObject.getExt());
252
// return sb.toString();
253
// }
254
// }
255
// try {
256
// final URL url = fo.toUri().toURL();
257
// String path = url.getPath();
258
// int index1 = path.lastIndexOf('/');
259
// int len;
260
// if (noExt) {
261
// final int index2 = path.lastIndexOf('.');
262
// if (index2>index1) {
263
// len = index2;
264
// }
265
// else {
266
// len = path.length();
267
// }
268
// }
269
// else {
270
// len = path.length();
271
// }
272
// path = path.substring(index1+1,len);
273
// return path;
274
// } catch (MalformedURLException e) {
275
// return null;
276
// }
277
// }
278
/**
279      * Returns the name of JavaFileObject, similar to
280      * {@link java.io.File#getName}
281      */

282     public static String JavaDoc getName (final /*Java*/FileObject fo, final boolean noExt) {
283         assert fo != null;
284         return noExt ? fo.getName() : fo.getNameExt();
285     }
286         
287     
288     /**
289      * Returns the basename name without folder path
290      * @param file name, eg. obtained from {@link FileObjects#getPath} or {java.io.File.getPath}
291      * @return the base name
292      * @see #getBaseName(String,char)
293      */

294     public static String JavaDoc getBaseName( String JavaDoc fileName ) {
295         return getBaseName(fileName, File.separatorChar);
296     }
297     
298     /**
299      * Returns the basename name without folder path. You can specify
300      * the path separator since eg zip files uses '/' regardless of platform.
301      * @param file name, eg. obtained from {@link FileObjects#getPath} or {java.io.File.getPath}
302      * @param separator path separator
303      * @return the base name
304      */

305     public static String JavaDoc getBaseName( String JavaDoc fileName, char separator ) {
306         return getFolderAndBaseName(fileName, separator)[1];
307     }
308     
309     
310     /**
311      *Returns the folder (package name separated by original separators)
312      *and base name.
313      * @param path
314      * @return array of 2 strings, 1st the folder 2nd the base name
315      */

316     public static String JavaDoc[] getFolderAndBaseName (final String JavaDoc fileName, final char separator) {
317         final int i = fileName.lastIndexOf( separator );
318         if ( i == -1 ) {
319             return new String JavaDoc[] {"",fileName}; //NOI18N
320
}
321         else {
322             return new String JavaDoc[] {
323                 fileName.substring(0,i),
324                 fileName.substring( i + 1 )
325             };
326         }
327     }
328                 
329     public static String JavaDoc getBinaryName (final File JavaDoc file, final File JavaDoc root) {
330         assert file != null && root != null;
331         String JavaDoc fileName = FileObjects.getRelativePath (root, file);
332         int index = fileName.lastIndexOf('.'); //NOI18N
333
if (index > 0) {
334             fileName = fileName.substring(0,index);
335         }
336         return fileName.replace(File.separatorChar,'.'); //NOI18N
337
}
338     
339     public static String JavaDoc getSimpleName( /*Java*/FileObject fo ) {
340         
341         String JavaDoc name = getName(fo,true);
342         int i = name.lastIndexOf( '$' );
343         if ( i == -1 ) {
344             return name;
345         }
346         else {
347             return name.substring( i + 1 );
348         }
349     }
350     
351     public static String JavaDoc getSimpleName( String JavaDoc fileName ) {
352         
353         String JavaDoc name = getBaseName( fileName );
354         
355         int i = name.lastIndexOf( '$' );
356         if ( i == -1 ) {
357             return name;
358         }
359         else {
360             return name.substring( i + 1 );
361         }
362         
363     }
364     
365     public static String JavaDoc convertPackage2Folder( String JavaDoc packageName ) {
366         return packageName.replace( '.', '/' );
367     }
368     
369     
370     public static String JavaDoc convertFolder2Package (String JavaDoc packageName) {
371         return convertFolder2Package (packageName, '/'); //NOI18N
372
}
373     
374     public static String JavaDoc convertFolder2Package( String JavaDoc packageName, char folderSeparator ) {
375         return packageName.replace( folderSeparator, '.' );
376     }
377     
378     
379     public static String JavaDoc getRelativePath (final String JavaDoc packageName, final String JavaDoc relativeName) {
380         StringBuilder JavaDoc relativePath = new StringBuilder JavaDoc ();
381         relativePath.append(packageName.replace('.','/'));
382         relativePath.append(relativeName);
383         return relativePath.toString();
384     }
385     
386     public static String JavaDoc[] getParentRelativePathAndName (final String JavaDoc className) {
387         if (className.charAt(className.length()-1) == '.') {
388             return null;
389         }
390         final int index = className.lastIndexOf('.');
391         if (index<0) {
392             return new String JavaDoc[] {
393                 "", //NOI18N
394
className
395             };
396         }
397         else {
398             return new String JavaDoc[] {
399                 className.substring(0,index).replace('.','/'), //NOI18N
400
className.substring(index+1)
401             };
402         }
403     }
404     
405     
406     public static File JavaDoc getRootFile (final URL JavaDoc url) {
407         File JavaDoc rootFile;
408         if ("jar".equals(url.getProtocol())) { //NOI18N
409
rootFile = new File JavaDoc (URI.create(FileUtil.getArchiveFile(url).toExternalForm()));
410         }
411         else {
412             rootFile = new File JavaDoc (URI.create(url.toExternalForm()));
413         }
414         return rootFile;
415     }
416     
417     
418     // Private methods ---------------------------------------------------------
419

420     // Innerclasses ------------------------------------------------------------
421

422 // public static abstract class Base implements JavaFileObject {
423
//
424
// protected final JavaFileObject.Kind kind;
425
// protected final String pkgName;
426
// protected final String nameWithoutExt;
427
// protected final String ext;
428
//
429
// protected Base (final String pkgName, final String name) {
430
// assert pkgName != null;
431
// assert name != null;
432
// this.pkgName = pkgName;
433
// String[] res = getNameExtPair(name);
434
// this.nameWithoutExt = res[0];
435
// this.ext = res[1];
436
// if (FileObjects.JAVA.equalsIgnoreCase(ext)) { //NOI18N
437
// this.kind = Kind.SOURCE;
438
// }
439
// else if (FileObjects.CLASS.equalsIgnoreCase(ext) || "sig".equals(ext)) { //NOI18N
440
// this.kind = Kind.CLASS;
441
// }
442
// else if (FileObjects.HTML.equalsIgnoreCase(ext)) { //NOI18N
443
// this.kind = Kind.HTML;
444
// }
445
// else {
446
// this.kind = Kind.OTHER;
447
// }
448
// }
449
//
450
// public JavaFileObject.Kind getKind() {
451
// return this.kind;
452
// }
453
//
454
// public boolean isNameCompatible (String simplename, JavaFileObject.Kind k) {
455
// if (this.kind != k) {
456
// return false;
457
// }
458
// return nameWithoutExt.equals(simplename);
459
// }
460
//
461
// public NestingKind getNestingKind() {
462
// return null;
463
// }
464
//
465
// public Modifier getAccessLevel() {
466
// return null;
467
// }
468
//
469
// @Override
470
// public String toString() {
471
// return this.toUri().toString();
472
// }
473
//
474
// public String getPackage () {
475
// return this.pkgName;
476
// }
477
//
478
// public String getNameWithoutExtension () {
479
// return this.nameWithoutExt;
480
// }
481
//
482
// public String getName () {
483
// return this.nameWithoutExt + '.' + ext;
484
// }
485
//
486
// public String getExt () {
487
// return this.ext;
488
// }
489
//
490
// private static String[] getNameExtPair (String name) {
491
// int index = name.lastIndexOf ('.');
492
// String namenx;
493
// String ext;
494
// if (index <= 0) {
495
// namenx =name;
496
// ext = ""; //NOI18N
497
// }
498
// else {
499
// namenx = name.substring(0,index);
500
// if (index == name.length()-1) {
501
// ext = "";
502
// }
503
// else {
504
// ext = name.substring(index+1);
505
// }
506
// }
507
// return new String[] {
508
// namenx,
509
// ext
510
// };
511
// }
512
// }
513
//
514
// public static abstract class FileBase extends Base {
515
//
516
// protected final File f;
517
//
518
// protected FileBase (final File file, final String pkgName, final String name) {
519
// super (pkgName, name);
520
// assert file != null;
521
// assert file.equals(FileUtil.normalizeFile(file));
522
// this.f = file;
523
// }
524
//
525
// public File getFile () {
526
// return this.f;
527
// }
528
// }
529

530     
531     public static class InvalidFileException extends IOException JavaDoc {
532         
533         public InvalidFileException () {
534             super ();
535         }
536         
537         public InvalidFileException (final FileObject fo) {
538             super (NbBundle.getMessage(FileObjects.class,"FMT_InvalidFile",FileUtil.getFileDisplayName(fo)));
539         }
540     }
541     
542     
543     public static String JavaDoc getRelativePath (final File JavaDoc root, final File JavaDoc fo) {
544         final String JavaDoc rootPath = root.getAbsolutePath();
545         final String JavaDoc foPath = fo.getAbsolutePath();
546         assert foPath.startsWith(rootPath);
547         int index = rootPath.length();
548         if (rootPath.charAt(index-1)!=File.separatorChar) {
549             index++;
550         }
551         int foIndex = foPath.length();
552         if (foIndex <= index) {
553             return ""; //NOI18N
554
}
555         return foPath.substring(index);
556     }
557 //
558
// private static class RegularFileObject extends FileBase {
559
//
560
// private URI uriCache;
561
// private final JavaFileFilterImplementation filter;
562
//
563
// public RegularFileObject(final File f, final String packageName, final String baseName, final JavaFileFilterImplementation filter) {
564
// super (f, packageName, baseName);
565
// this.filter = filter;
566
// }
567
//
568
// public InputStream openInputStream() throws IOException {
569
// return new FileInputStream(f);
570
// }
571
//
572
// public Reader openReader (boolean b) throws IOException {
573
// throw new UnsupportedOperationException();
574
// }
575
//
576
// public OutputStream openOutputStream() throws IOException {
577
// return new FileOutputStream(f);
578
// }
579
//
580
// public Writer openWriter() throws IOException {
581
// //FIX: consider using encoding here
582
// return new OutputStreamWriter(new FileOutputStream(f));
583
// }
584
//
585
// public @Override boolean isNameCompatible(String simplename, JavaFileObject.Kind kind) {
586
// boolean res = super.isNameCompatible(simplename, kind);
587
// if (res) {
588
// return res;
589
// }
590
// else if (Utilities.isWindows()) {
591
// return nameWithoutExt.equalsIgnoreCase(simplename);
592
// }
593
// else {
594
// return false;
595
// }
596
// }
597
//
598
// public URI toUri () {
599
// if (this.uriCache == null) {
600
// this.uriCache = f.toURI();
601
// }
602
// return this.uriCache;
603
// }
604
//
605
// public long getLastModified() {
606
// return f.lastModified();
607
// }
608
//
609
// public boolean delete() {
610
// return f.delete();
611
// }
612
//
613
// public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
614
//
615
// char[] result;
616
// InputStreamReader in = new InputStreamReader (new FileInputStream(this.f), encodingName);
617
// try {
618
// int len = (int)this.f.length();
619
// result = new char [len+1];
620
// int red = 0, rv;
621
// while ((rv=in.read(result,red,len-red))>0 && (red=red+rv)<len);
622
// } finally {
623
// in.close();
624
// }
625
// result[result.length-1]='\n'; //NOI18N
626
// CharSequence buffer = CharBuffer.wrap (result);
627
// if (this.filter != null) {
628
// buffer = this.filter.filterCharSequence(buffer);
629
// }
630
// return buffer;
631
// }
632
//
633
// @Override
634
// public boolean equals(Object other) {
635
// if (!(other instanceof RegularFileObject))
636
// return false;
637
// RegularFileObject o = (RegularFileObject) other;
638
// return f.equals(o.f);
639
// }
640
//
641
// @Override
642
// public int hashCode() {
643
// return f.hashCode();
644
// }
645
//
646
// }
647
//
648
// /** A subclass of FileObject representing zip entries.
649
// * XXX: What happens when the archive is deleted or rebuilt?
650
// */
651
// private abstract static class ZipFileBase extends Base {
652
//
653
// protected final long mtime;
654
// protected final String resName;
655
//
656
// public ZipFileBase (final String folderName, final String baseName, long mtime) {
657
// super (convertFolder2Package(folderName),baseName);
658
// this.mtime = mtime;
659
// if (folderName.length() == 0) {
660
// this.resName = baseName;
661
// }
662
// else {
663
// StringBuilder resName = new StringBuilder (folderName);
664
// resName.append('/'); //NOI18N
665
// resName.append(baseName);
666
// this.resName = resName.toString();
667
// }
668
// }
669
//
670
// public OutputStream openOutputStream() throws IOException {
671
// throw new UnsupportedOperationException();
672
// }
673
//
674
// public Reader openReader(boolean b) throws IOException {
675
// throw new UnsupportedOperationException();
676
// }
677
//
678
// public Writer openWriter() throws IOException {
679
// throw new UnsupportedOperationException();
680
// }
681
//
682
// public long getLastModified() {
683
// return mtime;
684
// }
685
//
686
// public boolean delete() {
687
// throw new UnsupportedOperationException();
688
// }
689
//
690
// public CharBuffer getCharContent(boolean ignoreEncodingErrors) {
691
// throw new UnsupportedOperationException();
692
// }
693
//
694
// public final URI toUri () {
695
// URI zdirURI = this.getArchiveURI();
696
// return URI.create ("jar:"+zdirURI.toString()+"!/"+resName); //NOI18N
697
// }
698
//
699
// @Override
700
// public int hashCode() {
701
// return this.resName.hashCode();
702
// }
703
//
704
// @Override
705
// public boolean equals(Object other) {
706
// if (!(other instanceof ZipFileBase))
707
// return false;
708
// ZipFileBase o = (ZipFileBase) other;
709
// return getArchiveURI().equals(o.getArchiveURI()) && resName.equals(o.resName);
710
// }
711
//
712
// protected abstract URI getArchiveURI ();
713
//
714
// }
715
//
716
// private static class ZipFileObject extends ZipFileBase {
717
//
718
//
719
// /** The zipfile containing the entry.
720
// */
721
// private final File archiveFile;
722
//
723
//
724
// ZipFileObject(final File archiveFile, final String folderName, final String baseName, long mtime) {
725
// super (folderName,baseName,mtime);
726
// assert archiveFile != null : "archiveFile == null"; //NOI18N
727
// this.archiveFile = archiveFile;
728
//
729
// }
730
//
731
// public InputStream openInputStream() throws IOException {
732
// class ZipInputStream extends InputStream {
733
//
734
// private ZipFile zipfile;
735
// private InputStream delegate;
736
//
737
// public ZipInputStream (ZipFile zf) throws IOException {
738
// this.zipfile = zf;
739
// this.delegate = zf.getInputStream(new ZipEntry(resName));
740
// }
741
//
742
// public int read() throws IOException {
743
// throw new java.lang.UnsupportedOperationException("Not supported yet.");
744
// }
745
//
746
// public int read(byte b[], int off, int len) throws IOException {
747
// return delegate.read(b, off, len);
748
// }
749
//
750
// public int available() throws IOException {
751
// return this.delegate.available();
752
// }
753
//
754
// public void close() throws IOException {
755
// try {
756
// this.delegate.close();
757
// } finally {
758
// this.zipfile.close();
759
// }
760
// }
761
//
762
//
763
// };
764
// ZipFile zf = new ZipFile (archiveFile);
765
// return new ZipInputStream (zf);
766
// }
767
//
768
// public URI getArchiveURI () {
769
// return this.archiveFile.toURI();
770
// }
771
// }
772
//
773
// private static class CachedZipFileObject extends ZipFileBase {
774
//
775
// private ZipFile zipFile;
776
//
777
// CachedZipFileObject(final ZipFile zipFile, final String folderName, final String baseName, long mtime) {
778
// super (folderName,baseName,mtime);
779
// assert zipFile != null : "archiveFile == null"; //NOI18N
780
// this.zipFile = zipFile;
781
// }
782
//
783
// public InputStream openInputStream() throws IOException {
784
// return this.zipFile.getInputStream(new ZipEntry (this.resName));
785
// }
786
//
787
// public URI getArchiveURI () {
788
// return new File (this.zipFile.getName()).toURI();
789
// }
790
// }
791
//
792
//
793
// /** Temporay FileObject for parsing input stream.
794
// */
795
// private static class MemoryFileObject extends Base {
796
//
797
// private String fileName;
798
// private CharBuffer cb;
799
//
800
// public MemoryFileObject( String fileName, CharBuffer cb ) {
801
// super ("",fileName); //NOI18N
802
// this.cb = cb;
803
// this.fileName = fileName;
804
// }
805
//
806
//
807
// /**
808
// * Get the character content of the file, if available.
809
// * @param ignoreEncodingErrors if true, encoding errros will be replaced by the
810
// * default translation character; otherwise they should be reported as diagnostics.
811
// * @throws UnsupportedOperationException if character access is not supported
812
// */
813
// public java.nio.CharBuffer getCharContent(boolean ignoreEncodingErrors) throws java.io.IOException {
814
// return cb;
815
// }
816
//
817
// public boolean delete() {
818
// // Do nothing
819
// return false;
820
// }
821
//
822
// public URI toUri () {
823
// return URI.create (this.nameWithoutExt);
824
// }
825
//
826
// public long getLastModified() {
827
// return System.currentTimeMillis(); // XXX
828
// }
829
//
830
// /**
831
// * Get an InputStream for this object.
832
// *
833
// * @return an InputStream for this object.
834
// * @throws UnsupportedOperationException if the byte access is not supported
835
// */
836
// public InputStream openInputStream() throws java.io.IOException {
837
// return new ByteArrayInputStream(cb.toString().getBytes("UTF-8"));
838
// }
839
//
840
// /**
841
// * Get an OutputStream for this object.
842
// *
843
// * @return an OutputStream for this object.
844
// * @throws UnsupportedOperationException if byte access is not supported
845
// */
846
// public java.io.OutputStream openOutputStream() throws java.io.IOException {
847
// throw new UnsupportedOperationException();
848
// }
849
//
850
// /**
851
// * Get a reader for this object.
852
// *
853
// * @return a Reader for this file object.
854
// * @throws UnsupportedOperationException if character access is not supported
855
// * @throws IOException if an error occurs while opening the reader
856
// */
857
// public java.io.Reader openReader (boolean b) throws java.io.IOException {
858
// throw new UnsupportedOperationException();
859
// }
860
//
861
// /**
862
// * Get a writer for this object.
863
// * @throws UnsupportedOperationException if character access is not supported
864
// * @throws IOException if an error occurs while opening the writer
865
// */
866
// public java.io.Writer openWriter() throws java.io.IOException {
867
// throw new UnsupportedOperationException();
868
// }
869
//
870
// }
871

872     private static class SimpleNameStringComparator implements Comparator JavaDoc<String JavaDoc> {
873         
874         public int compare( String JavaDoc o1, String JavaDoc o2 ) {
875             return getSimpleName( o1 ).compareTo( getSimpleName( o2 ) );
876         }
877                         
878     }
879     
880     private static class SimpleNameFileObjectComparator implements Comparator JavaDoc</*Java*/FileObject> {
881         
882         public int compare( /*Java*/FileObject o1, /*Java*/FileObject o2 ) {
883             
884             String JavaDoc n1 = getSimpleName( o1 );
885             String JavaDoc n2 = getSimpleName( o2 );
886                         
887             return n1.compareTo( n2 );
888         }
889                         
890     }
891     
892     static final String JavaDoc encodingName = new OutputStreamWriter JavaDoc(new ByteArrayOutputStream JavaDoc()).getEncoding();
893     
894 }
895
Popular Tags