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 |
|
|
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); |
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 |
} |
} |
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. |
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); |
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 { |