1 16 package com.blandware.atleap.common.parsers.txt; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.common.parsers.SpecificPlainTextExtractor; 20 import com.blandware.atleap.common.parsers.exception.PlainTextExtractorException; 21 22 import java.io.*; 23 24 25 33 public class TXTPlainTextExtractor implements SpecificPlainTextExtractor { 34 private static final int BUFFER_SIZE = 4096; 35 private char[] buffer = new char[BUFFER_SIZE]; 36 37 protected String usedEncoding = null; 38 39 public TXTPlainTextExtractor() { 40 } 41 42 54 public void extract(InputStream input, Writer output, String encoding) 55 throws PlainTextExtractorException { 56 int readChars; 57 58 try { 59 if (encoding == null || encoding.trim().length() == 0) { 60 encoding = Constants.DEFAULT_ENCODING; 61 } 62 usedEncoding = encoding; 63 Reader reader = new BufferedReader(new InputStreamReader(input, encoding)); 64 while (true) { 65 readChars = reader.read(buffer); 66 if (readChars <= 0) { 67 break; 68 } 69 output.write(buffer, 0, readChars); 70 } 71 } catch (IOException e) { 72 throw new PlainTextExtractorException(e); 73 } 74 } 75 76 79 public String getUsedEncoding() { 80 return usedEncoding; 81 } 82 } 83 | Popular Tags |