ByteArrayOutputStream2 compressed = new ByteArrayOutputStream2(); DataOutputStream dout = new DataOutputStream(new DeflaterOutputStream(compressed, compresser)); int compressedSize = compressed.getCount(); ByteBuffer buf = ByteBuffer.allocateDirect(2 * 4 /* Int size */ + compressedSize); buf.putInt(MatDataTypes.miCOMPRESSED); buf.put(compressed.getBuf(), 0, compressedSize);
private void copy(InputStream stream, ByteArrayOutputStream2 output) throws IOException { final byte[] buffer = new byte[1024 * 4]; int n = 0; while (-1 != (n = stream.read(buffer))) { output.write(buffer, 0, n); } }
ByteArrayOutputStream2 compressed = new ByteArrayOutputStream2(); DataOutputStream dout = new DataOutputStream(new DeflaterOutputStream(compressed, compresser)); int compressedSize = compressed.getCount(); ByteBuffer buf = ByteBuffer.allocateDirect(2 * 4 /* Int size */ + compressedSize); buf.putInt(MatDataTypes.miCOMPRESSED); buf.put(compressed.getBuf(), 0, compressedSize);
/** * Read a mat file from a stream. Internally this will read the stream fully * into memory before parsing it. * * @param stream * a valid MAT-file stream to be read * @param filter * the array filter applied during reading * * @return the same as <code>{@link #getContent()}</code> * @see MatFileFilter * @throws IOException * if error occurs during file processing */ public synchronized Map<String, MLArray> read(InputStream stream, MatFileFilter filter) throws IOException { this.filter = filter; data.clear(); ByteBuffer buf = null; final ByteArrayOutputStream2 baos = new ByteArrayOutputStream2(); copy(stream, baos); buf = ByteBuffer.wrap(baos.getBuf(), 0, baos.getCount()); // Do the actual work parseData(buf); return getContent(); }
/** * Read a mat file from a stream. Internally this will read the stream fully * into memory before parsing it. * * @param stream * a valid MAT-file stream to be read * @param filter * the array filter applied during reading * * @return the same as <code>{@link #getContent()}</code> * @see MatFileFilter * @throws IOException * if error occurs during file processing */ public synchronized Map<String, MLArray> read(InputStream stream, MatFileFilter filter) throws IOException { this.filter = filter; data.clear(); ByteBuffer buf = null; final ByteArrayOutputStream2 baos = new ByteArrayOutputStream2(); copy(stream, baos); buf = ByteBuffer.wrap(baos.getBuf(), 0, baos.getCount()); // Do the actual work parseData(buf); return getContent(); }
private void copy(InputStream stream, ByteArrayOutputStream2 output) throws IOException { final byte[] buffer = new byte[1024 * 4]; int n = 0; while (-1 != (n = stream.read(buffer))) { output.write(buffer, 0, n); } }