List of utility methods to do File Write via ByteBuffer
boolean | writeDataLengthsToHeader(FileOutputStream fpo) write Data Lengths To Header long len; ByteBuffer bb = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN); FileChannel fc = fpo.getChannel(); try { len = fc.size(); fc.position(4); bb.putInt((int) (len - 8)); bb.flip(); ... |
void | writeDelimitedToOutputStream(byte[] bytes, OutputStream outputStream) Write length delimited data to the output stream outputStream.write(ByteBuffer.allocate(4).putInt(bytes.length).array()); outputStream.write(bytes); |
void | writeDouble(BufferedWriter bw, double[] buf) Write a given double array to the ASCII stream StringBuffer sb = new StringBuffer(); for (int i = 0; i < buf.length - 1; ++i) sb.append(Double.toString(buf[i]) + " "); sb.append(Double.toString(buf[buf.length - 1]) + "\n"); bw.append(sb.toString()); |
byte[] | writeEmpty() write Empty return ByteBuffer.allocate(4).putInt(EMPTY_CLIPBOARD).array();
|
void | writeFC(String fname, float[] res) write FC new File(fname).createNewFile(); ByteBuffer bbuffer = ByteBuffer.allocate(4 * res.length); FloatBuffer buffer = bbuffer.asFloatBuffer(); for (int i = 0; i < res.length; i++) buffer.put(res[i]); buffer.flip(); FileChannel fc = new RandomAccessFile(fname, "rw").getChannel(); fc.write(bbuffer); ... |
void | writeFile(File file, byte[] bytes) write File RandomAccessFile raf = new RandomAccessFile(file, "rw"); FileChannel channel = raf.getChannel(); channel.truncate(0); channel.write(ByteBuffer.wrap(bytes)); raf.close(); |
void | writeFile(File file, byte[] data) write File FileOutputStream output = null; FileChannel fc = null; try { output = new FileOutputStream(file); fc = output.getChannel(); ByteBuffer buffer = ByteBuffer.allocate(MAX_BUFFER_SIZE); int offset = 0; while (offset < data.length) { ... |
void | writeFile(String source, File outputFile) write a string to a file; the file will be overwritten if it already exists writeFile(source, outputFile, true); |
void | writeFileAsByteArray(File file, byte[] par2Data) write File As Byte Array ByteBuffer bb; FileChannel fc = null; try { fc = new FileOutputStream(file).getChannel(); bb = ByteBuffer.wrap(par2Data); fc.write(bb); } finally { if (fc != null) ... |
void | writeFileAsStringArray(File file, String[] par2DataArray) write File As String Array StringBuilder sb = new StringBuilder(); for (String t : par2DataArray) { sb.append(t); writeFileAsString(file, sb.toString()); |