List of usage examples for java.lang String getChars
public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin)
From source file:xbird.xquery.misc.PagedStringChunk2.java
public synchronized long store(String s) { final int strlen = s.length(); if (strlen < CHUNKED_THRESHOLD) { s.getChars(0, strlen, _tmpBuf, 0); return storeCharChunk(_tmpBuf, 0, strlen); } else {//from w ww. j a v a2s . co m byte[] b = StringUtils.getBytes(s); return storeStringChunk(b); } }
From source file:org.apache.axiom.util.stax.xop.XOPDecodingStreamReader.java
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException { if (dh != null) { String text = toBase64(); int copied = Math.min(length, text.length() - sourceStart); text.getChars(sourceStart, sourceStart + copied, target, targetStart); return copied; } else {/*from w ww .j a v a2 s . c o m*/ return super.getTextCharacters(sourceStart, target, targetStart, length); } }
From source file:VelocityWriter.java
/** * Write a portion of a String.//from ww w. ja v a 2s .co m * * @param s String to be written * @param off Offset from which to start reading characters * @param len Number of characters to be written * @throws IOException * */ public final void write(String s, int off, int len) throws IOException { if (bufferSize == 0) { writer.write(s, off, len); return; } int b = off, t = off + len; while (b < t) { int d = min(bufferSize - nextChar, t - b); s.getChars(b, b + d, cb, nextChar); b += d; nextChar += d; if (nextChar >= bufferSize) if (autoFlush) flushBuffer(); else bufferOverflow(); } }
From source file:org.botlibre.util.Utils.java
public static String buildZeroPrefixAndTruncTrailZeros(int number, int totalDigits) { String zeros = "000000000"; String numbString = Integer.toString(number); numbString = zeros.substring(0, (totalDigits - numbString.length())) + numbString; char[] numbChar = new char[numbString.length()]; numbString.getChars(0, numbString.length(), numbChar, 0); int truncIndex = totalDigits - 1; while (numbChar[truncIndex] == '0') { truncIndex--;//from www . j ava 2 s. co m } return new String(numbChar, 0, truncIndex + 1); }
From source file:org.apache.cocoon.util.log.ExtensiblePatternFormatter.java
/** * Parse the input pattern and build internal data structures. * * @param patternString the pattern/*w ww .j ava2 s . c o m*/ */ protected void parse(final String patternString) { final Stack stack = new Stack(); final int size = patternString.length(); final char pattern[] = new char[size]; int index = 0; patternString.getChars(0, size, pattern, 0); while (index < size) { if (pattern[index] == '%' && !(index != size - 1 && pattern[index + 1] == '%')) { index += addPatternRun(stack, pattern, index); } else { index += addTextRun(stack, pattern, index); } } final int elementCount = stack.size(); m_formatSpecification = new PatternRun[elementCount]; for (int i = 0; i < elementCount; i++) { m_formatSpecification[i] = (PatternRun) stack.elementAt(i); } }
From source file:StringExaminer.java
/** * Initialize the new instance with the string that should be scanned. * * @param stringToScan/* w w w . j av a 2 s . c o m*/ */ public StringScanner(String stringToScan) { super(); length = stringToScan.length(); buffer = new char[length]; stringToScan.getChars(0, length, buffer, 0); }
From source file:org.apache.fop.fonts.Font.java
/** * Calculates the word width.//from w ww. j a v a2s .c o m * @param word text to get width for * @return the width of the text */ public int getWordWidth(String word) { if (word == null) { return 0; } int wordLength = word.length(); int width = 0; char[] characters = new char[wordLength]; word.getChars(0, wordLength, characters, 0); for (int i = 0; i < wordLength; i++) { width += getCharWidth(characters[i]); } return width; }
From source file:org.openamf.io.AMFSerializer.java
/** * Most of this code was cribbed from Java's DataOutputStream.writeUTF method * which only supports Strings <= 65535 UTF-encoded characters. *///from www . java 2 s . c o m protected int writeString(String str) throws IOException { int strlen = str.length(); int utflen = 0; char[] charr = new char[strlen]; int c, count = 0; str.getChars(0, strlen, charr, 0); // check the length of the UTF-encoded string for (int i = 0; i < strlen; i++) { c = charr[i]; if ((c >= 0x0001) && (c <= 0x007F)) { utflen++; } else if (c > 0x07FF) { utflen += 3; } else { utflen += 2; } } /** * if utf-encoded String is < 64K, use the "String" data type, with a * two-byte prefix specifying string length; otherwise use the "Long String" * data type, withBUG#298 a four-byte prefix */ byte[] bytearr; if (utflen <= 65535) { outputStream.writeByte(AMFBody.DATA_TYPE_STRING); bytearr = new byte[utflen + 2]; } else { outputStream.writeByte(AMFBody.DATA_TYPE_LONG_STRING); bytearr = new byte[utflen + 4]; bytearr[count++] = (byte) ((utflen >>> 24) & 0xFF); bytearr[count++] = (byte) ((utflen >>> 16) & 0xFF); } bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF); bytearr[count++] = (byte) ((utflen >>> 0) & 0xFF); for (int i = 0; i < strlen; i++) { c = charr[i]; if ((c >= 0x0001) && (c <= 0x007F)) { bytearr[count++] = (byte) c; } else if (c > 0x07FF) { bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F)); bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F)); bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F)); } else { bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F)); bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F)); } } outputStream.write(bytearr); return utflen + 2; }
From source file:sernet.verinice.rcp.search.SearchView.java
private void createLimitInputField(Composite searchComposite) { limitText = new Text(searchComposite, SWT.SINGLE | SWT.BORDER); GridData gridLimitData = new GridData(SWT.FILL, SWT.NONE, true, false); limitText.setLayoutData(gridLimitData); limitText.setText(String.valueOf(VeriniceQuery.DEFAULT_LIMIT)); limitText.addKeyListener(new InputFieldsListener()); limitText.addListener(SWT.Verify, new Listener() { @Override/* w w w .jav a 2 s. com*/ public void handleEvent(Event e) { String string = e.text; char[] chars = new char[string.length()]; string.getChars(0, chars.length, chars, 0); for (int i = 0; i < chars.length; i++) { if (!('0' <= chars[i] && chars[i] <= '9')) { e.doit = false; return; } } } }); }
From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF0Serializer.java
/** * Most of this code was cribbed from Java's DataOutputStream.writeUTF method * which only supports Strings <= 65535 UTF-encoded characters. */// w ww . j a v a 2 s . c o m protected int writeString(String str) throws IOException { int strlen = str.length(); int utflen = 0; char[] charr = new char[strlen]; int c, count = 0; str.getChars(0, strlen, charr, 0); // check the length of the UTF-encoded string for (int i = 0; i < strlen; i++) { c = charr[i]; if ((c >= 0x0001) && (c <= 0x007F)) { utflen++; } else if (c > 0x07FF) { utflen += 3; } else { utflen += 2; } } /** * if utf-encoded String is < 64K, use the "String" data type, with a * two-byte prefix specifying string length; otherwise use the "Long String" * data type, withBUG#298 a four-byte prefix */ byte[] bytearr; if (utflen <= 65535) { outputStream.writeByte(AMF0Body.DATA_TYPE_STRING); bytearr = new byte[utflen + 2]; } else { outputStream.writeByte(AMF0Body.DATA_TYPE_LONG_STRING); bytearr = new byte[utflen + 4]; bytearr[count++] = (byte) ((utflen >>> 24) & 0xFF); bytearr[count++] = (byte) ((utflen >>> 16) & 0xFF); } bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF); bytearr[count++] = (byte) ((utflen >>> 0) & 0xFF); for (int i = 0; i < strlen; i++) { c = charr[i]; if ((c >= 0x0001) && (c <= 0x007F)) { bytearr[count++] = (byte) c; } else if (c > 0x07FF) { bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F)); bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F)); bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F)); } else { bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F)); bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F)); } } outputStream.write(bytearr); return utflen + 2; }