[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] storm/org/nongnu/storm BlockId.java BlockId.tes...
From: |
Benja Fallenstein |
Subject: |
[Gzz-commits] storm/org/nongnu/storm BlockId.java BlockId.tes... |
Date: |
Tue, 15 Apr 2003 05:33:41 -0400 |
CVSROOT: /cvsroot/storm
Module name: storm
Changes by: Benja Fallenstein <address@hidden> 03/04/15 05:33:41
Modified files:
org/nongnu/storm: BlockId.java BlockId.test
org/nongnu/storm/impl: DirPool.java
Added files:
org/nongnu/storm: FileBlock.java
Log message:
allow accessing blocks as files on the disk
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/FileBlock.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/BlockId.java.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/BlockId.test.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/impl/DirPool.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
Patches:
Index: storm/org/nongnu/storm/BlockId.java
diff -u storm/org/nongnu/storm/BlockId.java:1.9
storm/org/nongnu/storm/BlockId.java:1.10
--- storm/org/nongnu/storm/BlockId.java:1.9 Tue Apr 15 04:48:11 2003
+++ storm/org/nongnu/storm/BlockId.java Tue Apr 15 05:33:41 2003
@@ -120,6 +120,10 @@
return new FilterInputStream(in) {
public void close() throws IOException {
+ /** Read all that hasn't been read yet.
+ */
+ while(read() > 0);
+
super.close();
byte[] dig;
Index: storm/org/nongnu/storm/BlockId.test
diff -u storm/org/nongnu/storm/BlockId.test:1.6
storm/org/nongnu/storm/BlockId.test:1.7
--- storm/org/nongnu/storm/BlockId.test:1.6 Tue Apr 15 04:48:11 2003
+++ storm/org/nongnu/storm/BlockId.test Tue Apr 15 05:33:41 2003
@@ -122,6 +122,14 @@
except BlockId.WrongIdException: return 0
else: return 1
+def check3(id, data):
+ s = java.io.ByteArrayInputStream(data)
+ s2 = id.getCheckedInputStream(s)
+
+ try: s2.close()
+ except BlockId.WrongIdException: return 0
+ else: return 1
+
def testCheck():
id_1 = BlockId(uri_1)
@@ -139,3 +147,9 @@
assert check2(id_3, data_3)
assert (not check2(id_1, data_3)) and (not check2(id_2, data_3))
+
+ assert check3(id_2, data_2)
+ assert (not check3(id_1, data_2)) and (not check3(id_3, data_2))
+
+ assert check3(id_3, data_3)
+ assert (not check3(id_1, data_3)) and (not check3(id_2, data_3))
Index: storm/org/nongnu/storm/impl/DirPool.java
diff -u storm/org/nongnu/storm/impl/DirPool.java:1.4
storm/org/nongnu/storm/impl/DirPool.java:1.5
--- storm/org/nongnu/storm/impl/DirPool.java:1.4 Tue Apr 8 04:10:12 2003
+++ storm/org/nongnu/storm/impl/DirPool.java Tue Apr 15 05:33:41 2003
@@ -33,6 +33,7 @@
/** A StormPool storing blocks in individual files in a directory.
* File names have the form <code>data_</code><i>idstring</i>.
+ * Blocks in this pool are <code>DirPoolBlock</code>s.
*/
public class DirPool extends AbstractLocalPool {
@@ -54,10 +55,10 @@
}
- protected class FileBlockOutputStream extends AbstractBlockOutputStream {
+ protected class DirPoolBlockOutputStream extends AbstractBlockOutputStream
{
protected File tempFile;
- protected FileBlockOutputStream(File tempFile, String contentType)
+ protected DirPoolBlockOutputStream(File tempFile, String contentType)
throws IOException {
super(new BufferedOutputStream(new FileOutputStream(tempFile)),
contentType);
@@ -73,18 +74,18 @@
throw new IOException("Could not rename temporary file");
}
- block = new FileBlock(id);
+ block = new DirPoolBlock(id);
added(block);
return block;
}
}
- protected class FileBlock extends AbstractBlock {
+ protected class DirPoolBlock extends AbstractBlock implements FileBlock {
protected File file;
- protected FileBlock(BlockId id) throws IOException {
+ protected DirPoolBlock(BlockId id) throws IOException {
super(id);
- this.file = getFile(id);
+ this.file = DirPool.this.getFile(id);
if(!file.exists())
throw new FileNotFoundException("Block: "+id);
}
@@ -93,6 +94,13 @@
return new BufferedInputStream(
id.getCheckedInputStream(new FileInputStream(file)));
}
+
+ public File getFile() throws IOException {
+ // check the id
+ id.getCheckedInputStream(new FileInputStream(file)).close();
+
+ return file;
+ }
}
/** Create a new DirPool.
@@ -111,7 +119,7 @@
}
public Block get(BlockId id) throws IOException {
- return new FileBlock(id);
+ return new DirPoolBlock(id);
}
public void add(Block b) throws IOException {
File temp = TempFileUtil.tmpFile(dir);
@@ -150,7 +158,7 @@
public BlockOutputStream getBlockOutputStream(String contentType)
throws IOException {
File tempFile = TempFileUtil.tmpFile(dir);
- return new FileBlockOutputStream(tempFile, contentType);
+ return new DirPoolBlockOutputStream(tempFile, contentType);
}
protected DB getDB(IndexType indexType) throws IOException {