[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz lava/gzz/storm/StormPool.java lava/gzz/stor...
From: |
Benja Fallenstein |
Subject: |
[Gzz-commits] gzz lava/gzz/storm/StormPool.java lava/gzz/stor... |
Date: |
Fri, 08 Nov 2002 15:54:57 -0500 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Benja Fallenstein <address@hidden> 02/11/08 15:54:55
Modified files:
lava/gzz/storm : StormPool.java
lava/gzz/storm/impl: DirPool.java
lava/test/gzz/storm/impl: DirPool.test
test : testutil.py
Log message:
Start work on DirPool
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/StormPool.java.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/DirPool.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/impl/DirPool.test.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/test/testutil.py.diff?tr1=1.33&tr2=1.34&r1=text&r2=text
Patches:
Index: gzz/lava/gzz/storm/StormPool.java
diff -u gzz/lava/gzz/storm/StormPool.java:1.6
gzz/lava/gzz/storm/StormPool.java:1.7
--- gzz/lava/gzz/storm/StormPool.java:1.6 Thu Nov 7 17:07:00 2002
+++ gzz/lava/gzz/storm/StormPool.java Fri Nov 8 15:54:55 2002
@@ -46,7 +46,7 @@
* @throws FileNotFoundException if the block is not found
* in the pool.
*/
- Block get(BlockId id) throws IOException;
+ Block get(BlockId id) throws FileNotFoundException, IOException;
/** Add a block to this pool.
* The data in the block is checked by this class to assure
Index: gzz/lava/gzz/storm/impl/DirPool.java
diff -u gzz/lava/gzz/storm/impl/DirPool.java:1.1
gzz/lava/gzz/storm/impl/DirPool.java:1.2
--- gzz/lava/gzz/storm/impl/DirPool.java:1.1 Fri Nov 8 15:22:33 2002
+++ gzz/lava/gzz/storm/impl/DirPool.java Fri Nov 8 15:54:55 2002
@@ -5,18 +5,92 @@
import java.io.*;
import java.util.*;
+/** A StormPool storing blocks in individual files in a directory.
+ * File names have the form <code>b_</code><i>idstring</i>.
+ */
public class DirPool implements StormPool {
+
+ /** The directory we store our blocks in.
+ */
+ File dir;
+
+ /** Get the File object for the block
+ * corresponding to a given id.
+ */
+ protected File getFile(BlockId id) {
+ String hex = gzz.util.HexUtil.byteArrToHex(id.getBytes());
+ return new File(dir, "b_" + hex);
+ }
+
+ protected class FileBlockOutputStream extends BlockOutputStream {
+ protected ByteArrayOutputStream baos;
+ protected Header822 header;
+ protected Block block;
+
+ protected FileBlockOutputStream(Header822 header) throws IOException {
+ super(new ByteArrayOutputStream());
+ baos = (ByteArrayOutputStream)out;
+ this.header = header;
+ header.writeTo(baos);
+ }
+ public Block getBlock() { return block; }
+ public Header822 getHeader() { return null; }
+ public void close() throws IOException {
+ byte[] bytes = baos.toByteArray();
+ BlockId id = BlockId.getIdForData(bytes);
+ File file = getFile(id);
+
+ OutputStream os = new FileOutputStream(file);
+ os.write(bytes);
+ os.close();
+
+ block = new FileBlock(id);
+ }
+ }
+
+ protected class FileBlock implements Block {
+ protected File file;
+
+ protected BlockId id;
+
+ protected FileBlock(BlockId id) throws IOException {
+ this.id = id;
+ this.file = getFile(id);
+ }
+ public BlockId getId() { return id; }
+ public StormPool getPool() { return null; }
+ public Header822 getHeader() { return null; }
+ public InputStream getInputStream() {
+ return null;
+ }
+ public InputStream getRawInputStream() throws IOException {
+ return new FileInputStream(file);
+ }
+ }
+
+ /** Create a new DirPool.
+ * @param dir The directory blocks are stored in.
+ * Must already exist.
+ * @throws IllegalArgumentException if the directory
+ * does not exist yet.
+ */
+ public DirPool(File dir) {
+ this.dir = dir;
+ }
+
public Block get(BlockId id) { return null; }
public void add(Block b) {}
public void delete(Block b) {}
public Set getIds() { return null; }
public BlockOutputStream getBlockOutputStream(String contentType)
throws IOException {
- return null;
+ Header822 hdr = new UniqueHeader822();
+ hdr.add("Content-Type", contentType);
+ return new FileBlockOutputStream(hdr);
}
public BlockOutputStream getBlockOutputStream(Header822 hdr)
throws IOException {
- return null;
+ return new FileBlockOutputStream(new VerbatimHeader822(hdr));
}
public String getDefaultPoolName() { return null; }
public Set getPoolNames() { return null; }
Index: gzz/lava/test/gzz/storm/impl/DirPool.test
diff -u gzz/lava/test/gzz/storm/impl/DirPool.test:1.1
gzz/lava/test/gzz/storm/impl/DirPool.test:1.2
--- gzz/lava/test/gzz/storm/impl/DirPool.test:1.1 Fri Nov 8 15:22:33 2002
+++ gzz/lava/test/gzz/storm/impl/DirPool.test Fri Nov 8 15:54:55 2002
@@ -18,14 +18,18 @@
import java, gzz
+dir = gzz.util.TestingUtil.tmpFile(java.io.File("."));
+dir.mkdir();
+
s = gzz.storm.StormPoolTest()
+p = gzz.storm.impl.DirPool(dir)
-def p():
- return gzz.storm.impl.DirPool()
+def testNewBlock(): s.testNewBlock(p)
+def testOwnHeader(): s.testOwnHeader(p)
+def testIdsNotNull(): s.testIdsNotNull(p)
+def testAddId(): s.testAddId(p)
+def testBlockId(): s.testBlockId(p)
-def testNewBlock(): s.testNewBlock(p())
-def testOwnHeader(): s.testOwnHeader(p())
-def testIdsNotNull(): s.testIdsNotNull(p())
-def testAddId(): s.testAddId(p())
-def testBlockId(): s.testBlockId(p())
+def tearDown():
+ gzz.util.TestingUtil.deltree(dir)
Index: gzz/test/testutil.py
diff -u gzz/test/testutil.py:1.33 gzz/test/testutil.py:1.34
--- gzz/test/testutil.py:1.33 Tue Oct 29 14:55:36 2002
+++ gzz/test/testutil.py Fri Nov 8 15:54:55 2002
@@ -129,6 +129,8 @@
tests["needGL"] = needGL
try:
exec compiledTestFile in tests
+ if tests.has_key('tearDown'):
+ exec 'tearDown()' in tests
except NeedGLError, e:
print "Skipping OpenGL test %s" % file
@@ -141,6 +143,10 @@
self.module.needGL = needGL
exec faildefs in self.module.__dict__
exec self.code in self.module.__dict__
+
+ def tearDown(self):
+ if hasattr(self.module, 'tearDown'):
+ self.module.tearDown()
'''
code = code % (name, repr(file))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] gzz lava/gzz/storm/StormPool.java lava/gzz/stor...,
Benja Fallenstein <=