public void xx() {
    try {
      PublicKey pubKey = key;

      // FileInputStream sigfis = new FileInputStream(args[1]);
      byte[] sigToVerify = (byte[]) objIn.readObject();
      // sigfis.read(sigToVerify);
      // sigfis.close();

      Signature sig = Signature.getInstance("SHA1withDSA", "SUN");
      sig.initVerify(pubKey);

      FileInputStream datafis = (FileInputStream) objIn.readObject();
      BufferedInputStream bufin = new BufferedInputStream(datafis);

      byte[] buffer = new byte[1024];
      int len;
      while (bufin.available() != 0) {
        len = bufin.read(buffer);
        sig.update(buffer, 0, len);
      }
      ;

      bufin.close();

      boolean verifies = sig.verify(sigToVerify);

      System.out.println("signature verifies: " + verifies);
    } catch (Exception e) {
      System.err.println("Caught exception " + e.toString());
    }
  }
示例#2
1
  static void serTest(Map s, int size) throws Exception {
    if (!(s instanceof Serializable)) return;
    System.out.print("Serialize              : ");

    for (int i = 0; i < size; i++) {
      s.put(new Integer(i), Boolean.TRUE);
    }

    long startTime = System.currentTimeMillis();

    FileOutputStream fs = new FileOutputStream("MapCheck.dat");
    ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(fs));
    out.writeObject(s);
    out.close();

    FileInputStream is = new FileInputStream("MapCheck.dat");
    ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(is));
    Map m = (Map) in.readObject();

    long endTime = System.currentTimeMillis();
    long time = endTime - startTime;

    System.out.print(time + "ms");

    if (s instanceof IdentityHashMap) return;
    reallyAssert(s.equals(m));
  }
 public static void main(String[] args) throws IOException, ClassNotFoundException {
   File f = new File("objects2.dat");
   if (!f.exists()) {
     System.out.println("Creating objects and writing them to file:");
     SC c = new SC();
     SO o1 = new SO(1, c), o2 = new SO(2, c);
     o1.c.ci = 3;
     o2.c.ci = 4; // update the shared c twice
     o1.cprint();
     o2.cprint(); // prints i1c4 i2c4
     OutputStream os = new FileOutputStream(f);
     ObjectOutputStream oos1 = new ObjectOutputStream(os);
     oos1.writeObject(o1);
     oos1.flush();
     ObjectOutputStream oos2 = new ObjectOutputStream(os);
     oos2.writeObject(o2);
     oos2.close();
     System.out.println("\nRun the example again to read objects from file");
   } else {
     System.out.println("Reading objects from file (non-shared c):");
     InputStream is = new FileInputStream(f);
     ObjectInputStream ois1 = new ObjectInputStream(is);
     SO o1i = (SO) (ois1.readObject());
     ObjectInputStream ois2 = new ObjectInputStream(is);
     SO o2i = (SO) (ois2.readObject());
     o1i.cprint();
     o2i.cprint(); // prints i1c4 i2c4
     o1i.c.ci = 5;
     o2i.c.ci = 6; // update two different c's
     o1i.cprint();
     o2i.cprint(); // prints i1c5 i2c6
     f.delete();
   }
   System.out.println();
 }
