本文整理汇总了Java中java.nio.ByteBuffer.asCharBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.asCharBuffer方法的具体用法?Java ByteBuffer.asCharBuffer怎么用?Java ByteBuffer.asCharBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.asCharBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MDSWriter
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public MDSWriter( final OutputStream out , final Configuration config ) throws IOException{
this.out = out;
int blockSize = config.getInt( "block.size" , 1024 * 1024 * 256 );
blockMaker = FindBlockMaker.get( config.get( "block.maker.class" , BlockSkipPredicateBlockMaker.class.getName() ) );
blockMaker.setup( blockSize , config );
String blockMakerClassName = blockMaker.getReaderClassName();
int classNameLength = blockMakerClassName.length() * Character.BYTES;
byte[] header = new byte[MAGIC.length + Integer.BYTES + Integer.BYTES + classNameLength ];
ByteBuffer wrapBuffer = ByteBuffer.wrap( header );
CharBuffer viewCharBuffer = wrapBuffer.asCharBuffer();
int offset = 0;
wrapBuffer.put( MAGIC , 0 , MAGIC.length );
offset += MAGIC.length;
wrapBuffer.putInt( offset , blockSize );
offset += Integer.BYTES;
wrapBuffer.putInt( offset , classNameLength );
offset += Integer.BYTES;
viewCharBuffer.position( offset / Character.BYTES );
viewCharBuffer.put( blockMakerClassName.toCharArray() );
blockMaker.appendHeader( header );
}
示例2: testGetChar
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Test
public void testGetChar() {
ByteBuffer bb = ByteBuffer.allocate(10);
CharBuffer cb = bb.asCharBuffer();
cb.put("abcde");
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
char c = bs.getChar();
assertEquals('a', c);
assertEquals(2, bs.position());
c = bs.getChar();
assertEquals('b', c);
assertEquals(4, bs.position());
bs.position(8);
c = bs.getChar();
assertEquals('e', c);
assertEquals(10, bs.position());
try {
bs.getChar();
fail("expected BufferUnderflowException");
} catch (BufferUnderflowException expected) {
}
}
示例3: testGetCharInt
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Test
public void testGetCharInt() {
ByteBuffer bb = ByteBuffer.allocate(10);
CharBuffer cb = bb.asCharBuffer();
cb.put("abcde");
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
bs.position(3);
char c = bs.getChar(0);
assertEquals('a', c);
assertEquals(3, bs.position());
c = bs.getChar(2);
assertEquals('b', c);
assertEquals(3, bs.position());
c = bs.getChar(8);
assertEquals('e', c);
assertEquals(3, bs.position());
try {
bs.getChar(10);
fail("expected IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException expected) {
}
}
示例4: readFileHeader
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private FileHeaderMeta readFileHeader( final InputStream in ) throws IOException{
byte[] magic = new byte[MAGIC.length];
InputStreamUtils.read( in , magic , 0 , MAGIC.length );
if( ! Arrays.equals( magic , MAGIC) ){
throw new IOException( "Invalid binary." );
}
byte[] blockSize = new byte[Integer.BYTES];
ByteBuffer wrapBuffer = ByteBuffer.wrap( blockSize );
InputStreamUtils.read( in , blockSize , 0 , Integer.BYTES );
byte[] blockClassLength = new byte[Integer.BYTES];
ByteBuffer wrapLengthBuffer = ByteBuffer.wrap( blockClassLength );
InputStreamUtils.read( in , blockClassLength , 0 , Integer.BYTES );
int classNameSize = wrapLengthBuffer.getInt( 0 );
byte[] blockClass = new byte[classNameSize];
InputStreamUtils.read( in , blockClass , 0 , classNameSize );
ByteBuffer classNameBuffer = ByteBuffer.wrap( blockClass );
CharBuffer viewCharBuffer = classNameBuffer.asCharBuffer();
char[] classNameChars = new char[ classNameSize / Character.BYTES ];
viewCharBuffer.get( classNameChars );
String blockReaderClass = new String( classNameChars );
return new FileHeaderMeta( wrapBuffer.getInt( 0 ) , blockReaderClass , ( MAGIC.length + ( Integer.BYTES * 2 ) + classNameSize ) );
}
示例5: CMapFormat2
import java.nio.ByteBuffer; //导入方法依赖的package包/类
CMapFormat2(ByteBuffer buffer, int offset, char[] xlat) {
this.xlat = xlat;
int tableLen = buffer.getChar(offset+2);
buffer.position(offset+6);
CharBuffer cBuffer = buffer.asCharBuffer();
char maxSubHeader = 0;
for (int i=0;i<256;i++) {
subHeaderKey[i] = cBuffer.get();
if (subHeaderKey[i] > maxSubHeader) {
maxSubHeader = subHeaderKey[i];
}
}
/* The value of the subHeaderKey is 8 * the subHeader index,
* so the number of subHeaders can be obtained by dividing
* this value bv 8 and adding 1.
*/
int numSubHeaders = (maxSubHeader >> 3) +1;
firstCodeArray = new char[numSubHeaders];
entryCountArray = new char[numSubHeaders];
idDeltaArray = new short[numSubHeaders];
idRangeOffSetArray = new char[numSubHeaders];
for (int i=0; i<numSubHeaders; i++) {
firstCodeArray[i] = cBuffer.get();
entryCountArray[i] = cBuffer.get();
idDeltaArray[i] = (short)cBuffer.get();
idRangeOffSetArray[i] = cBuffer.get();
// System.out.println("sh["+i+"]:fc="+(int)firstCodeArray[i]+
// " ec="+(int)entryCountArray[i]+
// " delta="+(int)idDeltaArray[i]+
// " offset="+(int)idRangeOffSetArray[i]);
}
int glyphIndexArrSize = (tableLen-518-numSubHeaders*8)/2;
glyphIndexArray = new char[glyphIndexArrSize];
for (int i=0; i<glyphIndexArrSize;i++) {
glyphIndexArray[i] = cBuffer.get();
}
}
示例6: setFromBinary
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public void setFromBinary( final byte[] buffer , final int start , final int length ){
ByteBuffer wrapBuffer = ByteBuffer.wrap( buffer );
wrapBuffer.position( start );
int minSize = wrapBuffer.getInt();
int maxSize = wrapBuffer.getInt();
char[] minChars = new char[minSize];
char[] maxChars = new char[maxSize];
CharBuffer viewCharBuffer = wrapBuffer.asCharBuffer();
viewCharBuffer.get( minChars );
viewCharBuffer.get( maxChars );
min = new String( minChars );
max = new String( maxChars );
}
示例7: main
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static void main(String[] args) {
char[] data="UsingBuffers".toCharArray();
ByteBuffer bb=ByteBuffer.allocate(data.length*2);
CharBuffer cb=bb.asCharBuffer();
cb.put(data);
print(cb.rewind());
symmetricScramble(cb);
print(cb.rewind());
symmetricScramble(cb);
print(cb.rewind());
}
示例8: asCharBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static CharBuffer asCharBuffer(ByteBuffer buf) {
CharBuffer buffer = buf.asCharBuffer();
Buffer viewedBuffer = bufferViews.get(buf);
if (viewedBuffer != null) {
bufferViews.put(buffer, viewedBuffer);
} else {
bufferViews.put(buffer, buf);
}
return buffer;
}
示例9: getGaspTable
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private char[] getGaspTable() {
if (gaspTable != null) {
return gaspTable;
}
ByteBuffer buffer = getTableBuffer(gaspTag);
if (buffer == null) {
return gaspTable = new char[0];
}
CharBuffer cbuffer = buffer.asCharBuffer();
char format = cbuffer.get();
/* format "1" has appeared for some Windows Vista fonts.
* Its presently undocumented but the existing values
* seem to be still valid so we can use it.
*/
if (format > 1) { // unrecognised format
return gaspTable = new char[0];
}
char numRanges = cbuffer.get();
if (4+numRanges*4 > getTableSize(gaspTag)) { // sanity check
return gaspTable = new char[0];
}
gaspTable = new char[2*numRanges];
cbuffer.get(gaspTable);
return gaspTable;
}
示例10: CMapFormat10
import java.nio.ByteBuffer; //导入方法依赖的package包/类
CMapFormat10(ByteBuffer bbuffer, int offset, char[] xlat) {
firstCode = bbuffer.getInt() & INTMASK;
entryCount = bbuffer.getInt() & INTMASK;
bbuffer.position(offset+20);
CharBuffer buffer = bbuffer.asCharBuffer();
glyphIdArray = new char[entryCount];
for (int i=0; i< entryCount; i++) {
glyphIdArray[i] = buffer.get();
}
}
示例11: CMapFormat6
import java.nio.ByteBuffer; //导入方法依赖的package包/类
CMapFormat6(ByteBuffer bbuffer, int offset, char[] xlat) {
bbuffer.position(offset+6);
CharBuffer buffer = bbuffer.asCharBuffer();
firstCode = buffer.get();
entryCount = buffer.get();
glyphIdArray = new char[entryCount];
for (int i=0; i< entryCount; i++) {
glyphIdArray[i] = buffer.get();
}
}
示例12: newInstanceFromMetaBinary
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static ColumnBinary newInstanceFromMetaBinary( final byte[] metaBinary , final int start , final int length , final byte[] dataBuffer , final List<ColumnBinary> childList ) throws IOException{
int offset = start;
ByteBuffer wrapBuffer = ByteBuffer.wrap( metaBinary , start , length );
CharBuffer viewCharBuffer = wrapBuffer.asCharBuffer();
int classNameLength = wrapBuffer.getInt( offset );
offset += Integer.BYTES;
viewCharBuffer.position( ( offset - start ) / Character.BYTES );
char[] classNameChars = new char[ classNameLength / Character.BYTES ];
viewCharBuffer.get( classNameChars );
String metaClassName = String.valueOf( classNameChars );
offset += classNameLength;
int compressorClassNameLength = wrapBuffer.getInt( offset );
offset += Integer.BYTES;
viewCharBuffer.position( ( offset - start ) / Character.BYTES );
char[] compressorClassNameChars = new char[ compressorClassNameLength / Character.BYTES ];
viewCharBuffer.get( compressorClassNameChars );
String metaCompressorClassName = String.valueOf( compressorClassNameChars );
offset += compressorClassNameLength;
int columnNameLength = wrapBuffer.getInt( offset );
offset += Integer.BYTES;
viewCharBuffer.position( ( offset - start ) / Character.BYTES );
char[] columnNameChars = new char[ columnNameLength / Character.BYTES ];
viewCharBuffer.get( columnNameChars );
String metaColumnName = String.valueOf( columnNameChars );
offset += columnNameLength;
byte columnTypeByte = wrapBuffer.get( offset );
ColumnType metaColumnType = ColumnTypeFactory.getColumnTypeFromByte( columnTypeByte );
offset += Byte.BYTES;
int metaRowCount = wrapBuffer.getInt( offset );
offset += Integer.BYTES;
int metaRowData = wrapBuffer.getInt( offset );
offset += Integer.BYTES;
int metaLogicalData = wrapBuffer.getInt( offset );
offset += Integer.BYTES;
int metaCardinality = wrapBuffer.getInt( offset );
offset += Integer.BYTES;
int metaBinaryStart = wrapBuffer.getInt( offset );
offset += Integer.BYTES;
int metaBinaryLength = wrapBuffer.getInt( offset );
offset += Integer.BYTES;
return new ColumnBinary( ColumnBinaryMakerNameShortCut.getClassName( metaClassName ) , CompressorNameShortCut.getClassName( metaCompressorClassName ) , metaColumnName , metaColumnType , metaRowCount , metaRowData , metaLogicalData , metaCardinality , dataBuffer , metaBinaryStart , metaBinaryLength , childList );
}
示例13: toMetaBinary
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public byte[] toMetaBinary() throws IOException{
String shortCutClassName = ColumnBinaryMakerNameShortCut.getShortCutName( makerClassName );
String shortCutCompressorClassName = CompressorNameShortCut.getShortCutName( compressorClassName );
int classNameLength = shortCutClassName.length() * 2;
int compressorClassNameLength = shortCutCompressorClassName.length() * 2;
int columnNameLength = columnName.length() * 2;
byte columnTypeByte = ColumnTypeFactory.getColumnTypeByte( columnType );
byte[] result = new byte[getMetaSize()];
ByteBuffer wrapBuffer = ByteBuffer.wrap( result );
CharBuffer viewCharBuffer = wrapBuffer.asCharBuffer();
int offset = 0;
wrapBuffer.putInt( offset , classNameLength );
offset += Integer.BYTES;
viewCharBuffer.position( offset / Character.BYTES );
viewCharBuffer.put( shortCutClassName.toCharArray() );
offset += classNameLength;
wrapBuffer.putInt( offset , compressorClassNameLength );
offset += Integer.BYTES;
viewCharBuffer.position( offset / Character.BYTES );
viewCharBuffer.put( shortCutCompressorClassName.toCharArray() );
offset += compressorClassNameLength;
wrapBuffer.putInt( offset , columnNameLength );
offset += Integer.BYTES;
viewCharBuffer.position( offset / Character.BYTES );
viewCharBuffer.put( columnName.toCharArray() );
offset += columnNameLength;
wrapBuffer.put( offset , columnTypeByte );
offset += Byte.BYTES;
wrapBuffer.putInt( offset , rowCount );
offset += Integer.BYTES;
wrapBuffer.putInt( offset , rawDataSize );
offset += Integer.BYTES;
wrapBuffer.putInt( offset , logicalDataSize );
offset += Integer.BYTES;
wrapBuffer.putInt( offset , cardinality );
offset += Integer.BYTES;
wrapBuffer.putInt( offset , binaryStart );
offset += Integer.BYTES;
wrapBuffer.putInt( offset , binaryLength );
offset += Integer.BYTES;
return result;
}
示例14: getString
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static String getString(ByteBuffer bytes, int length, int additionalSkipLength) {
CharSequence cs = bytes.asCharBuffer();
String s = cs.subSequence(0, length).toString();
skipBytes(bytes, length * 2 + additionalSkipLength);
return s;
}
示例15: CMapFormat4
import java.nio.ByteBuffer; //导入方法依赖的package包/类
CMapFormat4(ByteBuffer bbuffer, int offset, char[] xlat) {
this.xlat = xlat;
bbuffer.position(offset);
CharBuffer buffer = bbuffer.asCharBuffer();
buffer.get(); // skip, we already know format=4
int subtableLength = buffer.get();
/* Try to recover from some bad fonts which specify a subtable
* length that would overflow the byte buffer holding the whole
* cmap table. If this isn't a recoverable situation an exception
* may be thrown which is caught higher up the call stack.
* Whilst this may seem lenient, in practice, unless the "bad"
* subtable we are using is the last one in the cmap table we
* would have no way of knowing about this problem anyway.
*/
if (offset+subtableLength > bbuffer.capacity()) {
subtableLength = bbuffer.capacity() - offset;
}
buffer.get(); // skip language
segCount = buffer.get()/2;
int searchRange = buffer.get();
entrySelector = buffer.get();
rangeShift = buffer.get()/2;
startCount = new char[segCount];
endCount = new char[segCount];
idDelta = new short[segCount];
idRangeOffset = new char[segCount];
for (int i=0; i<segCount; i++) {
endCount[i] = buffer.get();
}
buffer.get(); // 2 bytes for reserved pad
for (int i=0; i<segCount; i++) {
startCount[i] = buffer.get();
}
for (int i=0; i<segCount; i++) {
idDelta[i] = (short)buffer.get();
}
for (int i=0; i<segCount; i++) {
char ctmp = buffer.get();
idRangeOffset[i] = (char)((ctmp>>1)&0xffff);
}
/* Can calculate the number of glyph IDs by subtracting
* "pos" from the length of the cmap
*/
int pos = (segCount*8+16)/2;
buffer.position(pos);
int numGlyphIds = (subtableLength/2 - pos);
glyphIds = new char[numGlyphIds];
for (int i=0;i<numGlyphIds;i++) {
glyphIds[i] = buffer.get();
}
/*
System.err.println("segcount="+segCount);
System.err.println("entrySelector="+entrySelector);
System.err.println("rangeShift="+rangeShift);
for (int j=0;j<segCount;j++) {
System.err.println("j="+j+ " sc="+(int)(startCount[j]&0xffff)+
" ec="+(int)(endCount[j]&0xffff)+
" delta="+idDelta[j] +
" ro="+(int)idRangeOffset[j]);
}
//System.err.println("numglyphs="+glyphIds.length);
for (int i=0;i<numGlyphIds;i++) {
System.err.println("gid["+i+"]="+(int)glyphIds[i]);
}
*/
}