Here you can find the source of writeBytes(int[] data, String filename)
Parameter | Description |
---|---|
data | The integer array to write to disk. |
filename | The filename where the data should be written. |
Parameter | Description |
---|---|
IOException | an exception |
public static void writeBytes(int[] data, String filename) throws IOException
//package com.java2s; /* This file is part of the Joshua Machine Translation System. * /*from www .j ava 2 s . com*/ * Joshua is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 * of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ import java.io.FileOutputStream; import java.io.IOException; public class Main { /** * Writes data from the integer array to disk * as raw bytes. * * @param data The integer array to write to disk. * @param filename The filename where the data should be written. * @throws IOException */ public static void writeBytes(int[] data, String filename) throws IOException { FileOutputStream out = new FileOutputStream(filename); byte[] b = new byte[4]; for (int word : data) { for (int i = 0; i < 4; i++) { int offset = (b.length - 1 - i) * 8; b[i] = (byte) ((word >>> offset) & 0xFF); } out.write(b); } } }