예제 #1
0
 public void copy(InputStream is, OutputStream os) {
   try {
     copyNoClose(is, os);
   } finally {
     closeQuietly(is);
     closeQuietly(os);
   }
 }
예제 #2
0
 public void copy(InputStream is, File dest) {
   FileOutputStream os = null;
   try {
     os = new FileOutputStream(dest);
     copy(is, os);
   } catch (Throwable e) {
     throw new RuntimeException(e);
   } finally {
     closeQuietly(is);
     closeQuietly(os);
   }
 }
예제 #3
0
 void copy(Reader reader, OutputStream os) {
   int bufSize = 1024;
   char buf[] = new char[bufSize];
   BufferedWriter bw = null;
   try {
     bw = new BufferedWriter(new OutputStreamWriter(os, charSet));
     for (int read; (read = reader.read(buf)) != -1; ) {
       bw.write(buf, 0, read);
     }
   } catch (IOException e) {
     throw new RuntimeException(e);
   } finally {
     closeQuietly(reader);
     closeQuietly(bw);
   }
 }
예제 #4
0
 public void copy(File src, File dest) {
   logger.log(
       Level.FINEST, "Copying ''{0}'' to ''{1}''", new Object[] {src.getPath(), dest.getPath()});
   dest.getParentFile().mkdirs();
   FileInputStream is = null;
   FileOutputStream os = null;
   try {
     is = new FileInputStream(src);
     os = new FileOutputStream(dest);
     copy(is, os);
   } catch (Throwable e) {
     throw new RuntimeException(e);
   } finally {
     closeQuietly(is);
     closeQuietly(os);
   }
 }
예제 #5
0
 public String loadFromFileSystem(File dataFile) {
   InputStream is = null;
   try {
     is = new FileInputStream(dataFile);
     return toString(is);
   } catch (Throwable e) {
     throw new RuntimeException(String.format("Problem loading file: '%s'", dataFile), e);
   } finally {
     closeQuietly(is);
   }
 }
예제 #6
0
 public String loadFromClassPath(String dataFile) {
   InputStream is = null;
   try {
     //            is =
     // Thread.currentThread().getContextClassLoader().getResourceAsStream(dataFile);
     is = IoUtils.class.getResourceAsStream(dataFile);
     return toString(is);
   } catch (Throwable e) {
     throw new RuntimeException(String.format("Problem loading resource: '%s'", dataFile), e);
   } finally {
     closeQuietly(is);
   }
 }
예제 #7
0
 public void copyNoClose(File file, OutputStream os) {
   InputStream is = null;
   int bufSize = 1024;
   byte buf[] = new byte[bufSize];
   try {
     is = new FileInputStream(file);
     for (int read; (read = is.read(buf)) != -1; ) {
       os.write(buf, 0, read);
       os.flush();
     }
   } catch (IOException e) {
     throw new RuntimeException(e);
   } finally {
     closeQuietly(is);
   }
 }
예제 #8
0
 public String toString(InputStream is) {
   StringBuilder result = new StringBuilder();
   int bufSize = 1024;
   char buf[] = new char[bufSize];
   BufferedReader br = null;
   try {
     br = new BufferedReader(new InputStreamReader(is, charSet));
     for (int read; (read = br.read(buf)) != -1; ) {
       result.append(buf, 0, read);
     }
     return result.toString();
   } catch (IOException e) {
     throw new RuntimeException(e);
   } finally {
     closeQuietly(br);
   }
 }