1 21 22 package org.armedbear.j.mail; 23 24 import java.io.BufferedWriter ; 25 import java.io.FileOutputStream ; 26 import java.io.IOException ; 27 import java.io.OutputStreamWriter ; 28 import java.io.Writer ; 29 import org.armedbear.j.File; 30 import org.armedbear.j.Log; 31 32 public final class MailboxFileWriter extends BufferedWriter 33 { 34 private long offset; 35 36 private MailboxFileWriter(Writer out) 37 { 38 super(out); 39 } 40 41 public static MailboxFileWriter getInstance(File file, boolean append) 42 { 43 try { 44 FileOutputStream outputStream = 45 new FileOutputStream (file.canonicalPath(), append); 46 MailboxFileWriter writer = new MailboxFileWriter( 47 new OutputStreamWriter (outputStream, "ISO-8859-1")); 48 if (append && file.isFile()) 49 writer.offset = file.length(); 50 return writer; 51 } 52 catch (Exception e) { 53 Log.error(e); 54 return null; 55 } 56 } 57 58 public final long getOffset() 59 { 60 return offset; 61 } 62 63 public void write(int c) throws IOException 64 { 65 super.write(c); 66 ++offset; 67 } 68 69 public void write(char[] cbuf, int off, int len) throws IOException 70 { 71 super.write(cbuf, off, len); 72 offset += len; 73 } 74 75 public void write(String s, int off, int len) throws IOException 76 { 77 super.write(s, off, len); 78 offset += len; 79 } 80 81 public void newLine() throws IOException 82 { 83 super.write('\n'); ++offset; 85 } 86 87 public void flush() throws IOException 88 { 89 super.flush(); 90 } 91 92 public void close() throws IOException 93 { 94 super.close(); 95 } 96 } 97 | Popular Tags |