示例#4
0
  public static void main(String[] args) throws IOException, ClassNotFoundException {

    Singleton instance = Singleton.getInstance();

    // Serializing the singleton instance
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("singleton.tmp"));
    oos.writeObject(instance);
    oos.close();

    // Recreating the instance by reading the serialized object data store
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("singleton.tmp"));
    Singleton singleton = (Singleton) ois.readObject();
    ois.close();

    // Recreating the instance AGAIN by reading the serialized object data store
    ObjectInputStream ois2 = new ObjectInputStream(new FileInputStream("singleton.tmp"));
    Singleton singleton1 = (Singleton) ois2.readObject();
    ois2.close();

    // The singleton behavior have been broken
    System.out.println("Instance reference check : " + singleton.getInstance());
    System.out.println("Instance reference check : " + singleton1.getInstance());
    System.out.println("=========================================================");
    System.out.println("Object reference check : " + singleton);
    System.out.println("Object reference check : " + singleton1);
  }
  public ServerSolution() {
    accountMap = new HashMap<String, Account>();
    File file = new File(fileName);
    ObjectInputStream in = null;
    try {
      if (file.exists()) {
        System.out.println("Reading from file " + fileName + "...");
        in = new ObjectInputStream(new FileInputStream(file));

        Integer sizeI = (Integer) in.readObject();
        int size = sizeI.intValue();
        for (int i = 0; i < size; i++) {
          Account acc = (Account) in.readObject();
          if (acc != null) accountMap.put(acc.getName(), acc);
        }
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (Throwable t) {
          t.printStackTrace();
        }
      }
    }
  }
  static boolean loadDat(String path) {
    //        ByteArray byteArray = ByteArray.createByteArray(path);
    //        if (byteArray == null) return false;
    //
    //        int size = byteArray.nextInt(); // 这两个数组从byte转为int竟然要花4秒钟
    //        start = new int[size];
    //        for (int i = 0; i < size; ++i)
    //        {
    //            start[i] = byteArray.nextInt();
    //        }
    //
    //        size = byteArray.nextInt();
    //        pair = new int[size];
    //        for (int i = 0; i < size; ++i)
    //        {
    //            pair[i] = byteArray.nextInt();
    //        }

    try {
      ObjectInputStream in = new ObjectInputStream(new FileInputStream(path));
      start = (int[]) in.readObject();
      pair = (int[]) in.readObject();
      in.close();
    } catch (Exception e) {
      logger.warning("尝试载入缓存文件" + path + "发生异常[" + e + "],下面将载入源文件并自动缓存……");
      return false;
    }
    return true;
  }
 @SuppressWarnings({"boxing", "unchecked"})
 public void loadCache() {
   this.cache.clear();
   try {
     ObjectInputStream in = new ObjectInputStream(new FileInputStream(CACHE_FILE));
     this.remoteDiscoveryImpl.syso("load cache");
     try {
       final int cacheSize = (Integer) in.readObject();
       //					syso("size "+cacheSize);
       for (int i = 0; i < cacheSize; ++i) {
         HashMap<RemoteManagerEndpoint, Entry> rmee = new HashMap<RemoteManagerEndpoint, Entry>();
         Class<? extends Plugin> plugin = (Class<? extends Plugin>) in.readObject();
         this.remoteDiscoveryImpl.syso(plugin.getCanonicalName());
         //						syso("\t"+i+"'"+pluginName+"'");
         int numEntries = (Integer) in.readObject();
         //						syso("\t"+numEntries);
         for (int j = 0; j < numEntries; ++j) {
           Entry entry = (Entry) in.readObject();
           //							syso("\t\t"+entry);
           rmee.put(entry.manager, entry);
         }
         this.cache.put(plugin, rmee);
       }
     } catch (ClassNotFoundException e) {
       e.printStackTrace();
     } finally {
       in.close();
     }
   } catch (FileNotFoundException e) {
     this.remoteDiscoveryImpl.logger.warning("Loading cache file" + CACHE_FILE + " failed.");
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
示例#8
0
  /**
   * Not only deserialises the object, also performs adjustments on the timestamps to bring them in
   * alignment with the local time. Reads the current time on the peer node first. If the timestamp
   * of any items in the cache or commands are newer throws and IOException, because that means the
   * object is corrupted. Sets the timestamp of the contribution of the peer (if any) to the current
   * local time.
   */
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {

    name = (String) in.readObject();

    cache = new Hashtable();
    commands = new Hashtable();

    final long max = in.readLong(); // the timestamp that should be maximal
    final long diff = System.currentTimeMillis() - max;
    myContribution = (ContributionBox) in.readObject();
    if (myContribution != null) myContribution.timeStamp = max + diff;

    int cachesize = in.readInt();
    for (int i = 0; i < cachesize; ++i) {
      ContributionBox cb = (ContributionBox) in.readObject();
      if (cb.timeStamp > max)
        throw new IOException("corrupted timestamp in cache: " + cb.timeStamp + " " + max);
      cb.timeStamp += diff;
      cache.put(cb.contributor.name, cb);
    }

    int commandssize = in.readInt();
    for (int i = 0; i < commandssize; ++i) {
      Object comm = in.readObject();
      long time = in.readLong();
      if (time > max) throw new IOException("corrupted timestamp in commands: " + time + " " + max);
      time += diff;
      commands.put(comm, new Long(time));
    }
  }
  void ReceiveFileChunksFromServer() throws Exception, ClassNotFoundException {
    try {
      if (flagFilename) {
        filename = (String) in.readObject();
        totalChunks = Integer.parseInt((String) in.readObject());
        flagFilename = false;
      }

      if (availableChunks == null) availableChunks = new File[totalChunks];

      if (requiredChunks == null) requiredChunks = new File[totalChunks];

      int partNumber = Integer.parseInt((String) in.readObject());

      File partFile = new File("chunks/" + filename + "." + partNumber);
      byte[] msg = (byte[]) in.readObject();
      Files.write(partFile.toPath(), msg);
      availableChunks[partNumber] = partFile;
      System.out.println("Received chunk " + partNumber);
    } catch (ClassNotFoundException e) {
      flag = true;
    } catch (Exception e) {
      flag = true;
    }
  }
示例#10
0
 /**
  * Read an object from a deserialization stream.
  *
  * @param s An object deserialization stream.
  * @throws ClassNotFoundException If the object's class read from the stream cannot be found.
  * @throws IOException If an error occurs reading from the stream.
  */
 @SuppressWarnings("unchecked")
 private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
   s.defaultReadObject();
   final T value = (T) s.readObject();
   final List<Node<T>> children = (List<Node<T>>) s.readObject();
   node = new Node<>(value, children);
 }
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();

    isAdapter = in.readBoolean();
    if (isAdapter) {
      if (adapter_readAdapterObject == null) throw new ClassNotFoundException();
      Object[] args = {this, in};
      try {
        javaObject = adapter_readAdapterObject.invoke(null, args);
      } catch (Exception ex) {
        throw new IOException();
      }
    } else {
      javaObject = in.readObject();
    }

    String className = (String) in.readObject();
    if (className != null) {
      staticType = Class.forName(className);
    } else {
      staticType = null;
    }

    initMembers();
  }
 private void load(InputStream is) throws IOException, ClassNotFoundException, CoreException {
   // try to read the file version number. Pre 2.0 versions had no number
   int version = is.read();
   if (version == KEYRING_FILE_VERSION) {
     // read the authorization data
     CipherInputStream cis = new CipherInputStream(is, password);
     ObjectInputStream ois = new ObjectInputStream(cis);
     try {
       authorizationInfo = (Hashtable) ois.readObject();
       protectionSpace = (Hashtable) ois.readObject();
     } finally {
       ois.close();
     }
   } else {
     // the format has changed, just log a warning
     InternalPlatform.getDefault()
         .log(
             new Status(
                 IStatus.WARNING,
                 Platform.PI_RUNTIME,
                 Platform.FAILED_READ_METADATA,
                 Messages.meta_authFormatChanged,
                 null));
     // close the stream and save a new file in the correct format
     try {
       is.close();
     } catch (IOException e) {
       // ignore failure to close
     }
     needsSaving = true;
     save();
   }
 }
