objectoutputstream

Cannot see the contents of the array printed in console [duplicate]

早过忘川 提交于 2019-12-13 10:54:10
问题 This question already has answers here : What's the simplest way to print a Java array? (33 answers) Closed last year . public RMI post(PrintStream stream, Object object) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); // oos.writeObject(System.rmi); oos.flush(); oos.close(); // stream.println("Class size: " + baos.toByteArray().length); stream.println("Class data: " + baos.toByteArray()); stream.flush(); stream.close();

Send multiple data type over socket

这一生的挚爱 提交于 2019-12-13 04:24:15
问题 I want to send multiple data type over socket. I have that code: when I create client, it generates public and private keys and sends the public to serve and the serve stores it. when client wants to send message to another client, it gets his public key from the server to encrypt the message. But when I run this code it freeze at client in dest_public_key=(PublicKey) oin.readObject() Why it stop at here? Why it doesn't read the PublicKey's object that the handler writes to it? Is there any

HashMap saving with ObjectOutputStream

我的未来我决定 提交于 2019-12-12 13:10:04
问题 To save teleportation points on command, I have an HashMap : public HashMap<Player, Location> mapHomes = new HashMap<>(); Which is accessed like this: if(cmd.getName().equalsIgnoreCase("sethome")){ Location loc = player.getLocation(); mapHomes.put(player, loc); sender.sendMessage("Home set !"); return true; } if(cmd.getName().equalsIgnoreCase("home")){ Location loc1 = mapHomes.get(player); player.teleport(loc1); sender.sendMessage("Teleported to home"); return true; } return false; Since

Client/Server socket. Doesn't read or write

こ雲淡風輕ζ 提交于 2019-12-12 06:29:31
问题 First of all here are a my compilable projects. IDE = Netbeans I have serversocket in one project and client socket in second project. ServerSocket Project's code Fragment: showStatus(String status); is method which appends text to statusWindow (JTextArea); Socket gameClientSocket,ObjectOutputStream gameoos and ObjectInputStream gameois is declared outside code fragment Code: private void configureSockets() { try{ properties.showStatus("GAME_THREAD-waiting someone to accept");

Writing objects to file while appending [duplicate]

时光毁灭记忆、已成空白 提交于 2019-12-11 19:42:51
问题 This question already has answers here : Write and read multiple objects to file (3 answers) Closed 2 years ago . I have created a program which registers members for a library system. To store the data i have used text files and to read/write i implemented serialization. My problem is when i register one member and try to register another member, the second member records won't get saved. To append writing to the file i used the keyword "true" as well. Here is what i have done: //Am writing

How to send a string array using sockets and objectoutputstream

百般思念 提交于 2019-12-11 03:38:14
问题 I have this to send string or integer but if i want to send a string array what should i use? // A string ("Hello, World"). out.write("Hello, World".getBytes()); // An integer (123). out.write(ByteBuffer.allocate(4).putInt(123).array()); Thanks in advance 回答1: Just write the array ObjectOutputStream out = ... String[] array = ... out.writeObject(array); If you're using ObjectOutputStream , there's no need to muck about with byte arrays - the class provides high-level methods to read and write

ObjectInputStream read a empty object

爱⌒轻易说出口 提交于 2019-12-11 01:33:41
问题 I wrote a object using ObjectOutputStream, and read it using ObjectInputStream, and tested it , I get the expected result. But when write the object in other machine, read it in my computer, the read object's members are empty. Could someone help me? thanks public class TrustNet implements Serializable{ public double[][] trusts; public double avg = 0; public TrustNet(int size){ trusts = new double[size][size]; } public void writeToFile(String fileName){ try(ObjectOutputStream writer = new

Java serialization. Field changes value [duplicate]

坚强是说给别人听的谎言 提交于 2019-12-11 01:32:17
问题 This question already has answers here : (java) ObjectInputStream deserializing wrong version of object [duplicate] (3 answers) Closed last year . I have the following problem. I can set the transaction state to be either "start, end or ongoing". I set this, then serialise my Transaction object over to the server, who retrieves it. Works like a charm the first time (when the transaction is in start mode), but then when I resend the object, this time in "ongoing" mode, the server continues to

What character encoding does ObjectOutputStream 's writeObject method use?

。_饼干妹妹 提交于 2019-12-10 16:15:52
问题 I read that Java uses UTF-16 encoding internally. i.e. I understand that if I have like: String var = "जनमत"; then the "जनमत" will be encoded in UTF-16 internally. So, If I dump this variable to some file such as below: fileOut = new FileOutputStream("output.xyz"); out = new ObjectOutputStream(fileOut); out.writeObject(var); will the encoding of the string "जनमत" in the file "output.xyz" be in UTF-16? Also, later on if I want to read from the file "output.xyz" via ObjectInputStream, will I be

Java ObjectOutputStream on Socket not flush()ing

我与影子孤独终老i 提交于 2019-12-10 14:29:10
问题 I'm working on a network app written in Java, using ObjectOutputStream and ObjectInputStream on top of Sockets to exchange messages. My code looks like this: Sender: ObjectOutputStream out; ObjectInputStream in; try{ Socket socket=new Socket(address, port); socket.setSoLinger(true, socketLingerTime); out=new ObjectOutputStream(socket.getOutputStream()); out.writeObject(message); out.flush(); out.close(); }catch (variousExceptions)... Receiver: Object incoming; try{ incoming