Java ByteBuffer to String getStringDTrimmed(ByteBuffer byteBuffer, int length)

Here you can find the source of getStringDTrimmed(ByteBuffer byteBuffer, int length)

Description

get String D Trimmed

License

CDDL license

Declaration

public static String getStringDTrimmed(ByteBuffer byteBuffer, int length) 

Method Source Code


//package com.java2s;
/*//from  w  w  w  .j  ava  2s .  c om
 *         COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Notice
 *
 * The contents of this file are subject to the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL)
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.opensource.org/licenses/cddl1.txt
 *
 * The Original Code is Drombler.org. The Initial Developer of the
 * Original Code is Florian Brunner (Sourceforge.net user: puce).
 * Copyright 2014 Drombler.org. All Rights Reserved.
 *
 * Contributor(s): .
 */

import java.nio.ByteBuffer;

public class Main {
    public static String getStringDTrimmed(ByteBuffer byteBuffer, int length) {
        return getStringD(byteBuffer, length).trim();
    }

    private static String getStringD(ByteBuffer byteBuffer, int length) {
        return getStringA(byteBuffer, length);
    }

    private static String getStringA(ByteBuffer byteBuffer, int length) {
        byte[] dst = getBytes(byteBuffer, length);
        return new String(dst);
    }

    private static byte[] getBytes(ByteBuffer byteBuffer, int length) {
        byte[] dst = new byte[length];
        byteBuffer.get(dst);
        return dst;
    }
}

Related

  1. getString(ByteBuffer in, int maxLength)
  2. getString(final ByteBuffer buffer)
  3. getString(final ByteBuffer buffer, final int offset, final int length, final Charset encoding)
  4. getString(java.nio.ByteBuffer buffer, int offset, int len)
  5. getStringA(ByteBuffer byteBuffer, int length)
  6. getStringFromBuffer(ByteBuffer buf, int len)
  7. getStringFromBuffer(ByteBuffer buffer, int length)
  8. getStringFromByteBuffer(ByteBuffer bb)
  9. getStringFromByteBuffer(ByteBuffer data)