Here you can find the source of readShortBuffer(DataInputStream input)
Parameter | Description |
---|---|
input | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static ByteBuffer readShortBuffer(DataInputStream input) throws IOException
//package com.java2s; /**/* w w w .j ava 2s .c om*/ * Copyright 2016 LinkedIn Corp. All rights reserved. * * 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. */ import java.io.DataInputStream; import java.io.IOException; import java.nio.ByteBuffer; public class Main { /** * * @param input * @return * @throws IOException */ public static ByteBuffer readShortBuffer(DataInputStream input) throws IOException { short size = input.readShort(); if (size < 0) { return null; } ByteBuffer buffer = ByteBuffer.allocate(size); int read = 0; while (read < size) { int readBytes = input.read(buffer.array()); if (readBytes == -1 || readBytes == 0) { break; } read += readBytes; } if (read != size) { throw new IllegalArgumentException( "readShortBuffer the size of the input does not match the actual data size"); } return buffer; } }