Source Code Cross Referenced for TCByteBufferImpl.java in  » Net » Terracotta » com » tc » bytes » 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 » Net » Terracotta » com.tc.bytes 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
0003:         * notice. All rights reserved.
0004:         */
0005:        package com.tc.bytes;
0006:
0007:        import com.tc.util.Assert;
0008:        import com.tc.util.State;
0009:
0010:        import java.nio.ByteBuffer;
0011:
0012:        /**
0013:         * @author teck A thin wrapper to a real java.nio.ByteBuffer instance
0014:         */
0015:
0016:        // XXX: Should we wrap the native java.nio overflow, underflow and readOnly exceptions with the TC versions?
0017:        // This would make the TCByteBuffer interface consistent w.r.t. exceptions (whilst being blind to JDK13 vs JDK14)
0018:        public class TCByteBufferImpl implements  TCByteBuffer {
0019:
0020:            private static final State INIT = new State("INIT");
0021:            private static final State CHECKED_OUT = new State("CHECKED_OUT");
0022:            private static final State COMMITTED = new State("COMMITTED");
0023:
0024:            private final ByteBuffer buffer;
0025:            private final TCByteBuffer root;
0026:            private State state = INIT;
0027:
0028:            TCByteBufferImpl(int capacity, boolean direct) {
0029:                if (direct) {
0030:                    buffer = ByteBuffer.allocateDirect(capacity);
0031:                } else {
0032:                    buffer = ByteBuffer.allocate(capacity);
0033:                }
0034:                root = this ;
0035:            }
0036:
0037:            private TCByteBufferImpl(ByteBuffer buf) {
0038:                buffer = buf;
0039:                this .root = null;
0040:            }
0041:
0042:            private TCByteBufferImpl(ByteBuffer buf, TCByteBuffer root) {
0043:                buffer = buf;
0044:                this .root = root;
0045:            }
0046:
0047:            static TCByteBuffer wrap(byte[] data) {
0048:                return new TCByteBufferImpl(ByteBuffer.wrap(data));
0049:            }
0050:
0051:            protected ByteBuffer getBuffer() {
0052:                return buffer;
0053:            }
0054:
0055:            public TCByteBuffer clear() {
0056:                buffer.clear();
0057:                return this ;
0058:            }
0059:
0060:            public int capacity() {
0061:                return buffer.capacity();
0062:            }
0063:
0064:            public int position() {
0065:                return buffer.position();
0066:            }
0067:
0068:            public TCByteBuffer flip() {
0069:                buffer.flip();
0070:                return this ;
0071:            }
0072:
0073:            public boolean hasRemaining() {
0074:                return buffer.hasRemaining();
0075:            }
0076:
0077:            public int limit() {
0078:                return buffer.limit();
0079:            }
0080:
0081:            public TCByteBuffer limit(int newLimit) {
0082:                buffer.limit(newLimit);
0083:                return this ;
0084:            }
0085:
0086:            public TCByteBuffer position(int newPosition) {
0087:                buffer.position(newPosition);
0088:                return this ;
0089:            }
0090:
0091:            public int remaining() {
0092:                return buffer.remaining();
0093:            }
0094:
0095:            public com.tc.bytes.TCByteBuffer rewind() {
0096:                buffer.rewind();
0097:                return this ;
0098:            }
0099:
0100:            public ByteBuffer getNioBuffer() {
0101:                return buffer;
0102:            }
0103:
0104:            public boolean isDirect() {
0105:                return buffer.isDirect();
0106:            }
0107:
0108:            public byte[] array() {
0109:                return buffer.array();
0110:            }
0111:
0112:            public byte get() {
0113:                return buffer.get();
0114:            }
0115:
0116:            public boolean getBoolean() {
0117:                // XXX: Um-- why isn't there a getBoolean in ByteBuffer?
0118:                return buffer.get() > 0;
0119:            }
0120:
0121:            public boolean getBoolean(int index) {
0122:                return buffer.get(index) > 0;
0123:            }
0124:
0125:            public char getChar() {
0126:                return buffer.getChar();
0127:            }
0128:
0129:            public char getChar(int index) {
0130:                return buffer.getChar(index);
0131:            }
0132:
0133:            public double getDouble() {
0134:                return buffer.getDouble();
0135:            }
0136:
0137:            public double getDouble(int index) {
0138:                return buffer.getDouble(index);
0139:            }
0140:
0141:            public float getFloat() {
0142:                return buffer.getFloat();
0143:            }
0144:
0145:            public float getFloat(int index) {
0146:                return buffer.getFloat(index);
0147:            }
0148:
0149:            public int getInt() {
0150:                return buffer.getInt();
0151:            }
0152:
0153:            public int getInt(int index) {
0154:                return buffer.getInt(index);
0155:            }
0156:
0157:            public long getLong() {
0158:                return buffer.getLong();
0159:            }
0160:
0161:            public long getLong(int index) {
0162:                return buffer.getLong(index);
0163:            }
0164:
0165:            public short getShort() {
0166:                return buffer.getShort();
0167:            }
0168:
0169:            public short getShort(int index) {
0170:                return buffer.getShort(index);
0171:            }
0172:
0173:            public TCByteBuffer get(byte[] dst) {
0174:                buffer.get(dst);
0175:                return this ;
0176:            }
0177:
0178:            public TCByteBuffer get(byte[] dst, int offset, int length) {
0179:                buffer.get(dst, offset, length);
0180:                return this ;
0181:            }
0182:
0183:            public byte get(int index) {
0184:                return buffer.get(index);
0185:            }
0186:
0187:            public TCByteBuffer put(byte b) {
0188:                buffer.put(b);
0189:                return this ;
0190:            }
0191:
0192:            public TCByteBuffer put(byte[] src) {
0193:                buffer.put(src);
0194:                return this ;
0195:            }
0196:
0197:            public TCByteBuffer put(byte[] src, int offset, int length) {
0198:                buffer.put(src, offset, length);
0199:                return this ;
0200:            }
0201:
0202:            public TCByteBuffer put(int index, byte b) {
0203:                buffer.put(index, b);
0204:                return this ;
0205:            }
0206:
0207:            public TCByteBuffer putBoolean(boolean b) {
0208:                // XXX: Why isn't there a putBoolean in ByteBuffer?
0209:                buffer.put((b) ? (byte) 1 : (byte) 0);
0210:                return this ;
0211:            }
0212:
0213:            public TCByteBuffer putBoolean(int index, boolean b) {
0214:                buffer.put(index, (b) ? (byte) 1 : (byte) 0);
0215:                return this ;
0216:            }
0217:
0218:            public TCByteBuffer putChar(char c) {
0219:                buffer.putChar(c);
0220:                return this ;
0221:            }
0222:
0223:            public TCByteBuffer putChar(int index, char c) {
0224:                buffer.putChar(index, c);
0225:                return this ;
0226:            }
0227:
0228:            public TCByteBuffer putDouble(double d) {
0229:                buffer.putDouble(d);
0230:                return this ;
0231:            }
0232:
0233:            public TCByteBuffer putDouble(int index, double d) {
0234:                buffer.putDouble(index, d);
0235:                return this ;
0236:            }
0237:
0238:            public TCByteBuffer putFloat(float f) {
0239:                buffer.putFloat(f);
0240:                return this ;
0241:            }
0242:
0243:            public TCByteBuffer putFloat(int index, float f) {
0244:                buffer.putFloat(index, f);
0245:                return this ;
0246:            }
0247:
0248:            public TCByteBuffer putInt(int i) {
0249:                buffer.putInt(i);
0250:                return this ;
0251:            }
0252:
0253:            public TCByteBuffer putInt(int index, int i) {
0254:                buffer.putInt(index, i);
0255:                return this ;
0256:            }
0257:
0258:            public TCByteBuffer putLong(long l) {
0259:                buffer.putLong(l);
0260:                return this ;
0261:            }
0262:
0263:            public TCByteBuffer putLong(int index, long l) {
0264:                buffer.putLong(index, l);
0265:                return this ;
0266:            }
0267:
0268:            public TCByteBuffer putShort(short s) {
0269:                buffer.putShort(s);
0270:                return this ;
0271:            }
0272:
0273:            public TCByteBuffer putShort(int index, short s) {
0274:                buffer.putShort(index, s);
0275:                return this ;
0276:            }
0277:
0278:            public TCByteBuffer duplicate() {
0279:                return new TCByteBufferImpl(buffer.duplicate(), root);
0280:            }
0281:
0282:            public TCByteBuffer put(TCByteBuffer src) {
0283:                buffer.put(src.getNioBuffer());
0284:                return this ;
0285:            }
0286:
0287:            public TCByteBuffer slice() {
0288:                return new TCByteBufferImpl(buffer.slice(), root);
0289:            }
0290:
0291:            public int arrayOffset() {
0292:                return buffer.arrayOffset();
0293:            }
0294:
0295:            public TCByteBuffer asReadOnlyBuffer() {
0296:                return new TCByteBufferImpl(buffer.asReadOnlyBuffer(), root);
0297:            }
0298:
0299:            public boolean isReadOnly() {
0300:                return buffer.isReadOnly();
0301:            }
0302:
0303:            public String toString() {
0304:                return (buffer == null) ? "TCByteBufferJDK14(null buffer)"
0305:                        : "TCByteBufferJDK14@" + System.identityHashCode(this )
0306:                                + "(" + buffer.toString() + ")";
0307:            }
0308:
0309:            public boolean hasArray() {
0310:                return buffer.hasArray();
0311:            }
0312:
0313:            // Can be called only once on any of the views and the root is gone
0314:            public void recycle() {
0315:                if (root != null) {
0316:                    TCByteBufferFactory.returnBuffer(root.reInit());
0317:                }
0318:            }
0319:
0320:            public TCByteBuffer reInit() {
0321:                clear();
0322:                return this ;
0323:            }
0324:
0325:            public final TCByteBuffer get(int index, byte[] dst) {
0326:                return get(index, dst, 0, dst.length);
0327:            }
0328:
0329:            public final TCByteBuffer get(int index, byte[] dst, int offset,
0330:                    int length) {
0331:                final int origPosition = position();
0332:
0333:                try {
0334:                    position(index);
0335:                    get(dst, offset, length);
0336:                } finally {
0337:                    position(origPosition);
0338:                }
0339:
0340:                return this ;
0341:            }
0342:
0343:            public final TCByteBuffer put(int index, byte[] src) {
0344:                return put(index, src, 0, src.length);
0345:            }
0346:
0347:            public final TCByteBuffer put(int index, byte[] src, int offset,
0348:                    int length) {
0349:                final int origPosition = position();
0350:
0351:                try {
0352:                    position(index);
0353:                    put(src, offset, length);
0354:                } finally {
0355:                    position(origPosition);
0356:                }
0357:
0358:                return this ;
0359:            }
0360:
0361:            public final TCByteBuffer putUint(long i) {
0362:                if ((i > 0xFFFFFFFFL) || (i < 0L)) {
0363:                    // make code formatter sane
0364:                    throw new IllegalArgumentException(
0365:                            "Unsigned integer value must be positive and <= (2^32)-1");
0366:                }
0367:
0368:                put((byte) ((i >> 24) & 0x000000FF));
0369:                put((byte) ((i >> 16) & 0x000000FF));
0370:                put((byte) ((i >> 8) & 0x000000FF));
0371:                put((byte) (i & 0x000000FF));
0372:
0373:                return this ;
0374:            }
0375:
0376:            public final TCByteBuffer putUint(int index, long i) {
0377:                final int origPosition = position();
0378:
0379:                try {
0380:                    position(index);
0381:                    putUint(i);
0382:                } finally {
0383:                    position(origPosition);
0384:                }
0385:
0386:                return this ;
0387:            }
0388:
0389:            public final TCByteBuffer putUshort(int s) {
0390:                if ((s > 0x0000FFFF) || (s < 0)) {
0391:                    throw new IllegalArgumentException(
0392:                            "Unsigned integer value must be positive and <= (2^16)-1");
0393:                }
0394:
0395:                put((byte) ((s >> 8) & 0x000000FF));
0396:                put((byte) (s & 0x000000FF));
0397:
0398:                return this ;
0399:            }
0400:
0401:            public final TCByteBuffer putUshort(int index, int s) {
0402:                final int origPosition = position();
0403:
0404:                try {
0405:                    position(index);
0406:                    putUshort(s);
0407:                } finally {
0408:                    position(origPosition);
0409:                }
0410:
0411:                return this ;
0412:            }
0413:
0414:            public final long getUint() {
0415:                long rv = 0;
0416:
0417:                rv += ((long) (get() & 0xFF) << 24);
0418:                rv += ((get() & 0xFF) << 16);
0419:                rv += ((get() & 0xFF) << 8);
0420:                rv += ((get() & 0xFF));
0421:
0422:                return rv;
0423:            }
0424:
0425:            public final long getUint(int index) {
0426:                final int origPosition = position();
0427:
0428:                try {
0429:                    position(index);
0430:                    return getUint();
0431:                } finally {
0432:                    position(origPosition);
0433:                }
0434:            }
0435:
0436:            public final int getUshort() {
0437:                int rv = 0;
0438:
0439:                rv += ((get() & 0xFF) << 8);
0440:                rv += ((get() & 0xFF));
0441:
0442:                Assert.eval((rv >= 0) && (rv <= 0xFFFF));
0443:
0444:                return rv;
0445:            }
0446:
0447:            public final int getUshort(int index) {
0448:                final int origPosition = position();
0449:
0450:                try {
0451:                    position(index);
0452:                    return getUshort();
0453:                } finally {
0454:                    position(origPosition);
0455:                }
0456:            }
0457:
0458:            public final short getUbyte() {
0459:                return (short) (get() & 0xFF);
0460:            }
0461:
0462:            public final short getUbyte(int index) {
0463:                final int origPosition = position();
0464:
0465:                try {
0466:                    position(index);
0467:                    return getUbyte();
0468:                } finally {
0469:                    position(origPosition);
0470:                }
0471:            }
0472:
0473:            public final TCByteBuffer putUbyte(int index, short value) {
0474:                final int origPosition = position();
0475:
0476:                try {
0477:                    position(index);
0478:                    putUbyte(value);
0479:                } finally {
0480:                    position(origPosition);
0481:                }
0482:
0483:                return this ;
0484:            }
0485:
0486:            public final TCByteBuffer putUbyte(short value) {
0487:                if ((value < 0) || (value > 0xFF)) {
0488:                    throw new IllegalArgumentException(
0489:                            "Unsigned byte value must in range 0-255 inclusive");
0490:                }
0491:                put((byte) (value & 0xFF));
0492:                return this ;
0493:            }
0494:
0495:            public void commit() {
0496:                if (state == COMMITTED) {
0497:                    throw new AssertionError("Already commited");
0498:                }
0499:                state = COMMITTED;
0500:            }
0501:
0502:            public void checkedOut() {
0503:                if (state == CHECKED_OUT) {
0504:                    throw new AssertionError("Already checked out");
0505:                }
0506:                state = CHECKED_OUT;
0507:            }
0508:
0509:            /* This is the debug version. PLEASE DONT DELETE */
0510:
0511:            // private static final TCLogger logger = TCLogging.getLogger(TCByteBufferJDK14.class);
0512:            //
0513:            // private final ByteBuffer buffer;
0514:            // private final TCByteBufferJDK14 root;
0515:            // private List childs;
0516:            // private static final boolean debug = true;
0517:            // private static final boolean debugFinalize = false;
0518:            // private ActivityMonitor monitor;
0519:            //
0520:            // TCByteBufferJDK14(int capacity, boolean direct) {
0521:            // if (direct) {
0522:            // buffer = ByteBuffer.allocateDirect(capacity);
0523:            // } else {
0524:            // buffer = ByteBuffer.allocate(capacity);
0525:            // }
0526:            // root = this;
0527:            // if (debug) {
0528:            // childs = new ArrayList();
0529:            // monitor = new ActivityMonitor();
0530:            // monitor.addActivity("TCBB", "Created");
0531:            // }
0532:            // }
0533:            //
0534:            // private TCByteBufferJDK14(ByteBuffer buf) {
0535:            // buffer = buf;
0536:            // this.root = null;
0537:            // if (debug) childs = new ArrayList();
0538:            // }
0539:            //
0540:            // private TCByteBufferJDK14(ByteBuffer buf, TCByteBufferJDK14 root) {
0541:            // buffer = buf;
0542:            // childs = null;
0543:            // this.root = root;
0544:            // if (debug) this.root.addChild(this);
0545:            // }
0546:            //
0547:            // private void addChild(TCByteBufferJDK14 child) {
0548:            // if (debug) childs.add(child);
0549:            // }
0550:            //
0551:            // static TCByteBufferJDK14 wrap(byte[] data) {
0552:            // return new TCByteBufferJDK14(ByteBuffer.wrap(data));
0553:            // }
0554:            //
0555:            // protected ByteBuffer getBuffer() {
0556:            // if (debug) {
0557:            // checkState();
0558:            // logGet();
0559:            // }
0560:            // return buffer;
0561:            // }
0562:            //
0563:            // public TCByteBuffer clear() {
0564:            // buffer.clear();
0565:            // if (debug) {
0566:            // childs.clear();
0567:            // monitor.clear();
0568:            // }
0569:            // return this;
0570:            // }
0571:            //
0572:            // public int capacity() {
0573:            // if (debug) checkState();
0574:            // return buffer.capacity();
0575:            // }
0576:            //
0577:            // public int position() {
0578:            // if (debug) checkState();
0579:            // return buffer.position();
0580:            // }
0581:            //
0582:            // public TCByteBuffer flip() {
0583:            // if (debug) checkState();
0584:            // buffer.flip();
0585:            // return this;
0586:            // }
0587:            //
0588:            // private void checkState() {
0589:            // if (debug && this != root) {
0590:            // // This doesnt check for the root itself, I dont know how to check for the root itself being modified once check
0591:            // // back in
0592:            // Assert.assertNotNull(root);
0593:            // Assert.assertTrue(root.isChild(this));
0594:            // }
0595:            // }
0596:            //
0597:            // private boolean isChild(TCByteBufferJDK14 child) {
0598:            // return childs.contains(child);
0599:            // }
0600:            //
0601:            // public boolean hasRemaining() {
0602:            // if (debug) checkState();
0603:            // return buffer.hasRemaining();
0604:            // }
0605:            //
0606:            // public int limit() {
0607:            // if (debug) checkState();
0608:            // return buffer.limit();
0609:            // }
0610:            //
0611:            // public TCByteBuffer limit(int newLimit) {
0612:            // if (debug) checkState();
0613:            // buffer.limit(newLimit);
0614:            // return this;
0615:            // }
0616:            //
0617:            // public TCByteBuffer position(int newPosition) {
0618:            // if (debug) checkState();
0619:            // buffer.position(newPosition);
0620:            // return this;
0621:            // }
0622:            //
0623:            // public int remaining() {
0624:            // if (debug) checkState();
0625:            // return buffer.remaining();
0626:            // }
0627:            //
0628:            // public com.tc.bytes.TCByteBuffer rewind() {
0629:            // if (debug) checkState();
0630:            // buffer.rewind();
0631:            // return this;
0632:            // }
0633:            //
0634:            // public boolean isNioBuffer() {
0635:            // return true;
0636:            // }
0637:            //
0638:            // public Object getNioBuffer() {
0639:            // if (debug) checkState();
0640:            // return buffer;
0641:            // }
0642:            //
0643:            // public boolean isDirect() {
0644:            // return buffer.isDirect();
0645:            // }
0646:            //
0647:            // public byte[] array() {
0648:            // // Not fool proof
0649:            // if (debug) checkState();
0650:            // return buffer.array();
0651:            // }
0652:            //
0653:            // public byte get() {
0654:            // if (debug) {
0655:            // checkState();
0656:            // logGet();
0657:            // }
0658:            // return buffer.get();
0659:            // }
0660:            //
0661:            // public boolean getBoolean() {
0662:            // // XXX: Um-- why isn't there a getBoolean in ByteBuffer?
0663:            // if (debug) {
0664:            // checkState();
0665:            // logGet();
0666:            // }
0667:            // return buffer.get() > 0;
0668:            // }
0669:            //
0670:            // public boolean getBoolean(int index) {
0671:            // if (debug) {
0672:            // checkState();
0673:            // logGet();
0674:            // }
0675:            // return buffer.get(index) > 0;
0676:            // }
0677:            //
0678:            // public char getChar() {
0679:            // if (debug) {
0680:            // checkState();
0681:            // logGet();
0682:            // }
0683:            // return buffer.getChar();
0684:            // }
0685:            //
0686:            // public char getChar(int index) {
0687:            // if (debug) {
0688:            // checkState();
0689:            // logGet();
0690:            // }
0691:            // return buffer.getChar(index);
0692:            // }
0693:            //
0694:            // public double getDouble() {
0695:            // if (debug) {
0696:            // checkState();
0697:            // logGet();
0698:            // }
0699:            // return buffer.getDouble();
0700:            // }
0701:            //
0702:            // public double getDouble(int index) {
0703:            // if (debug) {
0704:            // checkState();
0705:            // logGet();
0706:            // }
0707:            // return buffer.getDouble(index);
0708:            // }
0709:            //
0710:            // public float getFloat() {
0711:            // if (debug) {
0712:            // checkState();
0713:            // logGet();
0714:            // }
0715:            // return buffer.getFloat();
0716:            // }
0717:            //
0718:            // public float getFloat(int index) {
0719:            // if (debug) {
0720:            // checkState();
0721:            // logGet();
0722:            // }
0723:            // return buffer.getFloat(index);
0724:            // }
0725:            //
0726:            // public int getInt() {
0727:            // if (debug) {
0728:            // checkState();
0729:            // logGet();
0730:            // }
0731:            // return buffer.getInt();
0732:            // }
0733:            //
0734:            // public int getInt(int index) {
0735:            // if (debug) {
0736:            // checkState();
0737:            // logGet();
0738:            // }
0739:            // return buffer.getInt(index);
0740:            // }
0741:            //
0742:            // public long getLong() {
0743:            // if (debug) {
0744:            // checkState();
0745:            // logGet();
0746:            // }
0747:            // return buffer.getLong();
0748:            // }
0749:            //
0750:            // public long getLong(int index) {
0751:            // if (debug) {
0752:            // checkState();
0753:            // logGet();
0754:            // }
0755:            // return buffer.getLong(index);
0756:            // }
0757:            //
0758:            // public short getShort() {
0759:            // if (debug) {
0760:            // checkState();
0761:            // logGet();
0762:            // }
0763:            // return buffer.getShort();
0764:            // }
0765:            //
0766:            // public short getShort(int index) {
0767:            // if (debug) {
0768:            // checkState();
0769:            // logGet();
0770:            // }
0771:            // return buffer.getShort(index);
0772:            // }
0773:            //
0774:            // public TCByteBuffer get(byte[] dst) {
0775:            // if (debug) {
0776:            // checkState();
0777:            // logGet();
0778:            // }
0779:            // buffer.get(dst);
0780:            // return this;
0781:            // }
0782:            //
0783:            // public TCByteBuffer get(byte[] dst, int offset, int length) {
0784:            // if (debug) {
0785:            // checkState();
0786:            // logGet();
0787:            // }
0788:            // buffer.get(dst, offset, length);
0789:            // return this;
0790:            // }
0791:            //
0792:            // public byte get(int index) {
0793:            // if (debug) {
0794:            // checkState();
0795:            // logGet();
0796:            // }
0797:            // return buffer.get(index);
0798:            // }
0799:            //
0800:            // public TCByteBuffer put(byte b) {
0801:            // if (debug) {
0802:            // checkState();
0803:            // logPut();
0804:            // }
0805:            // buffer.put(b);
0806:            // return this;
0807:            // }
0808:            //
0809:            // public TCByteBuffer put(byte[] src) {
0810:            // if (debug) {
0811:            // checkState();
0812:            // logPut();
0813:            // }
0814:            // buffer.put(src);
0815:            // return this;
0816:            // }
0817:            //
0818:            // public TCByteBuffer put(byte[] src, int offset, int length) {
0819:            // if (debug) {
0820:            // checkState();
0821:            // logPut();
0822:            // }
0823:            // buffer.put(src, offset, length);
0824:            // return this;
0825:            // }
0826:            //
0827:            // public TCByteBuffer put(int index, byte b) {
0828:            // if (debug) {
0829:            // checkState();
0830:            // logPut();
0831:            // }
0832:            // buffer.put(index, b);
0833:            // return this;
0834:            // }
0835:            //
0836:            // public TCByteBuffer putBoolean(boolean b) {
0837:            // // XXX: Why isn't there a putBoolean in ByteBuffer?
0838:            // if (debug) {
0839:            // checkState();
0840:            // logPut();
0841:            // }
0842:            // buffer.put((b) ? (byte) 1 : (byte) 0);
0843:            // return this;
0844:            // }
0845:            //
0846:            // public TCByteBuffer putBoolean(int index, boolean b) {
0847:            // if (debug) {
0848:            // checkState();
0849:            // logPut();
0850:            // }
0851:            // buffer.put(index, (b) ? (byte) 1 : (byte) 0);
0852:            // return this;
0853:            // }
0854:            //
0855:            // public TCByteBuffer putChar(char c) {
0856:            // if (debug) {
0857:            // checkState();
0858:            // logPut();
0859:            // }
0860:            // buffer.putChar(c);
0861:            // return this;
0862:            // }
0863:            //
0864:            // public TCByteBuffer putChar(int index, char c) {
0865:            // if (debug) {
0866:            // checkState();
0867:            // logPut();
0868:            // }
0869:            // buffer.putChar(index, c);
0870:            // return this;
0871:            // }
0872:            //
0873:            // public TCByteBuffer putDouble(double d) {
0874:            // if (debug) {
0875:            // checkState();
0876:            // logPut();
0877:            // }
0878:            // buffer.putDouble(d);
0879:            // return this;
0880:            // }
0881:            //
0882:            // public TCByteBuffer putDouble(int index, double d) {
0883:            // if (debug) {
0884:            // checkState();
0885:            // logPut();
0886:            // }
0887:            // buffer.putDouble(index, d);
0888:            // return this;
0889:            // }
0890:            //
0891:            // public TCByteBuffer putFloat(float f) {
0892:            // if (debug) {
0893:            // checkState();
0894:            // logPut();
0895:            // }
0896:            // buffer.putFloat(f);
0897:            // return this;
0898:            // }
0899:            //
0900:            // public TCByteBuffer putFloat(int index, float f) {
0901:            // if (debug) {
0902:            // checkState();
0903:            // logPut();
0904:            // }
0905:            // buffer.putFloat(index, f);
0906:            // return this;
0907:            // }
0908:            //
0909:            // public TCByteBuffer putInt(int i) {
0910:            // if (debug) {
0911:            // checkState();
0912:            // logPut();
0913:            // }
0914:            // buffer.putInt(i);
0915:            // return this;
0916:            // }
0917:            //
0918:            // public TCByteBuffer putInt(int index, int i) {
0919:            // if (debug) {
0920:            // checkState();
0921:            // logPut();
0922:            // }
0923:            // buffer.putInt(index, i);
0924:            // return this;
0925:            // }
0926:            //
0927:            // public TCByteBuffer putLong(long l) {
0928:            // if (debug) {
0929:            // checkState();
0930:            // logPut();
0931:            // }
0932:            // buffer.putLong(l);
0933:            // return this;
0934:            // }
0935:            //
0936:            // public TCByteBuffer putLong(int index, long l) {
0937:            // if (debug) checkState();
0938:            // logPut();
0939:            // buffer.putLong(index, l);
0940:            // return this;
0941:            // }
0942:            //
0943:            // public TCByteBuffer putShort(short s) {
0944:            // if (debug) {
0945:            // checkState();
0946:            // logPut();
0947:            // }
0948:            // buffer.putShort(s);
0949:            // return this;
0950:            // }
0951:            //
0952:            // public TCByteBuffer putShort(int index, short s) {
0953:            // if (debug) {
0954:            // checkState();
0955:            // logPut();
0956:            // }
0957:            // buffer.putShort(index, s);
0958:            // return this;
0959:            // }
0960:            //
0961:            // public TCByteBuffer duplicate() {
0962:            // if (debug) checkState();
0963:            // return new TCByteBufferJDK14(buffer.duplicate(), root);
0964:            // }
0965:            //
0966:            // public TCByteBuffer put(TCByteBuffer src) {
0967:            // if (debug) {
0968:            // checkState();
0969:            // logPut();
0970:            // }
0971:            //
0972:            // if (!src.isNioBuffer()) { throw new IllegalArgumentException("src buffer is not backed by a java.nio.ByteBuffer");
0973:            // }
0974:            //
0975:            // buffer.put((ByteBuffer) src.getNioBuffer());
0976:            // return this;
0977:            // }
0978:            //
0979:            // public TCByteBuffer slice() {
0980:            // if (debug) checkState();
0981:            // return new TCByteBufferJDK14(buffer.slice(), root);
0982:            // }
0983:            //
0984:            // public int arrayOffset() {
0985:            // if (debug) checkState();
0986:            // return buffer.arrayOffset();
0987:            // }
0988:            //
0989:            // public TCByteBuffer asReadOnlyBuffer() {
0990:            // if (debug) checkState();
0991:            // return new TCByteBufferJDK14(buffer.asReadOnlyBuffer(), root);
0992:            // }
0993:            //
0994:            // public boolean isReadOnly() {
0995:            // if (debug) checkState();
0996:            // return buffer.isReadOnly();
0997:            // }
0998:            //
0999:            // public String toString() {
1000:            // if (debug) checkState();
1001:            // return (buffer == null) ? "null buffer" : buffer.toString();
1002:            // }
1003:            //
1004:            // public boolean hasArray() {
1005:            // if (debug) checkState();
1006:            // return buffer.hasArray();
1007:            // }
1008:            //
1009:            // // Can be called only once on any of the views and the root is gone
1010:            // public void recycle() {
1011:            // if (debug) checkState();
1012:            // if(root != null) TCByteBufferFactory.returnBuffer(root.reInit());
1013:            // }
1014:            //
1015:            // private TCByteBufferJDK14 reInit() {
1016:            // clear();
1017:            // return this;
1018:            // }
1019:            //
1020:            // void logGet() {
1021:            // if(root !=null) {
1022:            // root.monitor.clear();
1023:            // root.monitor.addActivity("TCBB", "get");
1024:            // }
1025:            // }
1026:            //
1027:            // void logPut() {
1028:            // if(root !=null) {
1029:            // root.monitor.clear();
1030:            // root.monitor.addActivity("TCBB", "put");
1031:            // }
1032:            // }
1033:            //
1034:            // static int count;
1035:            // static {
1036:            // CommonShutDownHook.addShutdownHook(new Runnable() {
1037:            // public void run() {
1038:            // logger.info("No of Root Buffers finalized = " + count);
1039:            // }
1040:            // });
1041:            // }
1042:            //
1043:            // public void finalize() {
1044:            // if (this == root) {
1045:            // count++;
1046:            // if (debugFinalize) monitor.printActivityFor("TCBB");
1047:            // }
1048:            // }
1049:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.