Ejemplo n.º 1
0
 private static void saveID(String clientid) {
   try {
     final OutputStream os =
         Persistence.get().getOutputStream(false, stendhal.getGameFolder(), FILE_NAME);
     final OutputStreamWriter writer = new OutputStreamWriter(os, "UTF-8");
     try {
       writer.write(clientid);
     } finally {
       writer.close();
     }
   } catch (final IOException e) {
     logger.error("Can't write " + stendhal.getGameFolder() + FILE_NAME, e);
   }
 }
Ejemplo n.º 2
0
 private static String readID() {
   String clientid = null;
   try {
     final InputStream is =
         Persistence.get().getInputStream(false, stendhal.getGameFolder(), FILE_NAME);
     final BufferedInputStream bis = new BufferedInputStream(is);
     try {
       ByteArrayOutputStream buf = new ByteArrayOutputStream();
       int result = bis.read();
       while (result != -1) {
         byte b = (byte) result;
         buf.write(b);
         result = bis.read();
       }
       clientid = buf.toString("UTF-8").trim();
     } finally {
       bis.close();
       is.close();
     }
   } catch (final IOException e) {
     // ignore exception
   }
   return clientid;
 }