Java Size read(byte[] input, int size)

Here you can find the source of read(byte[] input, int size)

Description

read

License

Open Source License

Declaration

public static double[][] read(byte[] input, int size) throws IOException, ParseException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;

import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.ParseException;

public class Main {
    private static final String DOT = ".";
    private static final String COMMA = ",";

    public static double[][] read(byte[] input, int size) throws IOException, ParseException {
        try (ByteArrayInputStream inputStream = new ByteArrayInputStream(input)) {
            return read(inputStream, size);
        }/*from  w  w  w  . j a va2s.  co m*/
    }

    public static double[][] read(InputStream inputStream, int size) throws IOException, ParseException {

        try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {

            double[][] result = new double[size][];

            int row = 0;

            String line;

            while ((line = bufferedReader.readLine()) != null) {

                String[] strings = line.trim().split("\\s+");

                double[] values = new double[strings.length];

                for (int i = 0; i < strings.length; i++) {
                    values[i] = Double.valueOf(strings[i].replace(COMMA, DOT));
                }

                result[row++] = values;

            }

            return result;

        }

    }
}

Related

  1. getSizeString(long size)
  2. getSizeText(long size)
  3. getSpaceSizeFromByte(long xB)
  4. getStringSize(String string)
  5. padString(String stringToPad, int size)
  6. readableBytes(long byteSize)
  7. readableSize(long num)
  8. readableSize(long size)
  9. readableSize(long size)