示例#13
0
  public ArrayList<FIncomePO> findbyHall(String hall) throws RemoteException, IOException {
    ArrayList<FIncomePO> income = new ArrayList<FIncomePO>();
    ObjectInputStream os = null;
    System.out.println("start find!");
    try {
      FileInputStream fs = new FileInputStream(file);
      os = new ObjectInputStream(fs);
      FIncomePO po = (FIncomePO) os.readObject();

      while (fs.available() > 0) {
        byte[] buf = new byte[4];
        fs.read(buf);
        FIncomePO incomepo = (FIncomePO) os.readObject();

        if (incomepo.getShop().equals(hall)) {
          income.add(incomepo);
        }
      }

      return income;
    } catch (Exception e) {
      return null;
    } finally {
      os.close();
    }
  }
示例#14
0
  public ArrayList<FIncomePO> findAll() throws RemoteException {

    ArrayList<FIncomePO> incomeList = new ArrayList<FIncomePO>();

    FileInputStream fis = null;
    ObjectInputStream ois = null;
    try {
      fis = new FileInputStream(file);
      ois = new ObjectInputStream(fis);

      FIncomePO in = (FIncomePO) ois.readObject();

      while (fis.available() > 0) {
        byte[] buf = new byte[4];
        fis.read(buf);
        FIncomePO incomepo = (FIncomePO) ois.readObject();
        incomeList.add(incomepo);
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        ois.close();
      } catch (IOException e) {
        // TODO 自动生成的 catch 块
        e.printStackTrace();
      }
    }
    return incomeList;
  }
