View Javadoc

1   /* HeaderBlock
2   *
3   * Created on September 12, 2006
4   *
5   * Copyright (C) 2006 Internet Archive.
6   *
7   * This file is part of the Heritrix web crawler (crawler.archive.org).
8   *
9   * Heritrix is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * any later version.
13  *
14  * Heritrix is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser Public License
20  * along with Heritrix; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23  package org.archive.util.ms;
24  
25  
26  import java.nio.ByteBuffer;
27  import java.nio.ByteOrder;
28  
29  
30  class HeaderBlock {
31  
32      
33      private ByteBuffer buffer;
34      
35      
36      public HeaderBlock(ByteBuffer buffer) {
37          // FIXME: Read the fields we're interested in directly from stream
38          this.buffer = buffer;
39          buffer.order(ByteOrder.LITTLE_ENDIAN);
40      }
41      
42      
43      public long getFileType() {
44          return buffer.getLong(0);
45      }
46      
47      
48      public int getBATCount() {
49          return buffer.getInt(0x2C);
50      }
51      
52      
53      public int getEntriesStart() {
54          return buffer.getInt(0x30);
55      }
56      
57      
58      public int getSmallBATStart() {
59          return buffer.getInt(0x3C);
60      }
61      
62      
63      public int getSmallBATCount() {
64          return buffer.getInt(0x40);
65      }
66      
67      
68      public int getExtendedBATStart() {
69          return buffer.getInt(0x44);
70      }
71      
72      
73      public int getExtendedBATCount() {
74          return buffer.getInt(0x48);
75      }
76      
77      
78      public int getBATBlockNumber(int block) {
79          assert block < 110;
80          return buffer.getInt(0x4C + block * 4);
81      }
82  
83      
84      public String toString() {
85          StringBuilder sb = new StringBuilder("HeaderBlock{");
86          sb.append("fileType=" + getFileType());
87          sb.append(" propertiesStart=" + getEntriesStart());
88          sb.append(" batCount=" + getBATCount());
89          sb.append(" extendedBATStart=" + getExtendedBATStart());
90          sb.append(" extendedBATCount=" + getExtendedBATCount());
91          sb.append(" smallBATStart=" + getSmallBATStart());
92          sb.append(" smallBATCount=" + getSmallBATCount());
93          sb.append("}");
94          return sb.toString();
95      }
96  
97  }