List of usage examples for com.google.common.io LittleEndianDataOutputStream close
@Override public void close() throws IOException
From source file:de.nx42.maps4cim.map.TextureMap.java
/** * Stores the texture map in the specified output stream, storing the integers * in little endian byte order/*from w ww . j a v a2s . c om*/ * @param out the output stream to write the texture map into * @param textureMap the texture map to write * @throws MapGeneratorException when the size of the texture map is invalid * @throws IOException when the resulting map can't be written */ protected void storeByteStream(OutputStream out, int[][] textureMap) throws MapGeneratorException, IOException { if (isValidSize(textureMap)) { // byte outputput stream, wrapped by a little endian integer processor ByteArrayOutputStream bos = new ByteArrayOutputStream(byteAmount); LittleEndianDataOutputStream dos = new LittleEndianDataOutputStream(bos); // pass the resulting integers to the little endian byte output stream for (int y = 0; y < edgeLength; y++) { for (int x = 0; x < edgeLength; x++) { dos.writeInt(textureMap[x][y]); } } // writeTo to the user defined output streame bos.writeTo(out); // close streams dos.close(); bos.close(); } else { throw new MapGeneratorException( "The size of the texture map is invalid. " + "Only Maps with 2048 * 2048 blocks are allowed"); } }
From source file:de.nx42.maps4cim.map.ReliefMap.java
/** * Stores the relief map in the specified output stream, transforming * the floats to little endian 32 bit integers. * @param out the output stream to write the relief map into * @param reliefMap the relief map to write * @throws MapGeneratorException when the size of the relief map is invalid * @throws IOException when the resulting map can't be written *//* ww w. j a va 2 s . c om*/ protected void storeByteStream(OutputStream out, float[][] reliefMap) throws MapGeneratorException, IOException { if (isValidSize(reliefMap)) { // byte outputput stream, wrapped by a little endian integer processor ByteArrayOutputStream bos = new ByteArrayOutputStream(byteAmount); LittleEndianDataOutputStream dos = new LittleEndianDataOutputStream(bos); // pass the resulting integers to the little endian byte output stream for (int y = 0; y < edgeLength; y++) { for (int x = 0; x < edgeLength; x++) { // convert the floats (meter) to integers (millimeter) dos.writeInt((int) (reliefMap[y][x] * 1000)); } } // write to the user defined output stream bos.writeTo(out); // close streams dos.close(); bos.close(); } else { throw new MapGeneratorException("The size of the relief map is invalid. " + "Only Maps with 2049 * 2049 control points are allowed"); } }