FloatReader { synchronized public void readNextValues(float[] values) throws IOException { Validate.notNull(values, "A values array is required"); Validate.isTrue(values.length >= groupSize, "Provided values array has length " + values.length + ". Must have at least " + groupSize + " elements to read float group"); for (int i = 0; i < groupSize; i++) { values[i] = readFloat(); if (i != groupSize - 1) { skipToNextValueInGroup(); } } skipToStartOfNextGroup(); } FloatReader(InputStream is); private  FloatReader(InputStream is, int offset, int groupSize, int groupSeparation, int groupValueGap, FloatFormat format, ByteOrder byteOrder); synchronized void readNextValues(float[] values); synchronized float[] readNextValues(); synchronized void skipToNextGroup(); synchronized void skip(long numBytes); int getOffset(); int getGroupSize(); int getGroupSeparation(); int getGroupValueGap(); FloatFormat getFormat(); ByteOrder getByteOrder();  }
@Test (expected = IllegalArgumentException.class) public void testReadValuesNullArray() throws Exception { FloatReader classUnderTest = new FloatReader(is); classUnderTest.readNextValues(null); }
@Test (expected = IllegalArgumentException.class) public void testReadValuesEmptyArray() throws Exception { FloatReader classUnderTest = new FloatReader(is); classUnderTest.readNextValues(new float[0]); }
@Test public void testReadNextValuesDefaultPattern() throws Exception { FloatReader classUnderTest = new FloatReader(is); float expected = 0.0f; float[] values = new float[]{-9999}; for (int i = 0; i < 100; i++) { classUnderTest.readNextValues(values); assertEquals(expected, values[0], 0.001); expected += 0.3f; values[0] = -9999f; } }
@Test public void testReadNextValuesWithCustomFormat() throws Exception { FloatReader classUnderTest = FloatReader.Builder.newFloatReaderForStream(is) .withOffset(4) .withGroupSize(3) .withGroupSeparation(8) .withGroupValueGap(4) .build(); float[][] expected = {{0.3f, 0.9f, 1.5f},{2.4f, 3.0f, 3.6f}}; float[] values = new float[3]; classUnderTest.readNextValues(values); assertArrayEquals(expected[0], values, 0.001f); classUnderTest.readNextValues(values); assertArrayEquals(expected[1], values, 0.001f); }
@Test public void testReadNextValuesUsesNaNWhenNoMoreBytes() throws Exception { FloatReader classUnderTest = FloatReader.Builder.newFloatReaderForStream(is) .withGroupValueGap(1) .withGroupSize(101) .build(); float[] values = new float[101]; for (int i = 0; i < values.length; i++) { values[i] = -9999; } classUnderTest.readNextValues(values); assertTrue(Float.isNaN(values[100])); }