Here you can find the source of splitLongToBuffers(ByteBuffer buffer, ByteBuffer buffer1, long iValue)
Parameter | Description |
---|---|
buffer | to write first part of value |
buffer1 | to write second part of value |
public static void splitLongToBuffers(ByteBuffer buffer, ByteBuffer buffer1, long iValue)
//package com.java2s; /*//from w w w.j a v a2 s . c om * Copyright 1999-2012 Luca Garulli (l.garulli--at--orientechnologies.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.nio.ByteBuffer; public class Main { public static final int SIZE_OF_LONG = 8; private static final int SIZE_OF_BYTE_IN_BITS = 8; /** * Split long value into two byte buffer. First byte of long will be written to first byte buffer and second to second one. How * many bytes will be written to first buffer determines based on <code>buffer.remaining()</code> value * * @param buffer * to write first part of value * @param buffer1 * to write second part of value */ public static void splitLongToBuffers(ByteBuffer buffer, ByteBuffer buffer1, long iValue) { int remaining = buffer.remaining(); int i; for (i = 0; i < remaining; ++i) { buffer.put((byte) (iValue >> SIZE_OF_BYTE_IN_BITS * (SIZE_OF_LONG - i - 1))); } for (int j = 0; j < SIZE_OF_LONG - remaining; ++j) { buffer1.put((byte) (iValue >> SIZE_OF_BYTE_IN_BITS * (SIZE_OF_LONG - i - j - 1))); } } }