Java Code Examples for java.nio.CharBuffer#mark()
The following examples show how to use
java.nio.CharBuffer#mark() .
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 |
/** * キャメルケースをアンダースコア区切りの大文字に変換します。 * * @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: UsingBuffers.java From LearningOfThinkInJava with Apache License 2.0 | 5 votes |
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 3
Source File: ReadStreamExtensions.java From gravel with Apache License 2.0 | 5 votes |
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 |
/** * 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 |
/** * 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 |
/** * 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 |
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 |
/** * 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 |
/** * 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: Chars.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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 11
Source File: Chars.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 |
/** * 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 |
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 |
/** * 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 |
/** * 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 |
/** * 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 20
Source File: ByteBufferUtils.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
/** * Creates deep copy of the given {@link CharBuffer} with at least requested capacity and at most maximum capacity. * The resulted deep copy has same internal state (position, limit, mark) as the given buffer. * @param oldBuffer copied buffer * @param requestedCapacity the resulted buffer has at least this capacity * @param maximumCapacity the resulted buffer has at most this capacity * @return the deep copy of the given buffer with expanded capacity */ public static CharBuffer expandCharBuffer(CharBuffer oldBuffer, int requestedCapacity, int maximumCapacity) { if (requestedCapacity > maximumCapacity) { throw new IllegalArgumentException("CharBuffer cannot be expanded. Requested capacity (" + requestedCapacity + ") cannot be bigger than maximum capacity (" + maximumCapacity + ")."); } if (oldBuffer.capacity() < requestedCapacity) { // Allocate a new buffer and transfer all settings to it. //// Save the state. int oldPosition = oldBuffer.position(); int oldLimit = oldBuffer.limit(); int oldMark = -1; try { oldMark = oldBuffer.reset().position(); } catch (InvalidMarkException e) { //DO NOTHING } //// Reallocate. int newCapacity = Math.min(normalizeCapacity(requestedCapacity), maximumCapacity); CharBuffer newBuffer = CharBuffer.allocate(newCapacity); oldBuffer.clear(); newBuffer.put(oldBuffer); //// Restore the state in old buffer oldBuffer.limit(oldLimit); if (oldMark >= 0) { oldBuffer.position(oldMark); oldBuffer.mark(); } oldBuffer.position(oldPosition); //// Restore the state in new buffer newBuffer.limit(oldLimit); if (oldMark >= 0) { newBuffer.position(oldMark); newBuffer.mark(); } newBuffer.position(oldPosition); return newBuffer; } else { return oldBuffer; } }