/** * Delegates to {@link EndianUtils#readSwappedDouble(InputStream)}. * @return the read long * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ @Override public double readDouble() throws IOException, EOFException { return EndianUtils.readSwappedDouble( in ); }
/** @see java.io.DataInput#readDouble() */ public double readDouble() throws IOException, EOFException { return EndianUtils.readSwappedDouble( in ); }
@Test public void testReadSwappedDouble() throws IOException { final byte[] bytes = new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; final double d1 = Double.longBitsToDouble( 0x0102030405060708L ); final double d2 = EndianUtils.readSwappedDouble( bytes, 0 ); assertEquals( d1, d2, 0.0 ); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); assertEquals( d1, EndianUtils.readSwappedDouble( input ), 0.0 ); }
@Test public void testEOFException() throws IOException { final ByteArrayInputStream input = new ByteArrayInputStream(new byte[] {}); try { EndianUtils.readSwappedDouble(input); fail("Expected EOFException"); } catch (final EOFException e) { // expected } }
@Test public void testSymmetryOfLong() { final double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123}; for (final double test : tests) { // testing the real problem byte[] buffer = new byte[8]; final long ln1 = Double.doubleToLongBits( test ); EndianUtils.writeSwappedLong(buffer, 0, ln1); final long ln2 = EndianUtils.readSwappedLong(buffer, 0); assertEquals( ln1, ln2 ); // testing the bug report buffer = new byte[8]; EndianUtils.writeSwappedDouble(buffer, 0, test); final double val = EndianUtils.readSwappedDouble(buffer, 0); assertEquals( test, val, 0 ); } }
/** * Delegates to {@link EndianUtils#readSwappedDouble(InputStream)}. * @return the read long * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ public double readDouble() throws IOException, EOFException { return EndianUtils.readSwappedDouble( in ); }
/** * Delegates to {@link EndianUtils#readSwappedDouble(InputStream)}. * @return the read long * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ public double readDouble() throws IOException, EOFException { return EndianUtils.readSwappedDouble( in ); }
/** * Delegates to {@link EndianUtils#readSwappedDouble(InputStream)}. * @return the read long * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ public double readDouble() throws IOException, EOFException { return EndianUtils.readSwappedDouble( in ); }
/** * Delegates to {@link EndianUtils#readSwappedDouble(InputStream)}. * @return the read long * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ public double readDouble() throws IOException, EOFException { return EndianUtils.readSwappedDouble( in ); }
/** * Delegates to {@link EndianUtils#readSwappedDouble(InputStream)}. * @return the read long * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ @Override public double readDouble() throws IOException, EOFException { return EndianUtils.readSwappedDouble( in ); }
/** * Delegates to {@link EndianUtils#readSwappedDouble(InputStream)}. * @return the read long * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ public double readDouble() throws IOException, EOFException { return EndianUtils.readSwappedDouble( in ); }
public ShpHeader(final DataInputStream dataInputStream) throws IOException { final int signature = dataInputStream.readInt(); if (signature != 9994) { throw new IOException("Not a valid shapefile. Expected 9994 as file header !"); } dataInputStream.skip(5 * 4); fileLength = dataInputStream.readInt(); version = EndianUtils.readSwappedInteger(dataInputStream); shapeType = EndianUtils.readSwappedInteger(dataInputStream); xmin = EndianUtils.readSwappedDouble(dataInputStream); ymin = EndianUtils.readSwappedDouble(dataInputStream); xmax = EndianUtils.readSwappedDouble(dataInputStream); ymax = EndianUtils.readSwappedDouble(dataInputStream); zmin = EndianUtils.readSwappedDouble(dataInputStream); zmax = EndianUtils.readSwappedDouble(dataInputStream); mmin = EndianUtils.readSwappedDouble(dataInputStream); mmax = EndianUtils.readSwappedDouble(dataInputStream); }
private void readShapeHeader() throws IOException { xmin = EndianUtils.readSwappedDouble(m_dataInputStream); ymin = EndianUtils.readSwappedDouble(m_dataInputStream); xmax = EndianUtils.readSwappedDouble(m_dataInputStream); ymax = EndianUtils.readSwappedDouble(m_dataInputStream); numParts = EndianUtils.readSwappedInteger(m_dataInputStream); numPoints = EndianUtils.readSwappedInteger(m_dataInputStream); if ((numParts + 1) > m_parts.length) { m_parts = new int[numParts + 1]; } for (int p = 0; p < numParts; p++) { m_parts[p] = EndianUtils.readSwappedInteger(m_dataInputStream); } m_parts[numParts] = numPoints; }
public PolylineMWritable readPolylineMWritable() throws IOException { final PolylineMWritable polylineMWritable = new PolylineMWritable(); readRecordHeader(); readShapeHeader(); polylineMWritable.lens = new int[numParts]; polylineMWritable.x = new double[numPoints]; polylineMWritable.y = new double[numPoints]; polylineMWritable.m = new double[numPoints]; int p = 0; for (int i = 0, j = 1; i < numParts; i++, j++) { final int count = m_parts[j] - m_parts[i]; polylineMWritable.lens[i] = count; for (int c = 0; c < count; c++, p++) { polylineMWritable.x[p] = EndianUtils.readSwappedDouble(m_dataInputStream); polylineMWritable.y[p] = EndianUtils.readSwappedDouble(m_dataInputStream); } } mmin = EndianUtils.readSwappedDouble(m_dataInputStream); mmax = EndianUtils.readSwappedDouble(m_dataInputStream); for (p = 0; p < numPoints; p++) { polylineMWritable.m[p] = EndianUtils.readSwappedDouble(m_dataInputStream); } return polylineMWritable; }
public Point queryPoint(final Point point) throws IOException { readRecordHeader(); point.setX(EndianUtils.readSwappedDouble(m_dataInputStream)); point.setY(EndianUtils.readSwappedDouble(m_dataInputStream)); return point; }
public Polygon queryPolygon(final Polygon polygon) throws IOException { polygon.setEmpty(); readRecordHeader(); readShapeHeader(); for (int i = 0, j = 1; i < numParts; ) { final int count = m_parts[j++] - m_parts[i++]; for (int c = 0; c < count; c++) { final double x = EndianUtils.readSwappedDouble(m_dataInputStream); final double y = EndianUtils.readSwappedDouble(m_dataInputStream); if (c > 0) { polygon.lineTo(x, y); } else { polygon.startPath(x, y); } } } polygon.closeAllPaths(); return polygon; }