Java DataInputStream Read readBytesArray(DataInputStream dis)

Here you can find the source of readBytesArray(DataInputStream dis)

Description

read Bytes Array

License

Open Source License

Declaration

static byte[] readBytesArray(DataInputStream dis) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Open Door Logistics (www.opendoorlogistics.com)
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License 3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 * /*from  ww  w .j  a v a 2s.  c  o m*/
 ******************************************************************************/

import java.io.DataInputStream;

public class Main {
    public static final String RENDER_GEOMETRY_FILE_EXT = "odlrg";

    static byte[] readBytesArray(DataInputStream dis) {
        try {
            int len = dis.readInt();
            if (len > 0) {
                byte[] ret = new byte[len];
                int read = dis.read(ret);
                if (read < len) {
                    throw new RuntimeException(
                            "Corrupt "
                                    + RENDER_GEOMETRY_FILE_EXT
                                    + " file; found array which is shorter than declated.");
                }
                return ret;
            }
            return null;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}

Related

  1. readBytes(DataInputStream stream, int size)
  2. readBytes(DataInputStream stream, int size)
  3. readBytes(File ff)
  4. readBytes(String filename)
  5. readBytes(String filename)
  6. readFromFile(File file)
  7. readFromFileToLineArray(File file)
  8. saveDoubleMatrixFromBinary(DataInputStream reader, int rows, int cols, PrintStream out)