1 |
//(c):Benja Fallenstein |
/* |
2 |
|
DirPool.java |
3 |
|
* |
4 |
|
* Copyright (c) 2002, Benja Fallenstein |
5 |
|
* |
6 |
|
* You may use and distribute under the terms of either the GNU Lesser |
7 |
|
* General Public License, either version 2 of the license or, |
8 |
|
* at your choice, any later version. Alternatively, you may use and |
9 |
|
* distribute under the terms of the XPL. |
10 |
|
* |
11 |
|
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of |
12 |
|
* the licenses. |
13 |
|
* |
14 |
|
* This software is distributed in the hope that it will be useful, |
15 |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README |
17 |
|
* file for more details. |
18 |
|
* |
19 |
|
*/ |
20 |
|
/* |
21 |
|
* Written by Benja Fallenstein |
22 |
|
*/ |
23 |
package gzz.storm.impl; |
package gzz.storm.impl; |
24 |
import gzz.storm.*; |
import gzz.storm.*; |
25 |
import gzz.storm.headers.*; |
import gzz.storm.headers.*; |
73 |
protected File file; |
protected File file; |
74 |
|
|
75 |
protected BlockId id; |
protected BlockId id; |
76 |
|
protected Header822 header; |
77 |
|
|
78 |
protected FileBlock(BlockId id) throws IOException { |
protected FileBlock(BlockId id) throws IOException { |
79 |
this.id = id; |
this.id = id; |
80 |
this.file = getFile(id); |
this.file = getFile(id); |
81 |
|
|
82 |
|
InputStream is = new FileInputStream(file); |
83 |
|
this.header = Headers822.readHeader(is); |
84 |
|
is.close(); |
85 |
} |
} |
86 |
public BlockId getId() { return id; } |
public BlockId getId() { return id; } |
87 |
public StormPool getPool() { return null; } |
public StormPool getPool() { return null; } |
88 |
public Header822 getHeader() { return null; } |
public Header822 getHeader() { return header; } |
89 |
public InputStream getInputStream() { |
public InputStream getInputStream() throws IOException { |
90 |
return null; |
InputStream is = new FileInputStream(file); |
91 |
|
Headers822.readHeader(is); |
92 |
|
return is; |
93 |
} |
} |
94 |
public InputStream getRawInputStream() throws IOException { |
public InputStream getRawInputStream() throws IOException { |
95 |
return new FileInputStream(file); |
return new FileInputStream(file); |
99 |
/** Create a new DirPool. |
/** Create a new DirPool. |
100 |
* @param dir The directory blocks are stored in. |
* @param dir The directory blocks are stored in. |
101 |
* Must already exist. |
* Must already exist. |
102 |
* @throws IllegalArgumentException if the directory |
* @throws IllegalArgumentException if the file isn't a directory |
103 |
* does not exist yet. |
* or does not exist yet. |
104 |
*/ |
*/ |
105 |
public DirPool(File dir) { |
public DirPool(File dir) { |
106 |
this.dir = dir; |
this.dir = dir; |
107 |
} |
} |
108 |
|
|
109 |
public Block get(BlockId id) { return null; } |
public Block get(BlockId id) throws IOException { |
110 |
|
return new FileBlock(id); |
111 |
|
} |
112 |
public void add(Block b) {} |
public void add(Block b) {} |
113 |
public void delete(Block b) {} |
public void delete(Block b) {} |
114 |
public Set getIds() { return null; } |
public Set getIds() { |
115 |
|
HashSet ids = new HashSet(); |
116 |
|
String[] list = dir.list(); |
117 |
|
|
118 |
|
for(int i=0; i<list.length; i++) |
119 |
|
if(list[i].startsWith("b_")) |
120 |
|
ids.add(new BlockId("storm:block:" + list[i].substring(2))); |
121 |
|
|
122 |
|
return ids; |
123 |
|
} |
124 |
public BlockOutputStream getBlockOutputStream(String contentType) |
public BlockOutputStream getBlockOutputStream(String contentType) |
125 |
throws IOException { |
throws IOException { |
126 |
Header822 hdr = new UniqueHeader822(); |
Header822 hdr = new UniqueHeader822(); |