1 11 package org.eclipse.core.internal.localstore; 12 13 import java.io.*; 14 15 34 public class SafeChunkyOutputStream extends FilterOutputStream { 35 protected String filePath; 36 protected boolean isOpen; 37 38 public SafeChunkyOutputStream(File target) throws IOException { 39 this(target.getAbsolutePath()); 40 } 41 42 public SafeChunkyOutputStream(String filePath) throws IOException { 43 super(new BufferedOutputStream(new FileOutputStream(filePath, true))); 44 this.filePath = filePath; 45 isOpen = true; 46 beginChunk(); 47 } 48 49 protected void beginChunk() throws IOException { 50 write(ILocalStoreConstants.BEGIN_CHUNK); 51 } 52 53 protected void endChunk() throws IOException { 54 write(ILocalStoreConstants.END_CHUNK); 55 } 56 57 protected void open() throws IOException { 58 out = new BufferedOutputStream(new FileOutputStream(filePath, true)); 59 isOpen = true; 60 beginChunk(); 61 } 62 63 public void succeed() throws IOException { 64 try { 65 endChunk(); 66 } finally { 67 isOpen = false; 68 close(); 69 } 70 } 71 72 public void write(int b) throws IOException { 73 if (!isOpen) 74 open(); 75 super.write(b); 76 } 77 } 78 | Popular Tags |