Java Code Examples for java.nio.CharBuffer#reset()

The following examples show how to use java.nio.CharBuffer#reset() . 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: StringUtil.java    From doma-gen with Apache License 2.0 6 votes vote down vote up
/**
 * キャメルケースをアンダースコア区切りの大文字に変換します。
 *
 * @param text 文字列
 * @return 変換された文字列。 ただし、{@code text} が {@code null} の場合は {@code null}、 {@code text}
 *     が空文字の場合は空文字を返します。
 */
public static String fromCamelCaseToSnakeCase(String text) {
  if (isNullOrEmpty(text)) {
    return text;
  }
  StringBuilder result = new StringBuilder();
  CharBuffer buf = CharBuffer.wrap(text);
  while (buf.hasRemaining()) {
    char c = buf.get();
    result.append(Character.toLowerCase(c));
    buf.mark();
    if (buf.hasRemaining()) {
      char c2 = buf.get();
      if (Character.isLowerCase(c) && Character.isUpperCase(c2)) {
        result.append("_");
      }
      buf.reset();
    }
  }
  return result.toString();
}
 
Example 2
Source File: Chars.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}
 
Example 3
Source File: ReadStreamExtensions.java    From gravel with Apache License 2.0 5 votes vote down vote up
public static boolean peekFor_(CharBuffer receiver, char ch) {
	if (atEnd(receiver))
		return false;
	receiver.mark();
	if (receiver.get() == ch) {
		return true;
	}
	receiver.reset();
	return false;
}
 
Example 4
Source File: StringUtils.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test whether parameter consists of space characters only
 * 
 * @param data
 * @return true if parameter contains space characters only
 * @deprecated Does not recognize ASCII control (Unicode C0 control) characters, such as tab (09), CR (13), LF (10) and others to be blank.
 * Use {@link UnicodeBlanks#isBlank(CharSequence)} instead.
 */
@Deprecated
public static boolean isBlank(CharBuffer data) {
	data.mark();
	for (int i = 0; i < data.length(); i++) {
		if (!Character.isSpaceChar(data.get())) {
			data.reset();
			return false;
		}
	}
	data.reset();
	return true;
}
 
Example 5
Source File: Chars.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}
 
Example 6
Source File: Chars.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}
 
Example 7
Source File: UsingBuffers.java    From java-core-learning-example with Apache License 2.0 5 votes vote down vote up
private static void symmetricScaramble(CharBuffer buffer) {
    while (buffer.hasRemaining()) {
        // 将mark设为position
        buffer.mark();
        char c1 = buffer.get();
        char c2 = buffer.get();
        // 重置为以前标记的位置
        buffer.reset();
        buffer.put(c2).put(c1);
    }
}
 
Example 8
Source File: Chars.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}
 
Example 9
Source File: Chars.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}
 
Example 10
Source File: UsingBuffers.java    From LearningOfThinkInJava with Apache License 2.0 5 votes vote down vote up
private static void symmetricScramble(CharBuffer buffer){
    while (buffer.hasRemaining()){
        buffer.mark();
        char c1=buffer.get();
        char c2=buffer.get();
        buffer.reset();
        buffer.put(c2).put(c1);
    }
}
 
Example 11
Source File: Chars.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}
 
Example 12
Source File: Chars.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}
 
Example 13
Source File: Chars.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}
 
Example 14
Source File: Chars.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}
 
Example 15
Source File: Chars.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}
 
Example 16
Source File: UsingBuffers.java    From LearningOfThinkInJava with Apache License 2.0 5 votes vote down vote up
private static void symmetricScramble(CharBuffer buffer){
    while (buffer.hasRemaining()){
        buffer.mark();
        char c1=buffer.get();
        char c2=buffer.get();
        buffer.reset();
        buffer.put(c2).put(c1);
    }
}
 
Example 17
Source File: Chars.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}
 
Example 18
Source File: Chars.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}
 
Example 19
Source File: Chars.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sums the remaining chars in the char buffer.
 */
static int intSum(CharBuffer cb) {
    int sum = 0;
    cb.mark();
    while (cb.hasRemaining()) {
        sum += cb.get();
    }
    cb.reset();
    return sum;
}