Source Code Cross Referenced for BandSet.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » pack200 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.pack200 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        import java.io.ByteArrayOutputStream;
020:        import java.io.IOException;
021:        import java.io.InputStream;
022:        import java.util.Arrays;
023:
024:        import org.apache.harmony.pack200.bytecode.CPClass;
025:        import org.apache.harmony.pack200.bytecode.CPDouble;
026:        import org.apache.harmony.pack200.bytecode.CPFieldRef;
027:        import org.apache.harmony.pack200.bytecode.CPFloat;
028:        import org.apache.harmony.pack200.bytecode.CPInteger;
029:        import org.apache.harmony.pack200.bytecode.CPInterfaceMethodRef;
030:        import org.apache.harmony.pack200.bytecode.CPLong;
031:        import org.apache.harmony.pack200.bytecode.CPMethodRef;
032:        import org.apache.harmony.pack200.bytecode.CPNameAndType;
033:        import org.apache.harmony.pack200.bytecode.CPString;
034:        import org.apache.harmony.pack200.bytecode.CPUTF8;
035:        import org.apache.harmony.pack200.bytecode.ClassConstantPool;
036:
037:        public abstract class BandSet {
038:
039:            public abstract void unpack(InputStream inputStream)
040:                    throws IOException, Pack200Exception;
041:
042:            protected Segment segment;
043:
044:            protected SegmentHeader header;
045:
046:            public BandSet(Segment segment) {
047:                this .segment = segment;
048:                this .header = segment.getSegmentHeader();
049:            }
050:
051:            /**
052:             * Decode a band and return an array of <code>int</code> values
053:             *
054:             * @param name
055:             *            the name of the band (primarily for logging/debugging
056:             *            purposes)
057:             * @param in
058:             *            the InputStream to decode from
059:             * @param defaultCodec
060:             *            the default codec for this band
061:             * @param count
062:             *            the number of elements to read
063:             * @return an array of decoded <code>int</code> values
064:             * @throws IOException
065:             *             if there is a problem reading from the underlying input
066:             *             stream
067:             * @throws Pack200Exception
068:             *             if there is a problem decoding the value or that the value is
069:             *             invalid
070:             */
071:            public int[] decodeBandInt(String name, InputStream in,
072:                    BHSDCodec defaultCodec, int count) throws IOException,
073:                    Pack200Exception {
074:                // TODO Might be able to improve this directly.
075:                int[] result = new int[count];
076:                long[] longResult = decodeBandLong(name, in, defaultCodec,
077:                        count);
078:                for (int i = 0; i < count; i++) {
079:                    result[i] = (int) longResult[i];
080:                }
081:                return result;
082:            }
083:
084:            /**
085:             * Decode a band and return an array of <code>int[]</code> values
086:             *
087:             * @param name
088:             *            the name of the band (primarily for logging/debugging
089:             *            purposes)
090:             * @param in
091:             *            the InputStream to decode from
092:             * @param defaultCodec
093:             *            the default codec for this band
094:             * @param counts
095:             *            the numbers of elements to read for each int array within the
096:             *            array to be returned
097:             * @return an array of decoded <code>int[]</code> values
098:             * @throws IOException
099:             *             if there is a problem reading from the underlying input
100:             *             stream
101:             * @throws Pack200Exception
102:             *             if there is a problem decoding the value or that the value is
103:             *             invalid
104:             */
105:            public int[][] decodeBandInt(String name, InputStream in,
106:                    BHSDCodec defaultCodec, int[] counts) throws IOException,
107:                    Pack200Exception {
108:                int[][] result = new int[counts.length][];
109:                int totalCount = 0;
110:                for (int i = 0; i < counts.length; i++) {
111:                    totalCount += counts[i];
112:                }
113:                int[] twoDResult = decodeBandInt(name, in, defaultCodec,
114:                        totalCount);
115:                int index = 0;
116:                for (int i = 0; i < result.length; i++) {
117:                    result[i] = new int[counts[i]];
118:                    for (int j = 0; j < result[i].length; j++) {
119:                        result[i][j] = twoDResult[index];
120:                        index++;
121:                    }
122:                }
123:                return result;
124:            }
125:
126:            /**
127:             * Decode a band and return an array of <code>long</code> values
128:             *
129:             * @param name
130:             *            the name of the band (primarily for logging/debugging
131:             *            purposes)
132:             * @param in
133:             *            the InputStream to decode from
134:             * @param codec
135:             *            the default codec for this band
136:             * @param count
137:             *            the number of elements to read
138:             * @return an array of decoded <code>long</code> values
139:             * @throws IOException
140:             *             if there is a problem reading from the underlying input
141:             *             stream
142:             * @throws Pack200Exception
143:             *             if there is a problem decoding the value or that the value is
144:             *             invalid
145:             */
146:            public long[] decodeBandLong(String name, InputStream in,
147:                    BHSDCodec codec, int count) throws IOException,
148:                    Pack200Exception {
149:                if (codec.getB() == 1 || count == 0) {
150:                    return codec.decode(count, in);
151:                }
152:                long[] getFirst = codec.decode(1, in);
153:                if (getFirst.length == 0) {
154:                    return getFirst;
155:                }
156:                long first = getFirst[0];
157:                if (codec.isSigned() && first >= -256 && first <= -1) {
158:                    // Non-default codec should be used
159:                    Codec nonDefaultCodec = CodecEncoding.getCodec(
160:                            (int) (-1 - first), header
161:                                    .getBandHeadersInputStream(), codec);
162:                    return nonDefaultCodec.decode(count, in);
163:                } else if (!codec.isSigned() && first >= codec.getL()
164:                        && first <= codec.getL() + 255) {
165:                    // Non-default codec should be used
166:                    Codec nonDefaultCodec = CodecEncoding.getCodec((int) first
167:                            - codec.getL(), header.getBandHeadersInputStream(),
168:                            codec);
169:                    return nonDefaultCodec.decode(count, in);
170:                } else {
171:                    // First element should not be discarded
172:                    return codec.decode(count - 1, in, first);
173:                }
174:            }
175:
176:            public byte[] encodeBandLong(long[] data, BHSDCodec codec)
177:                    throws IOException, Pack200Exception {
178:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
179:                for (int i = 0; i < data.length; i++) {
180:                    baos.write(codec.encode(data[i], i == 0 ? 0 : data[i - 1]));
181:                }
182:                return baos.toByteArray();
183:            }
184:
185:            public long[] parseFlags(String name, InputStream in, int count,
186:                    BHSDCodec codec, boolean hasHi) throws IOException,
187:                    Pack200Exception {
188:                return parseFlags(name, in, new int[] { count }, (hasHi ? codec
189:                        : null), codec)[0];
190:            }
191:
192:            public long[][] parseFlags(String name, InputStream in,
193:                    int counts[], BHSDCodec codec, boolean hasHi)
194:                    throws IOException, Pack200Exception {
195:                return parseFlags(name, in, counts, (hasHi ? codec : null),
196:                        codec);
197:            }
198:
199:            public long[] parseFlags(String name, InputStream in, int count,
200:                    BHSDCodec hiCodec, BHSDCodec loCodec) throws IOException,
201:                    Pack200Exception {
202:                return parseFlags(name, in, new int[] { count }, hiCodec,
203:                        loCodec)[0];
204:            }
205:
206:            public long[][] parseFlags(String name, InputStream in,
207:                    int counts[], BHSDCodec hiCodec, BHSDCodec loCodec)
208:                    throws IOException, Pack200Exception {
209:                int count = counts.length;
210:                if (count == 0) {
211:                    return new long[][] { {} };
212:                }
213:                int sum = 0;
214:                long[][] result = new long[count][];
215:                for (int i = 0; i < count; i++) {
216:                    result[i] = new long[counts[i]];
217:                    sum += counts[i];
218:                }
219:                long[] hi = null;
220:                int[] lo;
221:                if (hiCodec != null) {
222:                    hi = decodeBandLong(name, in, hiCodec, sum);
223:                    lo = decodeBandInt(name, in, loCodec, sum);
224:                } else {
225:                    lo = decodeBandInt(name, in, loCodec, sum);
226:                }
227:
228:                int index = 0;
229:                for (int i = 0; i < result.length; i++) {
230:                    for (int j = 0; j < result[i].length; j++) {
231:                        if (hi != null) {
232:                            result[i][j] = (hi[index] << 32) | lo[index];
233:                        } else {
234:                            result[i][j] = lo[index];
235:                        }
236:                        index++;
237:                    }
238:                }
239:
240:                // TODO Remove debugging code
241:                debug("Parsed *" + name + " (" + result.length + ")");
242:                return result;
243:            }
244:
245:            /**
246:             * Helper method to parse <i>count</i> references from <code>in</code>,
247:             * using <code>codec</code> to decode the values as indexes into
248:             * <code>reference</code> (which is populated prior to this call). An
249:             * exception is thrown if a decoded index falls outside the range
250:             * [0..reference.length-1].
251:             *
252:             * @param name
253:             *            the band name
254:             * @param in
255:             *            the input stream to read from
256:             * @param codec
257:             *            the codec to use for decoding
258:             * @param count
259:             *            the number of references to decode
260:             * @param reference
261:             *            the array of values to use for the indexes; often
262:             *            {@link #cpUTF8}
263:             *
264:             * @throws IOException
265:             *             if a problem occurs during reading from the underlying stream
266:             * @throws Pack200Exception
267:             *             if a problem occurs with an unexpected value or unsupported
268:             *             codec
269:             */
270:            public String[] parseReferences(String name, InputStream in,
271:                    BHSDCodec codec, int count, String[] reference)
272:                    throws IOException, Pack200Exception {
273:                return parseReferences(name, in, codec, new int[] { count },
274:                        reference)[0];
275:            }
276:
277:            /**
278:             * Helper method to parse <i>count</i> references from <code>in</code>,
279:             * using <code>codec</code> to decode the values as indexes into
280:             * <code>reference</code> (which is populated prior to this call). An
281:             * exception is thrown if a decoded index falls outside the range
282:             * [0..reference.length-1]. Unlike the other parseReferences, this
283:             * post-processes the result into an array of results.
284:             *
285:             * @param name
286:             *            TODO
287:             * @param in
288:             *            the input stream to read from
289:             * @param codec
290:             *            the codec to use for decoding
291:             * @param count
292:             *            the number of references to decode
293:             * @param reference
294:             *            the array of values to use for the indexes; often
295:             *            {@link #cpUTF8}
296:             *
297:             * @throws IOException
298:             *             if a problem occurs during reading from the underlying stream
299:             * @throws Pack200Exception
300:             *             if a problem occurs with an unexpected value or unsupported
301:             *             codec
302:             */
303:            public String[][] parseReferences(String name, InputStream in,
304:                    BHSDCodec codec, int counts[], String[] reference)
305:                    throws IOException, Pack200Exception {
306:                int count = counts.length;
307:                if (count == 0) {
308:                    return new String[][] { {} };
309:                }
310:                String[][] result = new String[count][];
311:                int sum = 0;
312:                for (int i = 0; i < count; i++) {
313:                    result[i] = new String[counts[i]];
314:                    sum += counts[i];
315:                }
316:                // TODO Merge the decode and parsing of a multiple structure into one
317:                String[] result1 = new String[sum];
318:                int[] indices = decodeBandInt(name, in, codec, sum,
319:                        reference.length - 1);
320:                for (int i1 = 0; i1 < sum; i1++) {
321:                    int index = indices[i1];
322:                    if (index < 0 || index >= reference.length)
323:                        throw new Pack200Exception(
324:                                "Something has gone wrong during parsing references, index = "
325:                                        + index + ", array size = "
326:                                        + reference.length);
327:                    result1[i1] = reference[index];
328:                }
329:                String[] refs = result1;
330:                // TODO Merge the decode and parsing of a multiple structure into one
331:                int pos = 0;
332:                for (int i = 0; i < count; i++) {
333:                    int num = counts[i];
334:                    result[i] = new String[num];
335:                    System.arraycopy(refs, pos, result[i], 0, num);
336:                    pos += num;
337:                }
338:                return result;
339:            }
340:
341:            private int[] decodeBandInt(String name, InputStream in,
342:                    BHSDCodec codec, int count, int maxValue)
343:                    throws IOException, Pack200Exception {
344:                long[] band;
345:                Codec codecUsed = codec;
346:                if (codec.getB() == 1 || count == 0) {
347:                    band = codec.decode(count, in);
348:                } else {
349:                    long[] getFirst = codec.decode(1, in);
350:                    if (getFirst.length == 0) {
351:                        return new int[0];
352:                    }
353:                    long first = getFirst[0];
354:                    if (codec.isSigned() && first >= -256 && first <= -1) {
355:                        // Non-default codec should be used
356:                        codecUsed = CodecEncoding.getCodec((int) (-1 - first),
357:                                header.getBandHeadersInputStream(), codec);
358:                        band = codecUsed.decode(count, in);
359:                    } else if (!codec.isSigned() && first >= codec.getL()
360:                            && first <= codec.getL() + 255) {
361:                        // Non-default codec should be used
362:                        codecUsed = CodecEncoding.getCodec((int) first
363:                                - codec.getL(), header
364:                                .getBandHeadersInputStream(), codec);
365:                        band = codecUsed.decode(count, in);
366:                    } else {
367:                        // First element should not be discarded
368:                        band = codec.decode(count - 1, in, first);
369:                    }
370:                }
371:
372:                int[] returnBand = new int[band.length];
373:                for (int i = 0; i < returnBand.length; i++) {
374:                    returnBand[i] = (int) band[i];
375:                }
376:
377:                /*
378:                 * Note - this is not in the spec, but seems to be used as an
379:                 * optimization by the RI for bands where the minimum and maximum values
380:                 * are known (ie reference bands). It will not hurt any implementation
381:                 * that is following the spec because all the values decoded will be
382:                 * inside the range anyway.
383:                 */
384:                if (codecUsed instanceof  BHSDCodec) {
385:                    for (int i = 0; i < returnBand.length; i++) {
386:                        while (returnBand[i] < 0) {
387:                            returnBand[i] += ((BHSDCodec) codecUsed)
388:                                    .cardinality();
389:                        }
390:                        while (returnBand[i] > maxValue) {
391:                            returnBand[i] -= ((BHSDCodec) codecUsed)
392:                                    .cardinality();
393:                        }
394:                    }
395:                } else if (codecUsed instanceof  PopulationCodec) {
396:                    PopulationCodec popCodec = (PopulationCodec) codecUsed;
397:                    long[] favoured = (long[]) popCodec.getFavoured().clone();
398:                    Arrays.sort(favoured);
399:                    for (int i = 0; i < returnBand.length; i++) {
400:                        if (returnBand[i] < 0 || returnBand[i] > maxValue) {
401:                            boolean favouredValue = Arrays.binarySearch(
402:                                    favoured, returnBand[i]) > -1;
403:                            Codec theCodec = favouredValue ? popCodec
404:                                    .getFavouredCodec() : popCodec
405:                                    .getUnvafouredCodec();
406:                            if (theCodec instanceof  BHSDCodec) {
407:                                while (returnBand[i] < 0) {
408:                                    returnBand[i] += ((BHSDCodec) theCodec)
409:                                            .cardinality();
410:                                }
411:                                while (returnBand[i] > maxValue) {
412:                                    returnBand[i] -= ((BHSDCodec) theCodec)
413:                                            .cardinality();
414:                                }
415:                            }
416:                        }
417:                    }
418:                }
419:
420:                return returnBand;
421:            }
422:
423:            /**
424:             * This is a local debugging message to aid the developer in writing this
425:             * class. It will be removed before going into production. If the property
426:             * 'debug.pack200' is set, this will generate messages to stderr; otherwise,
427:             * it will be silent.
428:             *
429:             * @param message
430:             * @deprecated this should be removed from production code
431:             */
432:            protected void debug(String message) {
433:                segment.debug(message);
434:            }
435:
436:            public CPInteger[] parseCPIntReferences(String name,
437:                    InputStream in, BHSDCodec codec, int count)
438:                    throws IOException, Pack200Exception {
439:                int[] reference = segment.getCpBands().getCpInt();
440:                int[] indices = decodeBandInt(name, in, codec, count,
441:                        reference.length - 1);
442:                CPInteger[] result = new CPInteger[indices.length];
443:                for (int i1 = 0; i1 < count; i1++) {
444:                    int index = indices[i1];
445:                    if (index < 0 || index >= reference.length)
446:                        throw new Pack200Exception(
447:                                "Something has gone wrong during parsing references, index = "
448:                                        + index + ", array size = "
449:                                        + reference.length);
450:                    result[i1] = new CPInteger(new Integer(reference[index]));
451:                }
452:                return result;
453:            }
454:
455:            public CPDouble[] parseCPDoubleReferences(String name,
456:                    InputStream in, BHSDCodec codec, int count)
457:                    throws IOException, Pack200Exception {
458:                double[] reference = segment.getCpBands().getCpDouble();
459:                int[] indices = decodeBandInt(name, in, codec, count,
460:                        reference.length - 1);
461:                CPDouble[] result = new CPDouble[indices.length];
462:                for (int i1 = 0; i1 < count; i1++) {
463:                    int index = indices[i1];
464:                    if (index < 0 || index >= reference.length)
465:                        throw new Pack200Exception(
466:                                "Something has gone wrong during parsing references, index = "
467:                                        + index + ", array size = "
468:                                        + reference.length);
469:                    result[i1] = new CPDouble(new Double(reference[index]));
470:                }
471:                return result;
472:            }
473:
474:            public CPFloat[] parseCPFloatReferences(String name,
475:                    InputStream in, BHSDCodec codec, int count)
476:                    throws IOException, Pack200Exception {
477:                float[] reference = segment.getCpBands().getCpFloat();
478:                int[] indices = decodeBandInt(name, in, codec, count,
479:                        reference.length - 1);
480:                CPFloat[] result = new CPFloat[indices.length];
481:                for (int i1 = 0; i1 < count; i1++) {
482:                    int index = indices[i1];
483:                    if (index < 0 || index >= reference.length)
484:                        throw new Pack200Exception(
485:                                "Something has gone wrong during parsing references, index = "
486:                                        + index + ", array size = "
487:                                        + reference.length);
488:                    result[i1] = new CPFloat(new Float(reference[index]));
489:                }
490:                return result;
491:            }
492:
493:            public CPLong[] parseCPLongReferences(String name, InputStream in,
494:                    BHSDCodec codec, int count) throws IOException,
495:                    Pack200Exception {
496:                long[] reference = segment.getCpBands().getCpLong();
497:                int[] indices = decodeBandInt(name, in, codec, count,
498:                        reference.length - 1);
499:                CPLong[] result = new CPLong[indices.length];
500:                for (int i1 = 0; i1 < count; i1++) {
501:                    int index = indices[i1];
502:                    if (index < 0 || index >= reference.length)
503:                        throw new Pack200Exception(
504:                                "Something has gone wrong during parsing references, index = "
505:                                        + index + ", array size = "
506:                                        + reference.length);
507:                    result[i1] = new CPLong(new Long(reference[index]));
508:                }
509:                return result;
510:            }
511:
512:            public CPUTF8[] parseCPUTF8References(String name, InputStream in,
513:                    BHSDCodec codec, int count) throws IOException,
514:                    Pack200Exception {
515:                String[] reference = segment.getCpBands().getCpUTF8();
516:                int[] indices = decodeBandInt(name, in, codec, count,
517:                        reference.length - 1);
518:                CPUTF8[] result = new CPUTF8[indices.length];
519:                for (int i1 = 0; i1 < count; i1++) {
520:                    int index = indices[i1];
521:                    if (index < 0 || index >= reference.length)
522:                        throw new Pack200Exception(
523:                                "Something has gone wrong during parsing references, index = "
524:                                        + index + ", array size = "
525:                                        + reference.length);
526:                    result[i1] = new CPUTF8(reference[index],
527:                            ClassConstantPool.DOMAIN_UNDEFINED);
528:                }
529:                return result;
530:            }
531:
532:            public CPUTF8[][] parseCPUTF8References(String name,
533:                    InputStream in, BHSDCodec codec, int[] counts)
534:                    throws IOException, Pack200Exception {
535:                String[] reference = segment.getCpBands().getCpUTF8();
536:                CPUTF8[][] result = new CPUTF8[counts.length][];
537:                int sum = 0;
538:                for (int i = 0; i < counts.length; i++) {
539:                    result[i] = new CPUTF8[counts[i]];
540:                    sum += counts[i];
541:                }
542:                CPUTF8[] result1 = new CPUTF8[sum];
543:                int[] indices = decodeBandInt(name, in, codec, sum,
544:                        reference.length - 1);
545:                for (int i1 = 0; i1 < sum; i1++) {
546:                    int index = indices[i1];
547:                    if (index < 0 || index >= reference.length)
548:                        throw new Pack200Exception(
549:                                "Something has gone wrong during parsing references, index = "
550:                                        + index + ", array size = "
551:                                        + reference.length);
552:                    result1[i1] = new CPUTF8(reference[index],
553:                            ClassConstantPool.DOMAIN_UNDEFINED);
554:                }
555:                CPUTF8[] refs = result1;
556:                int pos = 0;
557:                for (int i = 0; i < counts.length; i++) {
558:                    int num = counts[i];
559:                    result[i] = new CPUTF8[num];
560:                    System.arraycopy(refs, pos, result[i], 0, num);
561:                    pos += num;
562:                }
563:                return result;
564:            }
565:
566:            public CPString[] parseCPStringReferences(String name,
567:                    InputStream in, BHSDCodec codec, int count)
568:                    throws IOException, Pack200Exception {
569:                String[] reference = segment.getCpBands().getCpString();
570:                int[] indices = decodeBandInt(name, in, codec, count,
571:                        reference.length - 1);
572:                CPString[] result = new CPString[indices.length];
573:                for (int i1 = 0; i1 < count; i1++) {
574:                    int index = indices[i1];
575:                    if (index < 0 || index >= reference.length)
576:                        throw new Pack200Exception(
577:                                "Something has gone wrong during parsing references, index = "
578:                                        + index + ", array size = "
579:                                        + reference.length);
580:                    result[i1] = new CPString(reference[index]);
581:                }
582:                return result;
583:            }
584:
585:            public CPInterfaceMethodRef[] parseCPInterfaceMethodRefReferences(
586:                    String name, InputStream in, BHSDCodec codec, int count)
587:                    throws IOException, Pack200Exception {
588:                String[] reference = segment.getCpBands().getCpIMethodClass();
589:                String[] descriptors = segment.getCpBands()
590:                        .getCpIMethodDescriptor();
591:                int[] indices = decodeBandInt(name, in, codec, count,
592:                        reference.length - 1);
593:                CPInterfaceMethodRef[] result = new CPInterfaceMethodRef[indices.length];
594:                for (int i1 = 0; i1 < count; i1++) {
595:                    int index = indices[i1];
596:                    if (index < 0 || index >= reference.length)
597:                        throw new Pack200Exception(
598:                                "Something has gone wrong during parsing references, index = "
599:                                        + index + ", array size = "
600:                                        + reference.length);
601:                    result[i1] = new CPInterfaceMethodRef(reference[index],
602:                            descriptors[index]);
603:                }
604:                return result;
605:            }
606:
607:            public CPMethodRef[] parseCPMethodRefReferences(String name,
608:                    InputStream in, BHSDCodec codec, int count)
609:                    throws IOException, Pack200Exception {
610:                String[] reference = segment.getCpBands().getCpMethodClass();
611:                String[] descriptors = segment.getCpBands()
612:                        .getCpMethodDescriptor();
613:                int[] indices = decodeBandInt(name, in, codec, count,
614:                        reference.length - 1);
615:                CPMethodRef[] result = new CPMethodRef[indices.length];
616:                for (int i1 = 0; i1 < count; i1++) {
617:                    int index = indices[i1];
618:                    if (index < 0 || index >= reference.length)
619:                        throw new Pack200Exception(
620:                                "Something has gone wrong during parsing references, index = "
621:                                        + index + ", array size = "
622:                                        + reference.length);
623:                    result[i1] = new CPMethodRef(reference[index],
624:                            descriptors[index]);
625:                }
626:                return result;
627:            }
628:
629:            public CPFieldRef[] parseCPFieldRefReferences(String name,
630:                    InputStream in, BHSDCodec codec, int count)
631:                    throws IOException, Pack200Exception {
632:                String[] reference = segment.getCpBands().getCpFieldClass();
633:                String[] descriptors = segment.getCpBands()
634:                        .getCpFieldDescriptor();
635:                int[] indices = decodeBandInt(name, in, codec, count,
636:                        reference.length - 1);
637:                CPFieldRef[] result = new CPFieldRef[indices.length];
638:                for (int i1 = 0; i1 < count; i1++) {
639:                    int index = indices[i1];
640:                    if (index < 0 || index >= reference.length)
641:                        throw new Pack200Exception(
642:                                "Something has gone wrong during parsing references, index = "
643:                                        + index + ", array size = "
644:                                        + reference.length);
645:                    result[i1] = new CPFieldRef(reference[index],
646:                            descriptors[index]);
647:                }
648:                return result;
649:            }
650:
651:            public CPNameAndType[] parseCPDescriptorReferences(String name,
652:                    InputStream in, BHSDCodec codec, int count)
653:                    throws IOException, Pack200Exception {
654:                String[] reference = segment.getCpBands().getCpDescriptor();
655:                int[] indices = decodeBandInt(name, in, codec, count,
656:                        reference.length - 1);
657:                CPNameAndType[] result = new CPNameAndType[indices.length];
658:                for (int i1 = 0; i1 < count; i1++) {
659:                    int index = indices[i1];
660:                    if (index < 0 || index >= reference.length)
661:                        throw new Pack200Exception(
662:                                "Something has gone wrong during parsing references, index = "
663:                                        + index + ", array size = "
664:                                        + reference.length);
665:                    result[i1] = new CPNameAndType(reference[index]);
666:                }
667:                return result;
668:            }
669:
670:            public CPUTF8[] parseCPSignatureReferences(String name,
671:                    InputStream in, BHSDCodec codec, int count)
672:                    throws IOException, Pack200Exception {
673:                String[] reference = segment.getCpBands().getCpSignature();
674:                int[] indices = decodeBandInt(name, in, codec, count,
675:                        reference.length - 1);
676:                CPUTF8[] result = new CPUTF8[indices.length];
677:                for (int i1 = 0; i1 < count; i1++) {
678:                    int index = indices[i1];
679:                    if (index < 0 || index >= reference.length)
680:                        throw new Pack200Exception(
681:                                "Something has gone wrong during parsing references, index = "
682:                                        + index + ", array size = "
683:                                        + reference.length);
684:                    result[i1] = new CPUTF8(reference[index],
685:                            ClassConstantPool.DOMAIN_UNDEFINED);
686:                }
687:                return result;
688:            }
689:
690:            public CPClass[] parseCPClassReferences(String name,
691:                    InputStream in, BHSDCodec codec, int count)
692:                    throws IOException, Pack200Exception {
693:                String[] reference = segment.getCpBands().getCpClass();
694:                int[] indices = decodeBandInt(name, in, codec, count,
695:                        reference.length - 1);
696:                CPClass[] result = new CPClass[indices.length];
697:                for (int i1 = 0; i1 < count; i1++) {
698:                    int index = indices[i1];
699:                    if (index < 0 || index >= reference.length)
700:                        throw new Pack200Exception(
701:                                "Something has gone wrong during parsing references, index = "
702:                                        + index + ", array size = "
703:                                        + reference.length);
704:                    result[i1] = new CPClass(reference[index]);
705:                }
706:                return result;
707:            }
708:
709:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.