java.nio.ByteBuffer#getChar ( )源码实例Demo

下面列出了java.nio.ByteBuffer#getChar ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8-source   文件: TrueTypeGlyphMapper.java
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);
    numGlyphs = buffer.getChar(4); // offset 4 bytes in MAXP table.
    if (FontUtilities.isSolaris && isJAlocale && font.supportsJA()) {
        needsJAremapping = true;
        if (FontUtilities.isSolaris8 &&
            getGlyphFromCMAP(JA_WAVE_DASH_CHAR) == missingGlyph) {
            remapJAWaveDash = true;
        }
    } else {
        needsJAremapping = false;
    }
}
 
源代码2 项目: openjdk-jdk9   文件: CMap.java
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);
        }
 
源代码3 项目: Bytecoder   文件: CMap.java
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);
        }
 
源代码4 项目: jdk8u-dev-jdk   文件: TrueTypeFont.java
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;
        }
    }
 
源代码5 项目: dragonwell8_jdk   文件: TrueTypeGlyphMapper.java
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;
        if (FontUtilities.isSolaris8 &&
            getGlyphFromCMAP(JA_WAVE_DASH_CHAR) == missingGlyph) {
            remapJAWaveDash = true;
        }
    } else {
        needsJAremapping = false;
    }
}
 
源代码6 项目: openjdk-jdk8u   文件: CMap.java
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));
    }
}
 
源代码7 项目: mochadoom   文件: mapseg_t.java
@Override
public void unpack(ByteBuffer buf)
        throws IOException {
    buf.order(ByteOrder.LITTLE_ENDIAN);
    this.v1 = buf.getChar();
    this.v2 = buf.getChar();
    this.angle=buf.getChar();       
    this.linedef=buf.getChar();
    this.side=buf.getChar();
    this.offset=buf.getChar();
   
}
 
源代码8 项目: twister2   文件: StringPacker.java
@Override
public int readDataFromBuffer(ObjectBuilder<String, char[]> objectBuilder,
                              int currentBufferLocation, DataBuffer dataBuffer) {
  int totalDataLength = objectBuilder.getTotalSize();
  int startIndex = objectBuilder.getCompletedSize();
  int unitSize = Character.BYTES;
  startIndex = startIndex / unitSize;
  char[] val = objectBuilder.getPartialDataHolder();

  //deserializing
  int noOfElements = totalDataLength / unitSize;
  int bufferPosition = currentBufferLocation;
  int bytesRead = 0;
  for (int i = startIndex; i < noOfElements; i++) {
    ByteBuffer byteBuffer = dataBuffer.getByteBuffer();
    int remaining = dataBuffer.getSize() - bufferPosition;
    if (remaining >= unitSize) {
      val[i] = byteBuffer.getChar(bufferPosition);
      bytesRead += unitSize;
      bufferPosition += unitSize;
    } else {
      break;
    }
  }
  if (totalDataLength == bytesRead + startIndex) {
    objectBuilder.setFinalObject(new String(val));
  }
  return bytesRead;
}
 
源代码9 项目: mochadoom   文件: mapseg_v4_t.java
@Override
public void unpack(ByteBuffer buf)
        throws IOException {
    buf.order(ByteOrder.LITTLE_ENDIAN);
    this.v1 = buf.getInt();
    this.v2 = buf.getInt();
    this.angle=buf.getChar();       
    this.linedef=buf.getChar();
    this.side=buf.getChar();
    this.offset=buf.getChar();
   
}
 
源代码10 项目: jdk8u-jdk   文件: CMap.java
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);
        }
 
源代码11 项目: TencentKona-8   文件: CMap.java
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);
        }
 
源代码12 项目: jdk8u_jdk   文件: TrueTypeGlyphMapper.java
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;
        if (FontUtilities.isSolaris8 &&
            getGlyphFromCMAP(JA_WAVE_DASH_CHAR) == missingGlyph) {
            remapJAWaveDash = true;
        }
    } else {
        needsJAremapping = false;
    }
}
 
源代码13 项目: mochadoom   文件: maplinedef_t.java
@Override
public void unpack(ByteBuffer buf)
        throws IOException {
buf.order(ByteOrder.LITTLE_ENDIAN);
this.v1 = buf.getChar();
this.v2 = buf.getChar();
this.flags = buf.getShort();
this.special = buf.getShort();
this.tag = buf.getShort();
DoomBuffer.readCharArray(buf, this.sidenum, 2);
}
 
源代码14 项目: mochadoom   文件: mapsubsector_v4_t.java
@Override
public void unpack(ByteBuffer buf)
       throws IOException {
   buf.order(ByteOrder.LITTLE_ENDIAN);
   this.numsegs = buf.getChar();
   this.firstseg = buf.getInt();        
}
 
源代码15 项目: LearningOfThinkInJava   文件: GetData.java
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();

}
 
源代码16 项目: VSerializer   文件: AlphabeticalSerializer.java
private char[] toChars(byte[] bytes) {
    ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
    char[] chars = new char[bytes.length / 2];
    for (int i = 0; i < chars.length; i++) {
        chars[i] = byteBuffer.getChar();
    }
    return chars;
}
 
源代码17 项目: samba-documents-provider   文件: BroadcastUtils.java
/**
 * 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();
  }
}
 
源代码18 项目: dragonwell8_jdk   文件: TrueTypeFont.java
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;
        }
    }
 
源代码19 项目: jdk8u_jdk   文件: TrueTypeFont.java
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;
        }
    }
 
源代码20 项目: twister2   文件: CharArrayPacker.java
@Override
public void readFromBufferAndSet(ByteBuffer byteBuffer, int offset, char[] array, int index) {
  array[index] = byteBuffer.getChar(offset);
}