30 |
import java.io.*; |
import java.io.*; |
31 |
import java.security.*; |
import java.security.*; |
32 |
|
|
33 |
|
/** The URN of a Storm block. |
34 |
|
*/ |
35 |
public final class BlockId { |
public final class BlockId { |
36 |
private static String PREFIX = "urn:x-storm:block:"; |
private static String PREFIX = "urn:x-storm:1.0:"; |
37 |
private static int PREFIX_LEN = PREFIX.length(); |
private static int PREFIX_LEN = PREFIX.length(); |
38 |
|
|
39 |
public static class WrongIdException extends IOException { |
public static class WrongIdException extends IOException { |
47 |
private String uri; |
private String uri; |
48 |
|
|
49 |
public BlockId(String uri) throws IllegalArgumentException { |
public BlockId(String uri) throws IllegalArgumentException { |
50 |
|
uri = uri.toLowerCase().intern(); |
51 |
|
this.uri = uri; |
52 |
|
|
53 |
|
int dot = uri.lastIndexOf('.'); |
54 |
|
int comma = uri.lastIndexOf(','); |
55 |
|
|
56 |
|
if(!uri.startsWith(PREFIX) || dot < 0 || |
57 |
|
comma < 0 || dot < comma) |
58 |
|
throw new IllegalArgumentException("Bad block URN: "+uri); |
59 |
|
|
60 |
|
contentType = uri.substring(PREFIX_LEN, comma); |
61 |
|
sha1 = Base32.decode(uri.substring(comma+1, dot)); |
62 |
|
tigertree = Base32.decode(uri.substring(dot+1)); |
63 |
} |
} |
64 |
|
|
65 |
public BlockId(byte[] sha1, byte[] tigertree, |
public BlockId(byte[] sha1, byte[] tigertree, |
66 |
String contentType) { |
String contentType) { |
67 |
|
this.sha1 = sha1; |
68 |
|
this.tigertree = tigertree; |
69 |
|
this.contentType = contentType; |
70 |
|
|
71 |
|
uri = PREFIX + contentType + "," + |
72 |
|
Base32.encode(sha1) + "." + Base32.encode(tigertree); |
73 |
} |
} |
74 |
|
|
75 |
public byte[] getSha1() { return sha1; } |
public byte[] getSha1() { return sha1; } |
102 |
|
|
103 |
public boolean equals(Object o) { |
public boolean equals(Object o) { |
104 |
if(!(o instanceof BlockId)) return false; |
if(!(o instanceof BlockId)) return false; |
105 |
return ((BlockId)o).uri.equals(uri); |
return ((BlockId)o).uri == uri; |
106 |
} |
} |
107 |
|
|
108 |
public int hashCode() { return uri.hashCode(); } |
public int hashCode() { return uri.hashCode(); } |