本文整理匯總了Java中java.nio.CharBuffer.length方法的典型用法代碼示例。如果您正苦於以下問題:Java CharBuffer.length方法的具體用法?Java CharBuffer.length怎麽用?Java CharBuffer.length使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.CharBuffer
的用法示例。
在下文中一共展示了CharBuffer.length方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createCredentials
import java.nio.CharBuffer; //導入方法依賴的package包/類
private static Credentials createCredentials(String registry, JSONObject value) throws IOException {
if (value == null) {
return null;
}
byte[] auth = Base64.getDecoder().decode((String) value.get("auth")); // NOI18N
CharBuffer chars = Charset.forName("UTF-8").newDecoder().decode(ByteBuffer.wrap(auth)); // NOI18N
int index = -1;
for (int i = 0; i < chars.length(); i++) {
if (chars.get(i) == ':') {
index = i;
break;
}
}
if (index < 0) {
throw new IOException("Malformed registry authentication record");
}
String username = new String(chars.array(), 0, index);
char[] password = new char[chars.length() - index - 1];
if (password.length > 0) {
System.arraycopy(chars.array(), index + 1, password, 0, password.length);
}
return new Credentials(registry, username, password, (String) value.get("email")); // NOI18N
}
示例2: toStringInternal
import java.nio.CharBuffer; //導入方法依賴的package包/類
public String toStringInternal() {
if (charset == null) {
charset = DEFAULT_CHARSET;
}
// new String(byte[], int, int, Charset) takes a defensive copy of the
// entire byte array. This is expensive if only a small subset of the
// bytes will be used. The code below is from Apache Harmony.
CharBuffer cb;
cb = charset.decode(ByteBuffer.wrap(buff, start, end-start));
return new String(cb.array(), cb.arrayOffset(), cb.length());
}
示例3: matchWhiteSpaceDelimnatedWords
import java.nio.CharBuffer; //導入方法依賴的package包/類
public void matchWhiteSpaceDelimnatedWords(CharBuffer cb, WordListener wl) {
Matcher m = SPACE_PATTERN.matcher(cb);
int i = 0;
int s = 0;
while(m.find()) {
s = m.start();
if (s != i) {
wl.word(i, s);
}
i = m.end();
}
if (i != cb.length())
wl.word(i, cb.length());
}
示例4: toStringInternal
import java.nio.CharBuffer; //導入方法依賴的package包/類
public String toStringInternal() {
if (charset == null) {
charset = DEFAULT_CHARSET;
}
// new String(byte[], int, int, Charset) takes a defensive copy of the
// entire byte array. This is expensive if only a small subset of the
// bytes will be used. The code below is from Apache Harmony.
CharBuffer cb;
cb = charset.decode(ByteBuffer.wrap(buff, start, end - start));
return new String(cb.array(), cb.arrayOffset(), cb.length());
}
示例5: find
import java.nio.CharBuffer; //導入方法依賴的package包/類
public int[] find(int start, String pattern, boolean regExp, boolean matchCase) {
Storage storage = getStorage();
if (storage == null) {
return null;
}
if (regExp && regExpChanged(pattern, matchCase)) {
this.pattern = null;
}
if (!regExp && !matchCase) {
pattern = pattern.toLowerCase();
}
while (true) {
BufferResource<ByteBuffer> br = null;
int size = getCharCount() - start;
if (size > MAX_FIND_SIZE) {
int l = getLineAt(start + MAX_FIND_SIZE);
size = getLineStart(l) + length(l) - start;
} else if (size <= 0) {
break;
}
CharBuffer buff = null;
try {
try {
br = storage.getReadBuffer(toByteIndex(start), toByteIndex(size));
buff = br.getBuffer().asCharBuffer();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
if (buff == null) {
break;
}
if (regExp) {
if (this.pattern == null) {
this.pattern = matchCase
? Pattern.compile(pattern)
: Pattern.compile(pattern,
Pattern.CASE_INSENSITIVE);
}
Matcher matcher = this.pattern.matcher(buff);
if (matcher.find()) {
return new int[]{start + matcher.start(), start + matcher.end()};
}
} else {
int idx = matchCase ? buff.toString().indexOf(pattern)
: buff.toString().toLowerCase().indexOf(pattern);
if (idx != -1) {
return new int[]{start + idx, start + idx + pattern.length()};
}
}
start += buff.length();
} finally {
if (br != null) {
br.releaseBuffer();
}
}
}
return null;
}
示例6: write
import java.nio.CharBuffer; //導入方法依賴的package包/類
/**
* Writes <code>len</code> bytes from the specified byte array starting at
* offset <code>off</code> to this output stream. The general contract for
* <code>write(b, off, len)</code> is that some of the bytes in the array
* <code>b</code> are written to the output stream in order; element
* <code>b[off]</code> is the first byte written and
* <code>b[off+len-1]</code> is the last byte written by this operation.
* <p>
* If <code>off</code> is negative, or <code>len</code> is negative, or
* <code>off+len</code> is greater than the length of the array
* <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
*
* @param b
* the data.
* @param off
* the start offset in the data.
* @param len
* the number of bytes to write.
* @exception IOException
* if an I/O error occurs. In particular, an
* <code>IOException</code> is thrown if the output stream is
* closed.
*/
@Override public void write(byte[] b, int off, int len) throws IOException {
synchronized (writer) {
if (!isOpen) {
return;
}
if (off < 0 || len <= 0 || off + len > b.length) {
throw new IndexOutOfBoundsException();
}
ByteBuffer bytes = ByteBuffer.wrap(b, off, len);
CharBuffer chars = CharBuffer.allocate(len);
byte2char(bytes, chars);
char[] cbuf = new char[chars.length()];
chars.get(cbuf, 0, chars.length());
writer.write(cbuf);
writer.flush();
}
}
示例7: stringLiteral
import java.nio.CharBuffer; //導入方法依賴的package包/類
/**
* Convert a byte array into a valid mysql string literal, assuming that
* it will be inserted into a column with latin-1 encoding.
* Based on information at
* http://dev.mysql.com/doc/refman/5.1/en/string-literals.html
* @param arr
* @return
*/
public static String stringLiteral(byte arr[]) {
CharBuffer cb = Charset.forName("ISO-8859-1").decode(ByteBuffer.wrap(arr));
StringBuilder sb = new StringBuilder();
sb.append('\'');
for (int i = 0; i < cb.length(); i++) {
char c = cb.get(i);
switch (c) {
case '\'':
sb.append("\\'");
break;
case '\\':
sb.append("\\\\");
break;
case '\0':
sb.append("\\0");
break;
case '\b':
sb.append("\\b");
break;
case '\n':
sb.append("\\n");
break;
case '\r':
sb.append("\\r");
break;
case '\t':
sb.append("\\t");
break;
default:
if (Character.getNumericValue(c) < 0) {
// Fall back on hex string for values not defined in latin-1
return hexStringLiteral(arr);
} else {
sb.append(c);
}
}
}
sb.append('\'');
return sb.toString();
}