1 19 20 package org.netbeans.lib.cvsclient.file; 21 22 import java.io.*; 23 24 28 public class DefaultWriteTextFilePreprocessor 29 implements WriteTextFilePreprocessor { 30 31 private static final int CHUNK_SIZE = 32768; 32 33 public void copyTextFileToLocation(InputStream processedInputStream, File fileToWrite, OutputStreamProvider customOutput) throws IOException { 34 InputStream tempInput = null; 39 OutputStream out = null; 40 byte[] newLine = System.getProperty("line.separator").getBytes(); 41 try { 42 tempInput = new BufferedInputStream(processedInputStream); 43 out = new BufferedOutputStream(customOutput.createOutputStream()); 44 byte[] cchunk = new byte[CHUNK_SIZE]; 46 for (int readLength = tempInput.read(cchunk); 47 readLength > 0; 48 readLength = tempInput.read(cchunk)) { 49 50 for (int i = 0; i < readLength; i++) { 55 if (cchunk[i] == '\n') { 56 out.write(newLine); 57 } 58 else { 59 out.write(cchunk[i]); 60 } 61 } 62 } 63 } 64 finally { 65 if (tempInput != null) { 66 try { 67 tempInput.close(); 68 } 69 catch (IOException ex) { 70 } 72 } 73 if (out != null) { 74 try { 75 out.close(); 76 } 77 catch (IOException ex) { 78 } 80 } 81 } 82 } 83 } 84 | Popular Tags |