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}.
9 final class RecordConstants
{
14 public static final int BLOCK_SIZE
= 32 * 1024;
17 * Header length in data.
19 public static final int HEADER_LENGTH
= 7;
22 * CRC Mask. Comes from http://leveldb.googlecode.com/svn/trunk/util/crc32c.h
24 public static final int CRC_MASK_DELTA
= 0xa282ead8;
27 * An enumerated type that describes the type of the record being stored.
28 * These byte values must match those of the leveldb log format for
29 * compatibility between different implementations
30 * of the {@link RecordWriteChannelImpl}.
33 public enum RecordType
{
43 private RecordType(byte value
) {
47 * The byte value of the record type is written to the file as part of the
49 * @return the byte value of the record type.
56 * Converts a byte value into a {@link RecordType} enum.
57 * @param value the byte value of the {@link RecordType} you want.
58 * @return a {@link RecordType} that corresponds to the inputed byte value.
60 public static RecordType
get(byte value
) {
62 case 0x00: return NONE
;
63 case 0x01: return FULL
;
64 case 0x02: return FIRST
;
65 case 0x03: return MIDDLE
;
66 case 0x04: return LAST
;
67 default: return UNKNOWN
;
75 * Motivation taken from leveldb:
76 * it is problematic to compute the CRC of a string that
77 * contains embedded CRCs. Therefore we recommend that CRCs stored
78 * somewhere (e.g., in files) should be masked before being stored.
79 * @param crc the crc to mask.
80 * @return the masked crc.
82 public static long maskCrc(long crc
) {
83 return ((((crc
>> 15) | (crc
<< 17)) + RecordConstants
.CRC_MASK_DELTA
) & 0xFFFFFFFFL
);
88 * @param maskedCrc a masked crc.
89 * @return an unmasked crc.
91 public static long unmaskCrc(long maskedCrc
) {
92 long rot
= (maskedCrc
- CRC_MASK_DELTA
) & 0xFFFFFFFFL
;
93 return (((rot
>> 17) | (rot
<< 15)) & 0xFFFFFFFFL
);