Java ByteBuffer from getByteBufferOutputStream(final ByteBuffer buf)

Here you can find the source of getByteBufferOutputStream(final ByteBuffer buf)

Description

Create an OutputStream for a ByteBuffer

License

Open Source License

Parameter

Parameter Description
buf a parameter

Declaration

public static OutputStream getByteBufferOutputStream(final ByteBuffer buf) 

Method Source Code

//package com.java2s;
/**//from   ww  w.ja  va 2 s  .  c om
 * Copyright (C) 2010-2011, FuseSource Corp.  All rights reserved.
 *
 *     http://fusesource.com
 *
 * The software in this package is published under the terms of the
 * CDDL license a copy of which has been included with this distribution
 * in the license.txt file.
 */

import java.io.*;
import java.nio.ByteBuffer;

public class Main {
    /**
     * Create an OutputStream for a ByteBuffer
     *
     * @param buf
     * @return
     */
    public static OutputStream getByteBufferOutputStream(final ByteBuffer buf) {
        return new OutputStream() {
            public void write(int b) throws IOException {
                buf.put((byte) b);
            }

            public void write(byte[] bytes, int off, int len) throws IOException {
                buf.put(bytes, off, len);
            }
        };
    }
}

Related

  1. getByteBufferFromBytes(byte[] data)
  2. getByteBufferFromInt(int value)
  3. getByteBufferFromList(List values)
  4. getByteBufferFromUTF8(String str)
  5. getByteBufferFromUUID(java.util.UUID uuid)
  6. getByteBufferReadMethod(Class clazz)
  7. getByteBuffers(Collection newValue)
  8. getByteBufferUtf8(final String string)
  9. toByteBuffer(BigDecimal decimal)

  10. HOME | Copyright © www.java2s.com 2016