001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.harmony.pack200;
018:
019: /**
020: * Stores the combinations of bit flags that can be used in the segment header
021: * options. Whilst this could be defined in {@link Segment}, it's cleaner to
022: * pull it out into a separate class, not least because methods can then be used
023: * to determine the semantic meaning of the flags. In languages with a
024: * pre-processor, these may be defined by macros that do bitflag manipulation
025: * instead.
026: */
027: public class SegmentOptions {
028: private static final int DEFLATE_HINT = 1 << 5;
029:
030: private static final int HAVE_ALL_CODE_FLAGS = 1 << 2;
031:
032: private static final int HAVE_CLASS_FLAGS_HI = 1 << 9;
033:
034: // private static final int UNUSED_3 = 2^3;
035:
036: private static final int HAVE_CODE_FLAGS_HI = 1 << 10;
037:
038: private static final int HAVE_CP_NUMBERS = 1 << 1;
039:
040: private static final int HAVE_FIELD_FLAGS_HI = 1 << 10;
041:
042: private static final int HAVE_FILE_HEADERS = 1 << 4;
043:
044: private static final int HAVE_FILE_MODTIME = 1 << 6;
045:
046: private static final int HAVE_FILE_OPTIONS = 1 << 7;
047:
048: private static final int HAVE_FILE_SIZE_HI = 1 << 8;
049:
050: private static final int HAVE_METHOD_FLAGS_HI = 1 << 11;
051:
052: private static final int HAVE_SPECIAL_FORMATS = 1 << 0;
053:
054: /**
055: * The bit flags that are defined as unused by the specification;
056: * specifically, every bit above bit 13 and bit 3.
057: */
058: private static final int UNUSED = -1 << 13 | 1 << 3;
059:
060: private int options;
061:
062: /**
063: * Creates a new segment options with the given integer value.
064: *
065: * @param options
066: * the integer value to use as the flags
067: * @throws Pack200Exception
068: * if an unused bit (bit 3 or bit 13+) is non-zero
069: */
070: public SegmentOptions(int options) throws Pack200Exception {
071: if ((options & UNUSED) != 0)
072: throw new Pack200Exception("Some unused flags are non-zero");
073: this .options = options;
074: }
075:
076: public boolean hasAllCodeFlags() {
077: return (options & HAVE_ALL_CODE_FLAGS) != 0;
078: }
079:
080: public boolean hasArchiveFileCounts() {
081: return (options & HAVE_FILE_HEADERS) != 0;
082: }
083:
084: public boolean hasClassFlagsHi() {
085: return (options & HAVE_CLASS_FLAGS_HI) != 0;
086: }
087:
088: public boolean hasCodeFlagsHi() {
089: return (options & HAVE_CODE_FLAGS_HI) != 0;
090: }
091:
092: public boolean hasCPNumberCounts() {
093: return (options & HAVE_CP_NUMBERS) != 0;
094: }
095:
096: public boolean hasFieldFlagsHi() {
097: return (options & HAVE_FIELD_FLAGS_HI) != 0;
098: }
099:
100: public boolean hasFileModtime() {
101: return (options & HAVE_FILE_MODTIME) != 0;
102: }
103:
104: public boolean hasFileOptions() {
105: return (options & HAVE_FILE_OPTIONS) != 0;
106: }
107:
108: public boolean hasFileSizeHi() {
109: return (options & HAVE_FILE_SIZE_HI) != 0;
110: }
111:
112: public boolean hasMethodFlagsHi() {
113: return (options & HAVE_METHOD_FLAGS_HI) != 0;
114: }
115:
116: public boolean hasSpecialFormats() {
117: return (options & HAVE_SPECIAL_FORMATS) != 0;
118: }
119:
120: public boolean shouldDeflate() {
121: return (options & DEFLATE_HINT) != 0;
122: }
123: }
|