outputstream

Problems reading a huge file of 12 MB (java.lang.OutOfMemoryError)

懵懂的女人 提交于 2019-12-07 16:10:15
问题 i need to open a file of 12 Megabytes, but actually i'm doing it creating a buffer of 12834566-byte, because the size of the file is 12MB and i am developing this app for Android mobile systems. Then, i supose i have to read with blocks of 1024 Kbytes instead of one block of 12 Mbytes, with a for, but i don't know how to do it, i need a little help with it. This is my actual code: File f = new File(getCacheDir()+"/berlin.mp3"); if (!f.exists()) try { InputStream is = getAssets().open("berlin

Play/Akka integration with Java OutputStreams

断了今生、忘了曾经 提交于 2019-12-07 08:47:38
问题 I'm writing a Play! application which exposes a REST API allowing users to generate PDF reports. I'm constrained by the requirements to use a old Java API to do the actual report generation. That library has a method generate(OutputStream out, ...) , i.e. it takes a java.io.OutputStream where it writes the resulting report. My problem is integrating this with Play/Akka to serve the contents in Chunked Encoding. To that end, I need to create an Enumerator[Array[Byte]] which somehow contains

Send a zero-data TCP/IP packet using Java

别说谁变了你拦得住时间么 提交于 2019-12-07 07:51:10
问题 My goal is to send a TCP packet with empty data field, in order to test the socket with the remote machine. I am using the OutputStream class's method of write(byte[] b). my attempt: outClient = ClientSocket.getOutputStream(); outClient.write(("").getBytes()); Doing so, the packet never show up on the wire. It works fine if "" is replaced by " " or any non-zero string. I tried jpcap, which worked with me, but didn't serve my goal. I thought of extending the OutputStream class, and

Does closing the socket close the stream?

耗尽温柔 提交于 2019-12-07 06:59:49
问题 I am working in a legacy java application, In many files, socket and streams are used, where sockets are getting closed but not the streams, is this necessary to close all the streams before closing the socket. because I am getting "too many open files error", is this error because of not closing the streams..... closing the socket will automatically close the streams also? 回答1: From the Socket Javadoc: Closing this socket will also close the socket's InputStream and OutputStream . So

ObjectOutputStream writing extra characters

时光怂恿深爱的人放手 提交于 2019-12-07 05:13:29
问题 I know that writers should be used instead of outputstreams when writing text, but still I don't understand why there are extra characters in the file outputStream.txt after running this program: public static void main(String[] args) throws FileNotFoundException, IOException { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("C:\\Data\\tmp\\outputStream.txt"))); oos.writeObject("SomeObject"); oos.writeUTF("SomeUTF"); oos.flush(); oos.close(); BufferedWriter

Readline output to file Node.js

倖福魔咒の 提交于 2019-12-07 03:06:18
问题 How can I write output to file? I tried instead of process.stdout use fs.createWriteStream(temp + '/export2.json') , but it's not working. var rl = readline.createInterface({ input: fs.createReadStream(temp + '/export.json'), output: process.stdout, terminal: false }); rl.on('line', function(line) { rl.write(line); }); 回答1: Referring to node/readline line 313: Interface.prototype.write = function(d, key) { if (this.paused) this.resume(); this.terminal ? this._ttyWrite(d, key) : this.

How can I force a CipherOutputStream to finish encrypting but leave the underlying stream open?

假如想象 提交于 2019-12-06 23:43:01
问题 I have a CipherOutputStream backed by another OutputStream. After I have finished writing all the data I need encrypted to the CipherOutputStream, I need to append some unencrypted data. The documentation for CipherOutputStream says that calling flush() will not force the final block out of the encryptor; for that I need to call close() . But close() also closes the underlying OutputStream, which I still need to write more to. How can I force the last block out of the encryptor without

Convert OutputStream to ByteArrayOutputStream

时光总嘲笑我的痴心妄想 提交于 2019-12-06 17:46:32
问题 I am trying to convert an OutputStream to a ByteArrayOutput Stream. I was unable to find any clear simple answers on how to do this. This question was asked in the title of the question on StackOverflow, but the body of the question aske how to change a ByteArrayStream to OuputStream . I have an OutputStream that is already created and this example given in the answer will not compile! That Question is Here I have an OutputStream that is already constructed and has a length of 44 bytes called

HttpUrlConnection getOutputStream have plroblem

ぐ巨炮叔叔 提交于 2019-12-06 11:33:26
问题 i make a android application and used for HttpUrlConnection, POST method, HoloEverywhere Library but i have problem... why happen to problem that i don't know... im think that getOutputStream() error because if used to getOutputStream() method show message " application unfortunately, * has stopped." and stopped application. main.java import java.io.BufferedOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import

Cannot invoke initializer for type UnsafePointer<_> with an argument list of type (UnsafeMutableRawPointer)

大城市里の小女人 提交于 2019-12-06 09:29:01
When I write the output stream in multipeer connectivity from audio buffer data I got the error Cannot invoke initializer for type UnsafePointer<_> with an argument list of type (UnsafeMutableRawPointer) I found the many solutions, but this solution not helpful for me. My code is: func send(_ buffer: AudioBuffer) { print(buffer.mData!) print(buffer.mDataByteSize) outputStreme?.write(UnsafePointer(buffer.mData), maxLength: buffer.mDataByteSize) } Thanks in advance..:) Please check the official reference when some sort of spec changes has affected with your code. In your case AudioBuffer.mData