示例#15
0
  public ArrayList<FIncomePO> findByTime(String time1, String time2)
      throws RemoteException, IOException {
    ArrayList<FIncomePO> income = new ArrayList<FIncomePO>();
    ObjectInputStream os = null;

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    try {
      Date date1 = formatter.parse(time1);
      Date date2 = formatter.parse(time2);

      FileInputStream fs = new FileInputStream(file);
      os = new ObjectInputStream(fs);
      FIncomePO po = (FIncomePO) os.readObject();

      while (fs.available() > 0) {
        byte[] buf = new byte[4];
        fs.read(buf);
        FIncomePO incomepo = (FIncomePO) os.readObject();

        if (formatter.parse(incomepo.getTime()).after(date1)
            && formatter.parse(incomepo.getTime()).before(date2)) {

          income.add(incomepo);
        }
      }

      return income;
    } catch (Exception e) {
      return null;
    } finally {
      os.close();
    }
  }
示例#16
0
  public void run() {
    try {
      ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
      ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());

      BigInteger bg = dhSpec.getG();
      BigInteger bp = dhSpec.getP();
      oos.writeObject(bg);
      oos.writeObject(bp);

      KeyPairGenerator kpg = KeyPairGenerator.getInstance("DH");
      kpg.initialize(1024);
      KeyPair kpa = (KeyPair) ois.readObject();
      KeyAgreement dh = KeyAgreement.getInstance("DH");
      KeyPair kp = kpg.generateKeyPair();

      oos.writeObject(kp);

      dh.init(kp.getPrivate());
      Key pk = dh.doPhase(kpa.getPublic(), true);

      MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
      byte[] rawbits = sha256.digest(dh.generateSecret());

      Cipher c = Cipher.getInstance(CIPHER_MODE);
      SecretKey key = new SecretKeySpec(rawbits, 0, 16, "AES");
      byte ivbits[] = (byte[]) ois.readObject();
      IvParameterSpec iv = new IvParameterSpec(ivbits);
      c.init(Cipher.DECRYPT_MODE, key, iv);

      Mac m = Mac.getInstance("HmacSHA1");
      SecretKey mackey = new SecretKeySpec(rawbits, 16, 16, "HmacSHA1");
      m.init(mackey);

      byte ciphertext[], cleartext[], mac[];
      try {
        while (true) {
          ciphertext = (byte[]) ois.readObject();
          mac = (byte[]) ois.readObject();
          if (Arrays.equals(mac, m.doFinal(ciphertext))) {
            cleartext = c.update(ciphertext);
            System.out.println(ct + " : " + new String(cleartext, "UTF-8"));
          } else {
            // System.exit(1);
            System.out.println(ct + "error");
          }
        }
      } catch (EOFException e) {
        cleartext = c.doFinal();
        System.out.println(ct + " : " + new String(cleartext, "UTF-8"));
        System.out.println("[" + ct + "]");
      } finally {
        if (ois != null) ois.close();
        if (oos != null) oos.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#17
0
 public void loadModel(String file) throws Exception {
   ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
   params.parameters = (double[]) in.readObject();
   pipe.dataAlphabet = (Alphabet) in.readObject();
   pipe.typeAlphabet = (Alphabet) in.readObject();
   in.close();
   pipe.closeAlphabets();
 }
示例#18
0
 private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
   question = (String) in.readObject();
   final Object[] answer = new Object[in.readInt()];
   for (int x = 0; x < answer.length; x++) {
     answer[x] = in.readObject();
   }
   this.answer = TokenList.createD(answer);
 }
示例#19
0
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {

    in.defaultReadObject();

    Object prefix = in.readObject();
    Object uri = in.readObject();

    if (prefix != null) { // else leave namespace null here
      namespace = Namespace.getNamespace((String) prefix, (String) uri);
    }
  }
示例#20
0
 /**
  * Deserialize alphabet
  *
  * @param in
  * @throws IOException
  * @throws ClassNotFoundException
  */
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   int version = in.readInt();
   int size = in.readInt();
   list = new ArrayList(size);
   map = new TObjectIntHashMap(size);
   for (int i = 0; i < size; i++) {
     Object o = in.readObject();
     map.put(o, i);
     list.add(o);
   }
   if (version > 0) instanceId = (VMID) in.readObject();
 }
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    int version = in.readInt();
    int string1Length = in.readInt();
    int string2Length = in.readInt();
    String string1 = (String) in.readObject();
    String string2 = (String) in.readObject();
    int size = in.readInt();
    if (size == NULL_INTEGER) {
      string1Blocks = null;
    } else {
      string1Blocks = new String[size];
      for (int i = 0; i < size; i++) {
        string1Blocks[i] = (String) in.readObject();
      }
    }

    size = in.readInt();
    if (size == NULL_INTEGER) {
      string2Blocks = null;
    } else {
      string2Blocks = new String[size];
      for (int i = 0; i < size; i++) {
        string2Blocks[i] = (String) in.readObject();
      }
    }

    TObjectIntHashMap string1Present = (TObjectIntHashMap) in.readObject();
    TObjectIntHashMap string2Present = (TObjectIntHashMap) in.readObject();
    TObjectIntHashMap lexicon = (TObjectIntHashMap) in.readObject();

    size = in.readInt();
    if (size == NULL_INTEGER) {
      block1Indices = null;
    } else {
      block1Indices = new int[size];
      for (int i = 0; i < size; i++) {
        block1Indices[i] = in.readInt();
      }
    }

    size = in.readInt();
    if (size == NULL_INTEGER) {
      block2Indices = null;
    } else {
      block2Indices = new int[size];
      for (int i = 0; i < size; i++) {
        block2Indices[i] = in.readInt();
      }
    }

    delim = in.readChar();
  }
