View Javadoc
1 /* 2 * 3 * Created on Nov 23, 2004 4 */ 5 package org.relique.jdbc.csv; 6 7 import java.io.BufferedReader; 8 import java.io.FileInputStream; 9 import java.io.FileNotFoundException; 10 import java.io.IOException; 11 import java.io.InputStreamReader; 12 import java.io.RandomAccessFile; 13 import java.io.UnsupportedEncodingException; 14 15 /*** 16 * 17 * @author Zoran Milakovic 18 */ 19 public class CsvRandomAccessFile extends RandomAccessFile { 20 21 private String fileName = null; 22 private String charset = null; 23 private long position = 0; 24 25 public CsvRandomAccessFile(String fileName, String charset) throws FileNotFoundException, UnsupportedEncodingException { 26 super(fileName,"rw"); 27 if(charset != null) 28 this.charset = charset; 29 this.fileName = fileName; 30 } 31 32 public String readCsvLine() throws IOException { 33 String retVal = null; 34 if(Utils.isUTF16(this.charset)) { 35 FileInputStream is = new FileInputStream(fileName); 36 BufferedReader reader = new BufferedReader(new InputStreamReader(is,charset)); 37 is.getChannel().position(this.position); 38 retVal = reader.readLine(); 39 if(retVal != null && retVal.equals("")) { 40 retVal = reader.readLine(); 41 } 42 int length = 0; 43 if(retVal != null) { 44 length = retVal.getBytes(this.charset).length; 45 } 46 this.position += length; 47 super.seek(this.position); 48 reader.close(); 49 is.close(); 50 } else { 51 retVal = super.readLine(); 52 } 53 return retVal; 54 } 55 56 public void seek(long pos) throws IOException { 57 super.seek(pos); 58 this.position = pos; 59 } 60 61 }

This page was automatically generated by Maven