1 6 21 22 package de.schlichtherle.io; 23 24 import java.io.FileDescriptor ; 25 import java.io.FilterOutputStream ; 26 import java.io.InputStream ; 27 import java.io.OutputStream ; 28 import java.io.IOException ; 29 import java.io.FileNotFoundException ; 30 31 137 public class FileOutputStream extends FilterOutputStream { 138 139 private static OutputStream createOutputStream( 140 final java.io.File file, 141 final boolean append) 142 throws FileNotFoundException { 143 if (file instanceof File) { 144 final File smartFile = (File) file; 145 smartFile.ensureNotVirtualDirectory("cannot write"); 146 final String entryName = smartFile.getEnclEntryName(); 147 if (entryName != null) { 148 return createOutputStream( 149 smartFile.getEnclArchive().getArchiveController(), 150 entryName, smartFile, append); 151 } 152 } 153 return new java.io.FileOutputStream (file, append); 154 } 155 156 private static OutputStream createOutputStream( 157 final ArchiveController controller, 158 final String entryName, 159 final File file, 160 final boolean append) 161 throws FileNotFoundException { 162 try { 163 return controller.getOutputStream(entryName, append); 164 } catch (ArchiveController.FalsePositiveNativeException failure) { 165 final java.io.File delegate = file.getDelegate(); 166 final java.io.File parent = delegate.getParentFile(); 167 if (parent.isDirectory()) return new java.io.FileOutputStream (file); 169 else 170 throw failure; 171 } 172 } 173 174 179 public FileOutputStream(String name) 180 throws FileNotFoundException { 181 super(createOutputStream( 182 File.getDefaultArchiveDetector().createFile(name), false)); 183 } 184 185 190 public FileOutputStream(String name, boolean append) 191 throws FileNotFoundException { 192 super(createOutputStream( 193 File.getDefaultArchiveDetector().createFile(name), append)); 194 } 195 196 201 public FileOutputStream(java.io.File file) 202 throws FileNotFoundException { 203 super(createOutputStream(file, false)); 204 } 205 206 211 public FileOutputStream(java.io.File file, boolean append) 212 throws FileNotFoundException { 213 super(createOutputStream(file, append)); 214 } 215 216 220 public FileOutputStream(FileDescriptor fd) { 221 super(new java.io.FileOutputStream (fd)); 222 } 223 224 public void write(byte[] buf, int off, int len) throws IOException { 225 out.write(buf, off, len); 226 } 227 } 228
| Popular Tags
|