1 6 21 22 package de.schlichtherle.io; 23 24 import java.io.FileDescriptor ; 25 import java.io.FilterInputStream ; 26 import java.io.InputStream ; 27 import java.io.IOException ; 28 import java.io.FileNotFoundException ; 29 30 131 public class FileInputStream extends FilterInputStream { 132 133 private static InputStream createInputStream(final java.io.File file) 134 throws FileNotFoundException { 135 if (file instanceof File) { 136 final File smartFile = (File) file; 137 smartFile.ensureNotVirtualDirectory("cannot read"); 138 final String entryName = smartFile.getEnclEntryName(); 139 if (entryName != null) 140 return createInputStream( 141 smartFile.getEnclArchive().getArchiveController(), 142 entryName, smartFile); 143 } 144 return new java.io.FileInputStream (file); 145 } 146 147 private static InputStream createInputStream( 148 final ArchiveController controller, 149 final String entryName, 150 final File file) 151 throws FileNotFoundException { 152 try { 153 return controller.getInputStream(entryName); 154 } catch (ArchiveController.FalsePositiveNativeException failure) { 155 final java.io.File delegate = file.getDelegate(); 156 if (delegate.exists() && !delegate.isDirectory()) return new java.io.FileInputStream (file); 158 else 159 throw failure; 160 } 161 } 162 163 168 public FileInputStream(String name) 169 throws FileNotFoundException { 170 super(createInputStream(File.getDefaultArchiveDetector().createFile(name))); 171 } 172 173 178 public FileInputStream(java.io.File file) 179 throws FileNotFoundException { 180 super(createInputStream(file)); 181 } 182 183 187 public FileInputStream(FileDescriptor fd) { 188 super(new java.io.FileInputStream (fd)); 189 } 190 191 public int read(byte b[]) throws IOException { 192 return in.read(b, 0, b.length); 193 } 194 } 195
| Popular Tags
|