當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteBuffer.asCharBuffer方法代碼示例

本文整理匯總了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 );
}
 
開發者ID:yahoojapan,項目名稱:multiple-dimension-spread,代碼行數:26,代碼來源:MDSWriter.java

示例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) {
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:24,代碼來源:ByteSourceJUnitTest.java

示例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) {
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:24,代碼來源:ByteSourceJUnitTest.java

示例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 ) );
}
 
開發者ID:yahoojapan,項目名稱:multiple-dimension-spread,代碼行數:28,代碼來源:MDSReader.java

示例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();
            }
        }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:41,代碼來源:CMap.java

示例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 );
}
 
開發者ID:yahoojapan,項目名稱:multiple-dimension-spread,代碼行數:16,代碼來源:StringRangeBlockIndex.java

示例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());
}
 
開發者ID:sean417,項目名稱:LearningOfThinkInJava,代碼行數:14,代碼來源:UsingBuffers.java

示例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;
}
 
開發者ID:LWJGLX,項目名稱:debug,代碼行數:11,代碼來源:RT.java

示例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;
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:30,代碼來源:TrueTypeFont.java

示例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();
             }
         }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:CMap.java

示例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();
             }
         }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:CMap.java

示例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 );
}
 
開發者ID:yahoojapan,項目名稱:multiple-dimension-spread,代碼行數:54,代碼來源:ColumnBinary.java

示例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;
}
 
開發者ID:yahoojapan,項目名稱:multiple-dimension-spread,代碼行數:55,代碼來源:ColumnBinary.java

示例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;
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:7,代碼來源:ICUBinary.java

示例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]);
            }
*/
        }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:73,代碼來源:CMap.java


注:本文中的java.nio.ByteBuffer.asCharBuffer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。