01: /* HeaderBlock
02: *
03: * Created on September 12, 2006
04: *
05: * Copyright (C) 2006 Internet Archive.
06: *
07: * This file is part of the Heritrix web crawler (crawler.archive.org).
08: *
09: * 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: import java.nio.ByteBuffer;
26: import java.nio.ByteOrder;
27:
28: class HeaderBlock {
29:
30: private ByteBuffer buffer;
31:
32: public HeaderBlock(ByteBuffer buffer) {
33: // FIXME: Read the fields we're interested in directly from stream
34: this .buffer = buffer;
35: buffer.order(ByteOrder.LITTLE_ENDIAN);
36: }
37:
38: public long getFileType() {
39: return buffer.getLong(0);
40: }
41:
42: public int getBATCount() {
43: return buffer.getInt(0x2C);
44: }
45:
46: public int getEntriesStart() {
47: return buffer.getInt(0x30);
48: }
49:
50: public int getSmallBATStart() {
51: return buffer.getInt(0x3C);
52: }
53:
54: public int getSmallBATCount() {
55: return buffer.getInt(0x40);
56: }
57:
58: public int getExtendedBATStart() {
59: return buffer.getInt(0x44);
60: }
61:
62: public int getExtendedBATCount() {
63: return buffer.getInt(0x48);
64: }
65:
66: public int getBATBlockNumber(int block) {
67: assert block < 110;
68: return buffer.getInt(0x4C + block * 4);
69: }
70:
71: public String toString() {
72: StringBuilder sb = new StringBuilder("HeaderBlock{");
73: sb.append("fileType=" + getFileType());
74: sb.append(" propertiesStart=" + getEntriesStart());
75: sb.append(" batCount=" + getBATCount());
76: sb.append(" extendedBATStart=" + getExtendedBATStart());
77: sb.append(" extendedBATCount=" + getExtendedBATCount());
78: sb.append(" smallBATStart=" + getSmallBATStart());
79: sb.append(" smallBATCount=" + getSmallBATCount());
80: sb.append("}");
81: return sb.toString();
82: }
83:
84: }
|