//(c):Benja Fallenstein package gzz.storm; import gzz.util.HexUtil; import java.io.*; import java.util.*; public class DefaultPointerIndex extends PointerIndexType { /** The static instance of this singleton. */ public static final DefaultPointerIndex type = new DefaultPointerIndex(); protected DefaultPointerIndex() { } public Object createIndex(IndexedPool pool, IndexedPool.DB db) { throw new UnsupportedOperationException("not implemented"); } 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; String hex; 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; } } }