/[storm]/storm/org/nongnu/storm/impl/DirPool.java
ViewVC logotype

Diff of /storm/org/nongnu/storm/impl/DirPool.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by benja, Tue Apr 8 08:10:12 2003 UTC revision 1.5 by benja, Tue Apr 15 09:33:41 2003 UTC
# Line 33  import java.util.*; Line 33  import java.util.*;
33    
34  /** A StormPool storing blocks in individual files in a directory.  /** A StormPool storing blocks in individual files in a directory.
35   *  File names have the form <code>data_</code><i>idstring</i>.   *  File names have the form <code>data_</code><i>idstring</i>.
36     *  Blocks in this pool are <code>DirPoolBlock</code>s.
37   */   */
38  public class DirPool extends AbstractLocalPool {  public class DirPool extends AbstractLocalPool {
39    
# Line 54  public class DirPool extends AbstractLoc Line 55  public class DirPool extends AbstractLoc
55      }      }
56            
57    
58      protected class FileBlockOutputStream extends AbstractBlockOutputStream {      protected class DirPoolBlockOutputStream extends AbstractBlockOutputStream {
59          protected File tempFile;          protected File tempFile;
60    
61          protected FileBlockOutputStream(File tempFile, String contentType)          protected DirPoolBlockOutputStream(File tempFile, String contentType)
62                                                           throws IOException {                                                           throws IOException {
63              super(new BufferedOutputStream(new FileOutputStream(tempFile)),              super(new BufferedOutputStream(new FileOutputStream(tempFile)),
64                    contentType);                    contentType);
# Line 73  public class DirPool extends AbstractLoc Line 74  public class DirPool extends AbstractLoc
74                  throw new IOException("Could not rename temporary file");                  throw new IOException("Could not rename temporary file");
75              }              }
76    
77              block = new FileBlock(id);              block = new DirPoolBlock(id);
78              added(block);              added(block);
79              return block;              return block;
80          }          }
81      }      }
82    
83      protected class FileBlock extends AbstractBlock {      protected class DirPoolBlock extends AbstractBlock implements FileBlock {
84          protected File file;          protected File file;
85    
86          protected FileBlock(BlockId id) throws IOException {          protected DirPoolBlock(BlockId id) throws IOException {
87              super(id);              super(id);
88              this.file = getFile(id);              this.file = DirPool.this.getFile(id);
89              if(!file.exists())              if(!file.exists())
90                  throw new FileNotFoundException("Block: "+id);                  throw new FileNotFoundException("Block: "+id);
91          }          }
# Line 93  public class DirPool extends AbstractLoc Line 94  public class DirPool extends AbstractLoc
94              return new BufferedInputStream(              return new BufferedInputStream(
95                  id.getCheckedInputStream(new FileInputStream(file)));                  id.getCheckedInputStream(new FileInputStream(file)));
96          }          }
97    
98            public File getFile() throws IOException {
99                // check  the id
100                id.getCheckedInputStream(new FileInputStream(file)).close();
101    
102                return file;
103            }
104      }      }
105    
106      /** Create a new DirPool.      /** Create a new DirPool.
# Line 111  public class DirPool extends AbstractLoc Line 119  public class DirPool extends AbstractLoc
119      }      }
120    
121      public Block get(BlockId id) throws IOException {      public Block get(BlockId id) throws IOException {
122          return new FileBlock(id);          return new DirPoolBlock(id);
123      }      }
124      public void add(Block b) throws IOException {      public void add(Block b) throws IOException {
125          File temp = TempFileUtil.tmpFile(dir);          File temp = TempFileUtil.tmpFile(dir);
# Line 150  public class DirPool extends AbstractLoc Line 158  public class DirPool extends AbstractLoc
158      public BlockOutputStream getBlockOutputStream(String contentType)      public BlockOutputStream getBlockOutputStream(String contentType)
159                                                            throws IOException {                                                            throws IOException {
160          File tempFile = TempFileUtil.tmpFile(dir);          File tempFile = TempFileUtil.tmpFile(dir);
161          return new FileBlockOutputStream(tempFile, contentType);          return new DirPoolBlockOutputStream(tempFile, contentType);
162      }      }
163    
164      protected DB getDB(IndexType indexType) throws IOException {      protected DB getDB(IndexType indexType) throws IOException {

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26