示例#22
0
  public void loadModel(String file) throws Exception {
    ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
    params.parameters = (double[]) in.readObject();
    pipe.dataAlphabet = (Alphabet) in.readObject();
    pipe.typeAlphabet = (Alphabet) in.readObject();

    // afm 06-04-08
    if (options.separateLab) {
      classifier = (Classifier) in.readObject();
    }

    in.close();
    pipe.closeAlphabets();
  }
  private boolean sendLoginRequest(String userName, String password) throws Exception {
    boolean result = false;

    try {
      sslsocket = (SSLSocket) factory.createSocket(BURRITOPOS_SERVER_IP, BURRITOPOS_SERVER_PORT);
      in = new ObjectInputStream(sslsocket.getInputStream());
      out = new ObjectOutputStream(sslsocket.getOutputStream());

      String str = (String) in.readObject();
      dLog.trace("Got : " + str);
      out.writeObject(userName);
      str = (String) in.readObject();
      dLog.trace("Got : " + str);
      out.writeObject(password);
      str = (String) in.readObject();
      dLog.trace("Got : " + str);
      dLog.trace("good? " + str.split(" ")[0]);

      // check our input
      if (str.split(" ")[0].equals("OK")) {
        result = true;
      }

      out.writeObject("exit");
    } catch (Exception e1) {
      dLog.error("Exception in sendLoginRequest", e1);
    } finally {
      try {
        dLog.trace("Trying to close input stream");
        if (in != null) {
          in.close();
        }
        dLog.trace("Trying to close output stream");
        if (out != null) {
          out.close();
        }
        dLog.trace("Trying to close socket");
        if (sslsocket != null) {
          sslsocket.close();
        }
      } catch (Exception e2) {
        dLog.error("Exception closing socket", e2);
        throw (e2);
      }
    }

    dLog.trace("Returning result: " + result);
    return result;
  }
示例#24
0
  /**
   * Function awaits a User object followed by 0 or more Record objects in an array.
   *
   * @return true if successful
   * @throws IOException
   * @throws ClassNotFoundException
   */
  private static boolean waitForLoginData() throws IOException, ClassNotFoundException {
    user = (User) ois.readObject();

    if (user != null) {
      System.out.println(user.toString());

      records = (ArrayList<Record>) ois.readObject();
    } else {
      return false;
    }

    printRecords();

    return true;
  }
示例#25
0
  private Map<String, Pack> loadInstallationInformation(boolean modifyInstallation) {
    Map<String, Pack> installedpacks = new HashMap<String, Pack>();
    if (!modifyInstallation) {
      return installedpacks;
    }

    // installation shall be modified
    // load installation information
    ObjectInputStream oin = null;
    try {
      FileInputStream fin =
          new FileInputStream(
              new File(
                  installData.getInstallPath()
                      + File.separator
                      + InstallData.INSTALLATION_INFORMATION));
      oin = new ObjectInputStream(fin);
      List<Pack> packsinstalled = (List<Pack>) oin.readObject();
      for (Pack installedpack : packsinstalled) {
        installedpacks.put(installedpack.getName(), installedpack);
      }
      this.removeAlreadyInstalledPacks(installData.getSelectedPacks());
      logger.fine("Found " + packsinstalled.size() + " installed packs");

      Properties variables = (Properties) oin.readObject();

      for (Object key : variables.keySet()) {
        installData.setVariable((String) key, (String) variables.get(key));
      }
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      if (oin != null) {
        try {
          oin.close();
        } catch (IOException e) {
        }
      }
    }
    return installedpacks;
  }
