/** Read a long from a stream. * @param inputStream is the input stream. * @return the long value read from the stream. */ static long readLong(final InputStream inputStream) throws IOException { final long lower = ((long)(readInt(inputStream))) & 0x00000000ffffffffL; final long upper = (((long)(readInt(inputStream))) << 32) & 0xffffffff00000000L; return lower + upper; }
/** Read byte array. * @param inputStream is the input stream. * @return the byte array. */ static byte[] readByteArray(final InputStream inputStream) throws IOException { int stringLength = readInt(inputStream); int stringOffset = 0; final byte[] bytes = new byte[stringLength]; while (stringLength > 0) { final int amt = inputStream.read(bytes, stringOffset, stringLength); if (amt == -1) { throw new IOException("Unexpected end of input stream"); } stringOffset += amt; stringLength -= amt; } return bytes; }
private static List<List<GeoPoint>> readPointsList(final PlanetModel planetModel, final InputStream inputStream) throws IOException { final int count = SerializableObject.readInt(inputStream); final List<List<GeoPoint>> array = new ArrayList<>(count); for (int i = 0; i < count; i++) { array.add(java.util.Arrays.asList(SerializableObject.readPointArray(planetModel, inputStream))); } return array; }
/** Read an array. * @param planetModel is the planet model. * @param inputStream is the input stream. * @return the array. */ static <T extends SerializableObject> T[] readHeterogeneousArray(final PlanetModel planetModel, final InputStream inputStream, final Class<T> clazz) throws IOException { final int count = readInt(inputStream); @SuppressWarnings("unchecked") final T[] rval = (T[])Array.newInstance(clazz, count); for (int i = 0; i < count; i++) { rval[i] = clazz.cast(readObject(planetModel, inputStream)); } return rval; }
/** Read an array. * @param planetModel is the planet model. * @param inputStream is the input stream. * @param clazz is the class of the objects to read. * @return the array. */ static <T extends SerializableObject> T[] readHomogeneousArray(final PlanetModel planetModel, final InputStream inputStream, final Class<T> clazz) throws IOException { final int count = readInt(inputStream); @SuppressWarnings("unchecked") final T[] rval = (T[])Array.newInstance(clazz, count); for (int i = 0; i < count; i++) { rval[i] = clazz.cast(readObject(planetModel, inputStream, clazz)); } return rval; }