From d15ae9de9e3000a29a379a04f66dd5cf1d58b587 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Thu, 26 Apr 2012 15:15:46 +0000 Subject: [PATCH] refs #12 Small code fixes and proper test implementation. Serializer does now store a string as a string and does not convert it into an object. --- src/eva2/client/EvAClient.java | 3 ++- src/eva2/tools/Serializer.java | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/eva2/client/EvAClient.java b/src/eva2/client/EvAClient.java index b6f0792a..235c06f2 100644 --- a/src/eva2/client/EvAClient.java +++ b/src/eva2/client/EvAClient.java @@ -847,7 +847,8 @@ public class EvAClient implements RemoteStateListener, Serializable { } selectedModule = (String) JOptionPane.showInputDialog(evaFrame.getContentPane(), - "Which module do you want \n to load on host: " + comAdapter.getHostName() + " ?", "Load optimization module on host", + "Which module do you want \n to load on host: " + comAdapter.getHostName() + " ?", + "Load optimization module on host", JOptionPane.QUESTION_MESSAGE, null, ModuleNameList, diff --git a/src/eva2/tools/Serializer.java b/src/eva2/tools/Serializer.java index 8a47084e..351a0a7f 100644 --- a/src/eva2/tools/Serializer.java +++ b/src/eva2/tools/Serializer.java @@ -99,35 +99,38 @@ public class Serializer { } /** - * Serialize the string s and - * store its serialized state in File with name Filename. - * - * @param filename The file + * Serialize the string data and write it to the OutputStream. + * + * @param outStream The output stream * @param data The string data **/ public static void storeString(final OutputStream outStream, final String data) { try { - store(data, outStream, false); + outStream.write(data.getBytes()); } catch (Exception ex) { LOGGER.log(Level.SEVERE, "Could not write string to stream", ex); } } /** - * Deserialize the contents of File filename containing + * Deserialize the contents of the InputStream containing * a string and return the resulting string. * - * @param filename The file - * @return The deserialized data from the file + * @param inputStream The input stream to read from + * @return The deserialized data from the stream **/ public static String loadString(final InputStream inputStream) { - String data = null; + StringBuilder sBuilder = new StringBuilder(); try { - data = (String) load(inputStream); + int data = inputStream.read(); + while (data != -1) { + sBuilder.append((char) data); + data = inputStream.read(); + } } catch (Exception ex) { - LOGGER.log(Level.SEVERE, "Could not load string from file!", ex); + LOGGER.log(Level.SEVERE, "Could not load string from stream!", ex); } - return data; + return sBuilder.toString(); } /**