1 11 package org.eclipse.core.internal.localstore; 12 13 import java.io.*; 14 15 22 public class SafeFileInputStream extends FilterInputStream { 23 protected static final String EXTENSION = ".bak"; private static final int DEFAUT_BUFFER_SIZE = 2048; 25 26 public SafeFileInputStream(File file) throws IOException { 27 this(file.getAbsolutePath(), null); 28 } 29 30 33 public SafeFileInputStream(String targetPath, String tempPath) throws IOException { 34 super(getInputStream(targetPath, tempPath, DEFAUT_BUFFER_SIZE)); 35 } 36 37 40 public SafeFileInputStream(String targetPath, String tempPath, int bufferSize) throws IOException { 41 super(getInputStream(targetPath, tempPath, bufferSize)); 42 } 43 44 private static InputStream getInputStream(String targetPath, String tempPath, int bufferSize) throws IOException { 45 File target = new File(targetPath); 46 if (!target.exists()) { 47 if (tempPath == null) 48 tempPath = target.getAbsolutePath() + EXTENSION; 49 target = new File(tempPath); 50 } 51 return new BufferedInputStream(new FileInputStream(target), bufferSize); 52 } 53 } 54 | Popular Tags |