objectinputstream

Fortify security issue “Unreleased resource stream” for try-with-resource

走远了吗. 提交于 2021-02-11 14:34:11
问题 Fortify security run Noncompliant Code public static A read(String path) throws IOException, ClassNotFoundException { try (ObjectInputStream os = new ObjectInputStream(new GZIPInputStream(new FileInputStream(path)))) { return (A) os.readObject(); } } It is saying "Unreleased Resource: Streams" , but it is inside try-with-resource then what can be the issue? please help me. 回答1: Likely the issue your tool is worried about is if GZIPInputStream or ObjectInputStream throws an exception during

Android/Java: How to track progress of InputStream

做~自己de王妃 提交于 2021-02-08 05:28:15
问题 I have the following code in my Android app, and not sure whether it is my Googling skills, but am not able to find a good tutorial on how to monitor progress of InputStream. private void restoreFromUri(Uri uri) { try { InputStream is = getContentResolver().openInputStream(uri); ObjectInputStream ois = new ObjectInputStream(is); ArrayList<String> myList = (ArrayList) ois.readObject(); ois.close(); is.close(); } catch (Exception e) { Snackbar.make(snackView, e.getMessage(), Snackbar.LENGTH

CipherInputStream hangs

◇◆丶佛笑我妖孽 提交于 2021-01-29 08:17:48
问题 I am attempting to use encryption to communicate over sockets using java. I've successfully communicated with sockets without encryption, but when I try with encryption the program freezes. Here is the parent Connection class that works just fine: public class Connection implements Runnable { protected Socket socket; protected ObjectInputStream objectInputStream; protected ObjectOutputStream objectOutputStream; protected Thread listeningThread; protected Thread dispatchThread; protected

Using resources of try-with-resources outside try

时光怂恿深爱的人放手 提交于 2021-01-28 03:50:40
问题 I'm using SocketChannel to send message between a server and a client. Once a client connects with a server, the server opens the InputStreams and OutputStream in a try-with-resources try, to receive messages from the client and send messages to the client, like so: try (ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) {} I want to access out outside of the try. The try contains a while loop that

Using resources of try-with-resources outside try

好久不见. 提交于 2021-01-28 02:44:07
问题 I'm using SocketChannel to send message between a server and a client. Once a client connects with a server, the server opens the InputStreams and OutputStream in a try-with-resources try, to receive messages from the client and send messages to the client, like so: try (ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) {} I want to access out outside of the try. The try contains a while loop that

How to read from file to Set with objectInputStream

我与影子孤独终老i 提交于 2020-06-22 04:31:41
问题 I'm trying to read some information from a file with ObjectInputStream method. For some reason, the file does not contain the information after the command executed. No error appears. This is my code : public boolean findUser(String user_id) throws Exception { try (ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(fILENAME))){ //System.out.println("Adsfasdf"); System.out.println(objectInputStream); Set<MarkoliaUser> users = (Set<MarkoliaUser>) objectInputStream

ObjectOutputStream methods: writeBytes(String str) vs writeUTF(String s);

拥有回忆 提交于 2020-05-11 07:47:04
问题 What's the main difference between the two? Still both of them are for writing Strings. public void writeUTF(String str) throws IOException Primitive data write of this String in modified UTF-8 format. vs public void writeBytes(String str) throws IOException Writes a String as a sequence of bytes. When should I use one rather than the other? 回答1: It's in the documentation... from DataOutput.writeBytes(String): Writes a string to the output stream. For every character in the string s, taken in

ObjectOutputStream methods: writeBytes(String str) vs writeUTF(String s);

匆匆过客 提交于 2020-05-11 07:44:06
问题 What's the main difference between the two? Still both of them are for writing Strings. public void writeUTF(String str) throws IOException Primitive data write of this String in modified UTF-8 format. vs public void writeBytes(String str) throws IOException Writes a String as a sequence of bytes. When should I use one rather than the other? 回答1: It's in the documentation... from DataOutput.writeBytes(String): Writes a string to the output stream. For every character in the string s, taken in

EOFException in objectinputstream readobject

萝らか妹 提交于 2020-04-07 09:35:13
问题 i want to make a server client application. i set everything up and i get this error. i want the app to wait till i get more data. java.io.EOFException at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) on the line: listener.Received(inputstream.readObject(), id.ID); Server code: isrunning = true; Thread input = new Thread(new Runnable(){ @Override public

Performance issue using Javas Object streams with Sockets

守給你的承諾、 提交于 2020-01-20 05:46:48
问题 I'm trying to do local IPC using Sockets and Object streams in Java however I'm seeing poor performance. I am testing the ping time of sending an object via an ObjectOutputStream to receiving a reply via an ObjectInputStream over a Socket. Here's the Requestor: public SocketTest(){ int iterations = 100; try { Socket socket = new Socket("localhost", 1212); ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream()); ObjectOutputStream objectOutputStream = new