28 |
Pointer getPointer(String uri); |
Pointer getPointer(String uri); |
29 |
} |
} |
30 |
|
|
|
abstract public Object getIndex(IndexedPool pool, IndexedPool.DB db) |
|
|
throws IOException; |
|
|
|
|
31 |
public final String getIndexTypeURI() { |
public final String getIndexTypeURI() { |
32 |
return indexTypeURI; |
return indexTypeURI; |
33 |
} |
} |
34 |
|
|
35 |
/** The default implementation of getting the mapping |
abstract public Set getMappings(Block b) throws IOException; |
|
* for a pointer block. Subclasses which override this |
|
|
* must provide exactly the same functionality; |
|
|
* the only reason to override would be if the subclass |
|
|
* had a more efficient way to parse pointer blocks. |
|
|
*/ |
|
|
public Set getMappings(Block b) throws IOException { |
|
|
String blockContentType = |
|
|
b.getHeader().get("Content-Type").toLowerCase(); |
|
|
|
|
|
if(blockContentType.equals(contentType)) { |
|
|
BufferedReader br = new BufferedReader( |
|
|
new InputStreamReader(b.getInputStream(), "ISO8859_1")); |
|
|
String s = br.readLine(); |
|
|
if(!s.equals("GZZPTR0")) |
|
|
// Unknown pointer block format-- ignore |
|
|
return Collections.EMPTY_SET; |
|
|
|
|
|
byte[] key = br.readLine().getBytes("US-ASCII"); |
|
|
|
|
|
List items = new ArrayList(3); |
|
|
int len = 0; |
|
36 |
|
|
37 |
String hex; |
abstract public Object createIndex(IndexedPool pool, IndexedPool.DB db); |
|
while((hex = br.readLine()) != null) { |
|
|
byte[] arr = HexUtil.hexToByteArr(hex); |
|
|
if(arr.length > 127) |
|
|
throw new IOException("Storm id is too long: "+hex); |
|
|
items.add(arr); |
|
|
len += arr.length + 1; |
|
|
} |
|
|
|
|
|
br.close(); |
|
|
|
|
|
byte[] value = new byte[len]; |
|
|
int pos = 0; |
|
|
for(Iterator i=items.iterator(); i.hasNext();) { |
|
|
byte[] arr = (byte[])i.next(); |
|
|
value[pos] = (byte)arr.length; |
|
|
pos++; |
|
|
System.arraycopy(arr, 0, value, pos, arr.length); |
|
|
pos += arr.length; |
|
|
} |
|
|
|
|
|
IndexedPool.Mapping m = |
|
|
new IndexedPool.Mapping(b.getId(), key, value); |
|
|
return Collections.singleton(m); |
|
|
} else { |
|
|
return Collections.EMPTY_SET; |
|
|
} |
|
|
} |
|
38 |
} |
} |