KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > indexing > ObjectHeader


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.indexing;
12
13 class ObjectHeader implements Insertable {
14
15     public static final int SIZE = 4;
16     private static final int HeaderTagValue = 0xFFFF;
17     private static final int HeaderTagOffset = 0;
18     private static final int ObjectLengthOffset = 2;
19     private int objectLength;
20
21     /**
22      * ObjectHeader constructor comment.
23      */

24     public ObjectHeader(byte[] buffer) throws ObjectStoreException {
25         if (buffer.length != SIZE)
26             throw new IllegalArgumentException JavaDoc();
27         Buffer buf = new Buffer(buffer);
28         if (buf.getUInt(HeaderTagOffset, 2) != HeaderTagValue) {
29             throw new ObjectStoreException(ObjectStoreException.ObjectHeaderFailure);
30         }
31         this.objectLength = buf.getUInt(ObjectLengthOffset, 2);
32     }
33
34     /**
35      * ObjectHeader constructor comment.
36      */

37     public ObjectHeader(int objectLength) {
38         this.objectLength = objectLength;
39     }
40
41     public int getObjectLength() {
42         return objectLength;
43     }
44
45     public byte[] toByteArray() {
46         Buffer buf = new Buffer(SIZE);
47         buf.put(HeaderTagOffset, 2, HeaderTagValue);
48         buf.put(ObjectLengthOffset, 2, objectLength);
49         return buf.get();
50     }
51 }
52
Popular Tags