3 |
* |
* |
4 |
* Copyright (c) 2003, Benja Fallenstein |
* Copyright (c) 2003, Benja Fallenstein |
5 |
* |
* |
6 |
* This file is part of Storm. |
* This file is part of Fenfire. |
7 |
* |
* |
8 |
* Storm is free software; you can redistribute it and/or modify it under |
* Fenfire is free software; you can redistribute it and/or modify it under |
9 |
* the terms of the GNU Lesser General Public License as published by |
* the terms of the GNU Lesser General Public License as published by |
10 |
* the Free Software Foundation; either version 2 of the License, or |
* the Free Software Foundation; either version 2 of the License, or |
11 |
* (at your option) any later version. |
* (at your option) any later version. |
12 |
* |
* |
13 |
* Storm is distributed in the hope that it will be useful, but WITHOUT |
* Fenfire is distributed in the hope that it will be useful, but WITHOUT |
14 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
15 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General |
16 |
* Public License for more details. |
* Public License for more details. |
17 |
* |
* |
18 |
* You should have received a copy of the GNU Lesser General |
* You should have received a copy of the GNU Lesser General |
19 |
* Public License along with Storm; if not, write to the Free |
* Public License along with Fenfire; if not, write to the Free |
20 |
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
21 |
* MA 02111-1307 USA |
* MA 02111-1307 USA |
22 |
* |
* |
28 |
package org.nongnu.storm.impl; |
package org.nongnu.storm.impl; |
29 |
import org.nongnu.storm.*; |
import org.nongnu.storm.*; |
30 |
import org.nongnu.storm.util.*; |
import org.nongnu.storm.util.*; |
31 |
|
import com.bitzi.util.Base32; |
32 |
import java.io.*; |
import java.io.*; |
33 |
import java.util.*; |
import java.util.*; |
34 |
|
|
48 |
if(inDir == null) throw new NullPointerException("null directory"); |
if(inDir == null) throw new NullPointerException("null directory"); |
49 |
|
|
50 |
byte[] ascii = indexType.getIndexTypeURI().getBytes("US-ASCII"); |
byte[] ascii = indexType.getIndexTypeURI().getBytes("US-ASCII"); |
51 |
String hex = HexUtil.byteArrToHex(ascii); |
String hex = Base32.encode(ascii); |
52 |
dbDir = new File(inDir, "idx_"+hex); |
dbDir = new File(inDir, "idx_"+hex); |
53 |
|
|
54 |
if(!dbDir.exists()) { |
if(!dbDir.exists()) { |
66 |
} |
} |
67 |
|
|
68 |
protected File getKeyFile(byte[] key) throws IOException { |
protected File getKeyFile(byte[] key) throws IOException { |
69 |
return new File(dbDir, "key_"+HexUtil.byteArrToHex(key)); |
return new File(dbDir, "key_"+Base32.encode(key)); |
70 |
} |
} |
71 |
|
|
72 |
public Collector get(byte[] key) throws IOException { |
public Collector get(byte[] key) throws IOException { |
82 |
while(line != null && !line.equals("")) { |
while(line != null && !line.equals("")) { |
83 |
int i = line.indexOf(' '); |
int i = line.indexOf(' '); |
84 |
BlockId block = new BlockId(line.substring(0, i)); |
BlockId block = new BlockId(line.substring(0, i)); |
85 |
byte[] value = HexUtil.hexToByteArr(line.substring(i+1)); |
byte[] value = Base32.decode(line.substring(i+1)); |
86 |
|
|
87 |
result.add(new IndexedPool.Mapping(block, key, value)); |
result.add(new IndexedPool.Mapping(block, key, value)); |
88 |
|
|
116 |
OutputStream os = new FileOutputStream(getKeyFile(m.key).getPath(), true); |
OutputStream os = new FileOutputStream(getKeyFile(m.key).getPath(), true); |
117 |
os.write(m.block.getURI().getBytes("US-ASCII")); |
os.write(m.block.getURI().getBytes("US-ASCII")); |
118 |
os.write((byte)' '); |
os.write((byte)' '); |
119 |
os.write(HexUtil.byteArrToHex(m.value).getBytes("US-ASCII")); |
os.write(Base32.encode(m.value).getBytes("US-ASCII")); |
120 |
os.write((byte)'\n'); |
os.write((byte)'\n'); |
121 |
os.close(); |
os.close(); |
122 |
|
|