Java Code Examples for java.nio.ByteBuffer#getChar()
The following examples show how to use
java.nio.ByteBuffer#getChar() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrueTypeGlyphMapper.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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; } }
Example 2
Source File: CMap.java From Bytecoder with Apache License 2.0 | 5 votes |
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); }
Example 3
Source File: AlphabeticalSerializer.java From VSerializer with GNU General Public License v2.0 | 5 votes |
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; }
Example 4
Source File: GetData.java From LearningOfThinkInJava with Apache License 2.0 | 5 votes |
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(); }
Example 5
Source File: mapsubsector_v4_t.java From mochadoom with GNU General Public License v3.0 | 5 votes |
@Override public void unpack(ByteBuffer buf) throws IOException { buf.order(ByteOrder.LITTLE_ENDIAN); this.numsegs = buf.getChar(); this.firstseg = buf.getInt(); }
Example 6
Source File: maplinedef_t.java From mochadoom with GNU General Public License v3.0 | 5 votes |
@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); }
Example 7
Source File: TrueTypeGlyphMapper.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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; } }
Example 8
Source File: CMap.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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); }
Example 9
Source File: CMap.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example 10
Source File: mapseg_v4_t.java From mochadoom with GNU General Public License v3.0 | 5 votes |
@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(); }
Example 11
Source File: StringPacker.java From twister2 with Apache License 2.0 | 5 votes |
@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; }
Example 12
Source File: mapseg_t.java From mochadoom with GNU General Public License v3.0 | 5 votes |
@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(); }
Example 13
Source File: CMap.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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)); } }
Example 14
Source File: TrueTypeGlyphMapper.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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; } }
Example 15
Source File: TrueTypeFont.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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; } }
Example 16
Source File: CMap.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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); }
Example 17
Source File: TrueTypeFont.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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; } }
Example 18
Source File: TrueTypeFont.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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; } }
Example 19
Source File: BroadcastUtils.java From samba-documents-provider with GNU General Public License v3.0 | 4 votes |
/** * 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(); } }
Example 20
Source File: CharArrayPacker.java From twister2 with Apache License 2.0 | 4 votes |
@Override public void readFromBufferAndSet(ByteBuffer byteBuffer, int offset, char[] array, int index) { array[index] = byteBuffer.getChar(offset); }