1 4 package com.tc.util; 5 6 import com.tc.bytes.TCByteBuffer; 7 import com.tc.exception.TCRuntimeException; 8 9 import java.nio.ByteBuffer ; 10 11 15 class ByteishWrapper implements ByteishBuffer { 16 17 private ByteBuffer nioBuf; 18 private TCByteBuffer tcBuf; 19 20 private ByteishWrapper() { 21 throw new TCRuntimeException("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("Must specify a ByteBuffer or TCByteBuffer"); 31 } 32 } 33 34 public byte get(int position) { 35 return nioBuf != null ? nioBuf.get(position) : tcBuf.get(position); 36 } 37 38 public int limit() { 39 return nioBuf != null ? nioBuf.limit() : tcBuf.limit(); 40 } 41 42 } | Popular Tags |