示例#26
0
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   int version = in.readInt();
   this.encoding = (String) in.readObject();
   if (encoding.equals("null")) {
     encoding = null;
   }
 }
 private TaskObjectsExecutionResults runObject(TaskObjectsExecutionRequest obj)
     throws IOException, PDBatchTaskExecutorException {
   Object res = null;
   try {
     setAvailability(false);
     _oos.writeObject(obj);
     _oos.flush();
     res = _ois.readObject();
     setAvailability(true);
   } catch (IOException e) { // worker closed connection
     processException(e);
     throw e;
   } catch (ClassNotFoundException e) {
     processException(e);
     throw new IOException("stream has failed");
   }
   if (res instanceof TaskObjectsExecutionResults) {
     _isPrevRunSuccess = true;
     return (TaskObjectsExecutionResults) res;
   } else {
     PDBatchTaskExecutorException e =
         new PDBatchTaskExecutorException("worker failed to run tasks");
     if (_isPrevRunSuccess == false && !sameAsPrevFailedJob(obj._tasks)) {
       processException(e); // twice a loser, kick worker out
     }
     _isPrevRunSuccess = false;
     _prevFailedBatch = obj._tasks;
     throw e;
   }
 }
 private void setHPubAccessHandleString(String encodedHandleWithSpaces) {
   String encodedHandle = removeSpaceCharacters(encodedHandleWithSpaces);
   if ((encodedHandle == null) || (encodedHandle.length() < 5)) {
     return;
   }
   try {
     byte[] handleByteArray = null;
     sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder();
     try {
       handleByteArray = dec.decodeBuffer(encodedHandle);
     } catch (Exception e) {
       System.out.println("AccessEJBTemplate::setHPubAccessHandleString()  decoding buffer");
     }
     ;
     ByteArrayInputStream bais = new ByteArrayInputStream(handleByteArray);
     javax.ejb.Handle h1 = null;
     try {
       ObjectInputStream ois = new ObjectInputStream(bais);
       hPubAccessHandle = (javax.ejb.Handle) ois.readObject();
     } catch (Exception ioe) {
       System.out.println("Exception reading handle object");
     }
   } catch (Exception e) {
     e.printStackTrace(System.err);
     System.out.println("Exception AccessEJBTemplate::setHPubAccessHandleString()");
   }
   return;
 }
示例#29
0
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   int featuresLength;
   int version = in.readInt();
   ilist = (InstanceList) in.readObject();
   numTopics = in.readInt();
   alpha = in.readDouble();
   beta = in.readDouble();
   tAlpha = in.readDouble();
   vBeta = in.readDouble();
   int numDocs = ilist.size();
   topics = new int[numDocs][];
   for (int di = 0; di < ilist.size(); di++) {
     int docLen = ((FeatureSequence) ilist.get(di).getData()).getLength();
     topics[di] = new int[docLen];
     for (int si = 0; si < docLen; si++) topics[di][si] = in.readInt();
   }
   docTopicCounts = new int[numDocs][numTopics];
   for (int di = 0; di < ilist.size(); di++)
     for (int ti = 0; ti < numTopics; ti++) docTopicCounts[di][ti] = in.readInt();
   int numTypes = ilist.getDataAlphabet().size();
   typeTopicCounts = new int[numTypes][numTopics];
   for (int fi = 0; fi < numTypes; fi++)
     for (int ti = 0; ti < numTopics; ti++) typeTopicCounts[fi][ti] = in.readInt();
   tokensPerTopic = new int[numTopics];
   for (int ti = 0; ti < numTopics; ti++) tokensPerTopic[ti] = in.readInt();
 }
示例#30
0
  // Load a neural network from memory
  public NeuralNetwork loadGenome() {

    // Read from disk using FileInputStream
    FileInputStream f_in = null;
    try {
      f_in = new FileInputStream("./memory/mydriver.mem");
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    // Read object using ObjectInputStream
    ObjectInputStream obj_in = null;
    try {
      obj_in = new ObjectInputStream(f_in);
    } catch (IOException e) {
      e.printStackTrace();
    }

    // Read an object
    try {
      return (NeuralNetwork) obj_in.readObject();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
    return null;
  }