当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuffer.getChar方法代码示例

本文整理汇总了Java中java.nio.ByteBuffer.getChar方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.getChar方法的具体用法?Java ByteBuffer.getChar怎么用?Java ByteBuffer.getChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.ByteBuffer的用法示例。


在下文中一共展示了ByteBuffer.getChar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: TrueTypeGlyphMapper

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public TrueTypeGlyphMapper(TrueTypeFont font) {
    this.font = font;
    try {
        cmap = CMap.initialize(font);
    } catch (Exception e) {
        cmap = null;
    }
    if (cmap == null) {
        handleBadCMAP();
    }
    missingGlyph = 0; /* standard for TrueType fonts */
    ByteBuffer buffer = font.getTableBuffer(TrueTypeFont.maxpTag);
    if (buffer != null && buffer.capacity() >= 6) {
        numGlyphs = buffer.getChar(4); // offset 4 bytes in MAXP table.
    } else {
        handleBadCMAP();
    }
    if (FontUtilities.isSolaris && isJAlocale && font.supportsJA()) {
        needsJAremapping = true;
    } else {
        needsJAremapping = false;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:TrueTypeGlyphMapper.java

示例2: deserialize

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public char[] deserialize( ByteBuffer buffer ) throws IOException
{
    int len = buffer.getInt();

    switch ( len )
    {
        case 0:
            return new char[]
                {};

        case -1:
            return null;

        default:
            char[] result = new char[len];

            for ( int i = 0; i < len; i++ )
            {
                result[i] = buffer.getChar();
            }

            return result;
    }
}
 
开发者ID:apache,项目名称:directory-mavibot,代码行数:28,代码来源:CharArraySerializer.java

示例3: parseString

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static String parseString(ByteBuffer src) {
    int len = src.getChar();
    byte data[] = new byte[len];
    src.get(data);
    try {
        return new String(data, "UTF8");
    } catch (UnsupportedEncodingException uee) {
        throw new InternalError(); // UTF8 must be supported
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:Archive.java

示例4: main

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static void main(String[] args) {
    ByteBuffer bb=ByteBuffer.allocate(BSIZE);
    int i=0;
    while (i++<bb.limit()){
        if(bb.get()!=0){
            print("nonzero");
        }
        print("i="+i);
    }
    bb.rewind();

    bb.asCharBuffer().put("Howdy!");
    char c;
    while ((c=bb.getChar())!=0){
        printnb(c+"");
    }
    print();
    bb.rewind();
    bb.asShortBuffer().put((short)471142);
    print(bb.getShort());
    bb.rewind();

    bb.asIntBuffer().put(99471142);
    print(bb.getShort());
    bb.rewind();

    bb.asLongBuffer().put(99471142);
    print(bb.getLong());
    bb.rewind();

    bb.asFloatBuffer().put(99471142);
    print(bb.getFloat());
    bb.rewind();

    bb.asDoubleBuffer().put(99471142);
    print(bb.getDouble());
    bb.rewind();

}
 
开发者ID:sean417,项目名称:LearningOfThinkInJava,代码行数:40,代码来源:GetData.java

示例5: setStyle

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void setStyle(ByteBuffer os_2Table) {
        /* fsSelection is unsigned short at buffer offset 62 */
        if (os_2Table == null || os_2Table.capacity() < 64) {
            super.setStyle();
            return;
        }
        int fsSelection = os_2Table.getChar(62) & 0xffff;
        int italic  = fsSelection & fsSelectionItalicBit;
        int bold    = fsSelection & fsSelectionBoldBit;
        int regular = fsSelection & fsSelectionRegularBit;
//      System.out.println("platname="+platName+" font="+fullName+
//                         " family="+familyName+
//                         " R="+regular+" I="+italic+" B="+bold);
        if (regular!=0 && ((italic|bold)!=0)) {
            /* This is inconsistent. Try using the font name algorithm */
            super.setStyle();
            return;
        } else if ((regular|italic|bold) == 0) {
            /* No style specified. Try using the font name algorithm */
            super.setStyle();
            return;
        }
        switch (bold|italic) {
        case fsSelectionItalicBit:
            style = Font.ITALIC;
            break;
        case fsSelectionBoldBit:
            if (FontUtilities.isSolaris && platName.endsWith("HG-GothicB.ttf")) {
                /* Workaround for Solaris's use of a JA font that's marked as
                 * being designed bold, but is used as a PLAIN font.
                 */
                style = Font.PLAIN;
            } else {
                style = Font.BOLD;
            }
            break;
        case fsSelectionBoldBit|fsSelectionItalicBit:
            style = Font.BOLD|Font.ITALIC;
        }
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:TrueTypeFont.java

示例6: createCMap

import java.nio.ByteBuffer; //导入方法依赖的package包/类
static CMap createCMap(ByteBuffer buffer, int offset, char[] xlat) {
    /* First do a sanity check that this cmap subtable is contained
     * within the cmap table.
     */
    int subtableFormat = buffer.getChar(offset);
    long subtableLength;
    if (subtableFormat < 8) {
        subtableLength = buffer.getChar(offset+2);
    } else {
        subtableLength = buffer.getInt(offset+4) & INTMASK;
    }
    if (offset+subtableLength > buffer.capacity()) {
        if (FontUtilities.isLogging()) {
            FontUtilities.getLogger().warning("Cmap subtable overflows buffer.");
        }
    }
    switch (subtableFormat) {
    case 0:  return new CMapFormat0(buffer, offset);
    case 2:  return new CMapFormat2(buffer, offset, xlat);
    case 4:  return new CMapFormat4(buffer, offset, xlat);
    case 6:  return new CMapFormat6(buffer, offset, xlat);
    case 8:  return new CMapFormat8(buffer, offset, xlat);
    case 10: return new CMapFormat10(buffer, offset, xlat);
    case 12: return new CMapFormat12(buffer, offset, xlat);
    default: throw new RuntimeException("Cmap format unimplemented: " +
                                        (int)buffer.getChar(offset));
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:CMap.java

示例7: CMapFormat0

import java.nio.ByteBuffer; //导入方法依赖的package包/类
CMapFormat0(ByteBuffer buffer, int offset) {

            /* skip 6 bytes of format, length, and version */
            int len = buffer.getChar(offset+2);
            cmap = new byte[len-6];
            buffer.position(offset+6);
            buffer.get(cmap);
        }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:CMap.java

示例8: 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:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:CMap.java

示例9: getCorrectDecoder

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * If they have specified UTF-16 then decoder works out by looking at BOM
 * but if missing we have to make an educated guess otherwise just use
 * specified decoder
 *
 * @param inBuffer
 * @return
 */
protected CharsetDecoder getCorrectDecoder(ByteBuffer inBuffer)
{
    CharsetDecoder decoder=null;
    if(inBuffer.remaining()<=2)
    {
        decoder = getTextEncodingCharSet().newDecoder();
        decoder.reset();
        return decoder;
    }

    if(getTextEncodingCharSet()== StandardCharsets.UTF_16)
    {
        if(inBuffer.getChar(0)==0xfffe || inBuffer.getChar(0)==0xfeff)
        {
            //Get the Specified Decoder
            decoder = getTextEncodingCharSet().newDecoder();
            decoder.reset();
        }
        else
        {
            if(inBuffer.get(0)==0)
            {
                decoder = StandardCharsets.UTF_16BE.newDecoder();
                decoder.reset();
            }
            else
            {
                decoder = StandardCharsets.UTF_16LE.newDecoder();
                decoder.reset();
            }
        }
    }
    else
    {
        decoder = getTextEncodingCharSet().newDecoder();
        decoder.reset();
    }
    return decoder;
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:48,代码来源:AbstractString.java

示例10: getOne

import java.nio.ByteBuffer; //导入方法依赖的package包/类
void getOne(ByteBuffer b, PrimitiveType t) {
    switch (t) {
    case BYTE: b.get(); break;
    case CHAR: b.getChar(); break;
    case SHORT: b.getShort(); break;
    case INT: b.getInt(); break;
    case LONG: b.getLong(); break;
    case FLOAT: b.getFloat(); break;
    case DOUBLE: b.getDouble(); break;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ByteBufferTest.java

示例11: extractServers

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Parses a positive response to NetBIOS name request query.
 * https://tools.ietf.org/html/rfc1002
 * Section 4.2.13
 */
static List<String> extractServers(byte[] data, int expectedTransId) throws BrowsingException {
  try {
    ByteBuffer buffer = ByteBuffer.wrap(data).order(ByteOrder.BIG_ENDIAN);

    int transId = buffer.getChar();
    if (transId != expectedTransId) {
      // This response is not to our broadcast.

      if (BuildConfig.DEBUG) Log.d(TAG, "Irrelevant broadcast response");

      return Collections.emptyList();
    }

    skipBytes(buffer, 2); // Skip flags.

    skipBytes(buffer, 2); // No questions.
    skipBytes(buffer, 2); // Skip answers count.
    skipBytes(buffer, 2); // No authority resources.
    skipBytes(buffer, 2); // No additional resources.

    int nameLength = buffer.get();
    skipBytes(buffer, nameLength);

    skipBytes(buffer, 1);

    int nodeStatus = buffer.getChar();
    if (nodeStatus != 0x20 && nodeStatus != 0x21) {
      throw new BrowsingException("Received negative response for the broadcast");
    }

    skipBytes(buffer, 2);
    skipBytes(buffer, 4);
    skipBytes(buffer, 2);

    int addressListEntryCount = buffer.get();

    List<String> servers = new ArrayList<>();
    for (int i = 0; i < addressListEntryCount; i++) {
      byte[] nameArray = new byte[SERVER_NAME_LENGTH];
      buffer.get(nameArray, 0, SERVER_NAME_LENGTH);

      final String serverName = new String(nameArray, Charset.forName(SERVER_NAME_CHARSET));
      final int type = buffer.get();

      if (type == FILE_SERVER_NODE_TYPE) {
        servers.add(serverName.trim());
      }

      skipBytes(buffer, 2);
    }

    return servers;
  } catch (BufferUnderflowException e) {
    Log.e(TAG, "Malformed incoming packet");

    return Collections.emptyList();
  }
}
 
开发者ID:google,项目名称:samba-documents-provider,代码行数:64,代码来源:BroadcastUtils.java

示例12: LogItem

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public LogItem(byte[] in, int length) throws UnsupportedEncodingException {
    ByteBuffer bb = ByteBuffer.wrap(in, 0, length);
    bb.get(); // ignore version
    logtime = bb.getLong();
    mVerbosityLevel = bb.getInt();
    mLevel = VpnStatus.LogLevel.getEnumByValue(bb.getInt());
    mRessourceId = bb.getInt();
    int len = bb.getInt();
    if (len == 0) {
        mMessage = null;
    } else {
        if (len > bb.remaining()) throw new IndexOutOfBoundsException("String length " + len + " is bigger than remaining bytes " + bb.remaining());
        byte[] utf8bytes = new byte[len];
        bb.get(utf8bytes);
        mMessage = new String(utf8bytes, "UTF-8");
    }
    int numArgs = bb.getInt();
    if (numArgs > 30) {
        throw new IndexOutOfBoundsException("Too many arguments for Logitem to unmarschal");
    }
    if (numArgs == 0) {
        mArgs = null;
    } else {
        mArgs = new Object[numArgs];
        for (int i = 0; i < numArgs; i++) {
            char type = bb.getChar();
            switch (type) {
                case 's':
                    mArgs[i] = unmarschalString(bb);
                    break;
                case 'i':
                    mArgs[i] = bb.getInt();
                    break;
                case 'd':
                    mArgs[i] = bb.getDouble();
                    break;
                case 'f':
                    mArgs[i] = bb.getFloat();
                    break;
                case 'l':
                    mArgs[i] = bb.getLong();
                    break;
                case '0':
                    mArgs[i] = null;
                    break;
                default:
                    throw new UnsupportedEncodingException("Unknown format type: " + type);
            }
        }
    }
    if (bb.hasRemaining()) throw new UnsupportedEncodingException(bb.remaining() + " bytes left after unmarshaling everything");
}
 
开发者ID:akashdeepsingh9988,项目名称:Cybernet-VPN,代码行数:53,代码来源:LogItem.java

示例13: load

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public NormalizerImpl load(ByteBuffer bytes) {
    try {
        dataVersion=ICUBinary.readHeaderAndDataVersion(bytes, DATA_FORMAT, IS_ACCEPTABLE);
        int indexesLength=bytes.getInt()/4;  // inIndexes[IX_NORM_TRIE_OFFSET]/4
        if(indexesLength<=IX_MIN_MAYBE_YES) {
            throw new IOException("Normalizer2 data: not enough indexes");
        }
        int[] inIndexes=new int[indexesLength];
        inIndexes[0]=indexesLength*4;
        for(int i=1; i<indexesLength; ++i) {
            inIndexes[i]=bytes.getInt();
        }

        minDecompNoCP=inIndexes[IX_MIN_DECOMP_NO_CP];
        minCompNoMaybeCP=inIndexes[IX_MIN_COMP_NO_MAYBE_CP];

        minYesNo=inIndexes[IX_MIN_YES_NO];
        minYesNoMappingsOnly=inIndexes[IX_MIN_YES_NO_MAPPINGS_ONLY];
        minNoNo=inIndexes[IX_MIN_NO_NO];
        limitNoNo=inIndexes[IX_LIMIT_NO_NO];
        minMaybeYes=inIndexes[IX_MIN_MAYBE_YES];

        // Read the normTrie.
        int offset=inIndexes[IX_NORM_TRIE_OFFSET];
        int nextOffset=inIndexes[IX_EXTRA_DATA_OFFSET];
        normTrie=Trie2_16.createFromSerialized(bytes);
        int trieLength=normTrie.getSerializedLength();
        if(trieLength>(nextOffset-offset)) {
            throw new IOException("Normalizer2 data: not enough bytes for normTrie");
        }
        ICUBinary.skipBytes(bytes, (nextOffset-offset)-trieLength);  // skip padding after trie bytes

        // Read the composition and mapping data.
        offset=nextOffset;
        nextOffset=inIndexes[IX_SMALL_FCD_OFFSET];
        int numChars=(nextOffset-offset)/2;
        char[] chars;
        if(numChars!=0) {
            chars=new char[numChars];
            for(int i=0; i<numChars; ++i) {
                chars[i]=bytes.getChar();
            }
            maybeYesCompositions=new String(chars);
            extraData=maybeYesCompositions.substring(MIN_NORMAL_MAYBE_YES-minMaybeYes);
        }

        // smallFCD: new in formatVersion 2
        offset=nextOffset;
        smallFCD=new byte[0x100];
        for(int i=0; i<0x100; ++i) {
            smallFCD[i]=bytes.get();
        }

        // Build tccc180[].
        // gennorm2 enforces lccc=0 for c<MIN_CCC_LCCC_CP=U+0300.
        tccc180=new int[0x180];
        int bits=0;
        for(int c=0; c<0x180; bits>>=1) {
            if((c&0xff)==0) {
                bits=smallFCD[c>>8];  // one byte per 0x100 code points
            }
            if((bits&1)!=0) {
                for(int i=0; i<0x20; ++i, ++c) {
                    tccc180[c]=getFCD16FromNormData(c)&0xff;
                }
            } else {
                c+=0x20;
            }
        }

        return this;
    } catch(IOException e) {
        throw new InternalError(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:76,代码来源:NormalizerImpl.java

示例14: setStyle

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void setStyle(ByteBuffer os_2Table) {
        if (os_2Table == null) {
            return;
        }
        if (os_2Table.capacity() >= 8) {
            fontWeight = os_2Table.getChar(4) & 0xffff;
            fontWidth  = os_2Table.getChar(6) & 0xffff;
        }
        /* fsSelection is unsigned short at buffer offset 62 */
        if (os_2Table.capacity() < 64) {
            super.setStyle();
            return;
        }
        int fsSelection = os_2Table.getChar(62) & 0xffff;
        int italic  = fsSelection & fsSelectionItalicBit;
        int bold    = fsSelection & fsSelectionBoldBit;
        int regular = fsSelection & fsSelectionRegularBit;
//      System.out.println("platname="+platName+" font="+fullName+
//                         " family="+familyName+
//                         " R="+regular+" I="+italic+" B="+bold);
        if (regular!=0 && ((italic|bold)!=0)) {
            /* This is inconsistent. Try using the font name algorithm */
            super.setStyle();
            return;
        } else if ((regular|italic|bold) == 0) {
            /* No style specified. Try using the font name algorithm */
            super.setStyle();
            return;
        }
        switch (bold|italic) {
        case fsSelectionItalicBit:
            style = Font.ITALIC;
            break;
        case fsSelectionBoldBit:
            if (FontUtilities.isSolaris && platName.endsWith("HG-GothicB.ttf")) {
                /* Workaround for Solaris's use of a JA font that's marked as
                 * being designed bold, but is used as a PLAIN font.
                 */
                style = Font.PLAIN;
            } else {
                style = Font.BOLD;
            }
            break;
        case fsSelectionBoldBit|fsSelectionItalicBit:
            style = Font.BOLD|Font.ITALIC;
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:48,代码来源:TrueTypeFont.java

示例15: UCharacterProperty

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Constructor
 * @exception IOException thrown when data reading fails or data corrupted
 */
private UCharacterProperty() throws IOException
{
    // jar access
    ByteBuffer bytes=ICUBinary.getRequiredData(DATA_FILE_NAME_);
    m_unicodeVersion_ = ICUBinary.readHeaderAndDataVersion(bytes, DATA_FORMAT, new IsAcceptable());
    // Read or skip the 16 indexes.
    int propertyOffset = bytes.getInt();
    /* exceptionOffset = */ bytes.getInt();
    /* caseOffset = */ bytes.getInt();
    int additionalOffset = bytes.getInt();
    int additionalVectorsOffset = bytes.getInt();
    m_additionalColumnsCount_ = bytes.getInt();
    int scriptExtensionsOffset = bytes.getInt();
    int reservedOffset7 = bytes.getInt();
    /* reservedOffset8 = */ bytes.getInt();
    /* dataTopOffset = */ bytes.getInt();
    m_maxBlockScriptValue_ = bytes.getInt();
    m_maxJTGValue_ = bytes.getInt();
    ICUBinary.skipBytes(bytes, (16 - 12) << 2);

    // read the main properties trie
    m_trie_ = Trie2_16.createFromSerialized(bytes);
    int expectedTrieLength = (propertyOffset - 16) * 4;
    int trieLength = m_trie_.getSerializedLength();
    if(trieLength > expectedTrieLength) {
        throw new IOException("uprops.icu: not enough bytes for main trie");
    }
    // skip padding after trie bytes
    ICUBinary.skipBytes(bytes, expectedTrieLength - trieLength);

    // skip unused intervening data structures
    ICUBinary.skipBytes(bytes, (additionalOffset - propertyOffset) * 4);

    if(m_additionalColumnsCount_ > 0) {
        // reads the additional property block
        m_additionalTrie_ = Trie2_16.createFromSerialized(bytes);
        expectedTrieLength = (additionalVectorsOffset-additionalOffset)*4;
        trieLength = m_additionalTrie_.getSerializedLength();
        if(trieLength > expectedTrieLength) {
            throw new IOException("uprops.icu: not enough bytes for additional-properties trie");
        }
        // skip padding after trie bytes
        ICUBinary.skipBytes(bytes, expectedTrieLength - trieLength);

        // additional properties
        int size = scriptExtensionsOffset - additionalVectorsOffset;
        m_additionalVectors_ = new int[size];
        for (int i = 0; i < size; i ++) {
            m_additionalVectors_[i] = bytes.getInt();
        }
    }

    // Script_Extensions
    int numChars = (reservedOffset7 - scriptExtensionsOffset) * 2;
    if(numChars > 0) {
        m_scriptExtensions_ = new char[numChars];
        for(int i = 0; i < numChars; ++i) {
            m_scriptExtensions_[i] = bytes.getChar();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:UCharacterProperty.java


注:本文中的java.nio.ByteBuffer.getChar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。