01: /**
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */package com.tc.util;
04:
05: import com.tc.bytes.TCByteBuffer;
06: import com.tc.exception.TCRuntimeException;
07:
08: import java.nio.ByteBuffer;
09:
10: /**
11: * Only wanted to write the real dump() implementation once, so this wrapper should mask whether we are working with an
12: * NIO byte buffer or a TC byte buffer.
13: */
14: class ByteishWrapper implements ByteishBuffer {
15:
16: private ByteBuffer nioBuf;
17: private TCByteBuffer tcBuf;
18:
19: private ByteishWrapper() {
20: throw new TCRuntimeException(
21: "Private constructor should not be called");
22: }
23:
24: ByteishWrapper(ByteBuffer nioBuf, TCByteBuffer tcBuf) {
25: if (nioBuf != null) {
26: this .nioBuf = nioBuf;
27: } else if (tcBuf != null) {
28: this .tcBuf = tcBuf;
29: } else {
30: throw new TCRuntimeException(
31: "Must specify a ByteBuffer or TCByteBuffer");
32: }
33: }
34:
35: public byte get(int position) {
36: return nioBuf != null ? nioBuf.get(position) : tcBuf
37: .get(position);
38: }
39:
40: public int limit() {
41: return nioBuf != null ? nioBuf.limit() : tcBuf.limit();
42: }
43:
44: }
|