/[storm]/storm/org/nongnu/storm/BlockId.java
ViewVC logotype

Diff of /storm/org/nongnu/storm/BlockId.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by benja, Thu Apr 3 20:36:28 2003 UTC revision 1.4 by benja, Sun Apr 6 21:36:30 2003 UTC
# Line 30  import com.bitzi.util.*; Line 30  import com.bitzi.util.*;
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 {
# Line 45  public final class BlockId { Line 47  public final class BlockId {
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; }
# Line 81  public final class BlockId { Line 102  public final class BlockId {
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(); }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26