1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.api
.files
;
6 * A set of constants needed by {@link RecordReadChannelImpl} and {@link RecordWriteChannelImpl}.
10 final class RecordConstants
{
15 public static final int BLOCK_SIZE
= 32 * 1024;
18 * Header length in data.
20 public static final int HEADER_LENGTH
= 7;
23 * CRC Mask. Comes from http://leveldb.googlecode.com/svn/trunk/util/crc32c.h
25 public static final int CRC_MASK_DELTA
= 0xa282ead8;
28 * An enumerated type that describes the type of the record being stored.
29 * These byte values must match those of the leveldb log format for
30 * compatibility between different implementations
31 * of the {@link RecordWriteChannelImpl}.
34 public enum RecordType
{
44 private RecordType(byte value
) {
48 * The byte value of the record type is written to the file as part of the
50 * @return the byte value of the record type.
57 * Converts a byte value into a {@link RecordType} enum.
58 * @param value the byte value of the {@link RecordType} you want.
59 * @return a {@link RecordType} that corresponds to the inputed byte value.
61 public static RecordType
get(byte value
) {
63 case 0x00: return NONE
;
64 case 0x01: return FULL
;
65 case 0x02: return FIRST
;
66 case 0x03: return MIDDLE
;
67 case 0x04: return LAST
;
68 default: return UNKNOWN
;
76 * Motivation taken from leveldb:
77 * it is problematic to compute the CRC of a string that
78 * contains embedded CRCs. Therefore we recommend that CRCs stored
79 * somewhere (e.g., in files) should be masked before being stored.
80 * @param crc the crc to mask.
81 * @return the masked crc.
83 public static long maskCrc(long crc
) {
84 return ((((crc
>> 15) | (crc
<< 17)) + RecordConstants
.CRC_MASK_DELTA
) & 0xFFFFFFFFL
);
89 * @param maskedCrc a masked crc.
90 * @return an unmasked crc.
92 public static long unmaskCrc(long maskedCrc
) {
93 long rot
= (maskedCrc
- CRC_MASK_DELTA
) & 0xFFFFFFFFL
;
94 return (((rot
>> 17) | (rot
<< 15)) & 0xFFFFFFFFL
);