Esempio n. 1
0
 ///////////////////////////////////////////////////////
 // Saving and loading models
 ///////////////////////////////////////////////////////
 public void saveModel(String file) throws IOException {
   ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
   out.writeObject(params.parameters);
   out.writeObject(pipe.dataAlphabet);
   out.writeObject(pipe.typeAlphabet);
   out.close();
 }
 public static void main(String[] args) throws Exception {
   int choice = 0;
   Socket server = new Socket("127.0.0.1", 1300);
   ObjectOutputStream out = new ObjectOutputStream(server.getOutputStream());
   ObjectInputStream in = new ObjectInputStream(server.getInputStream());
   Scanner scan = new Scanner(System.in);
   while (true) {
     System.out.println("::::::::::::::::::::::::::::::::MENU::::::::::::::::::::::::::::::::::");
     System.out.println("1.Arithmetic Operations\n2.Logical Operations\n3.FileLookUpOperations");
     System.out.println("Enter the choice:");
     choice = scan.nextInt();
     switch (choice) {
       case 1:
         out.writeObject(1);
         System.out.println(in.readObject());
         break;
       case 2:
         out.writeObject(2);
         System.out.println(in.readObject());
         break;
       case 3:
         out.writeObject(3);
         System.out.println(in.readObject());
         break;
       default:
         System.out.println("Invalid Option");
         break;
     }
   }
 }
 public void run() {
   try {
     ObjectInputStream oin = new ObjectInputStream(client.getInputStream());
     test = new testMessage((testMessage) oin.readObject());
     serverMain.textPane2.setText(
         serverMain.textPane2.getText() + (new Date()) + ":" + test.qq + "开始验证有无密保问题......\n");
     ObjectOutputStream oout = new ObjectOutputStream(client.getOutputStream());
     String returnQuestion = "select * from safeQuestion_" + test.qq + ";";
     ResultSet res_return = state2.executeQuery(returnQuestion);
     if (res_return.next()) {
       changed = 2;
       String text1 = res_return.getString("question");
       res_return.next();
       String text2 = res_return.getString("question");
       res_return.next();
       String text3 = res_return.getString("question");
       oout.writeObject(new safeQuestionOrAnswer(null, text1, text2, text3));
       oout.close();
       serverMain.textPane2.setText(serverMain.textPane2.getText() + test.qq + "有无密保问题!\n");
     } else {
       oout.writeObject(null);
       changed = 1;
       serverMain.textPane2.setText(serverMain.textPane2.getText() + test.qq + "无密保问题!\n");
     }
     client.close();
     state2.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 4
0
 public static void main(String[] args) throws IOException, ClassNotFoundException {
   House house = new House();
   List<Animal> animals = new ArrayList<Animal>();
   animals.add(new Animal("Bosco the dog", house));
   animals.add(new Animal("Ralph the hamster", house));
   animals.add(new Animal("Molly the cat", house));
   print("animals: " + animals);
   ByteArrayOutputStream buf1 = new ByteArrayOutputStream();
   ObjectOutputStream o1 = new ObjectOutputStream(buf1);
   o1.writeObject(animals);
   o1.writeObject(animals); // Write a 2nd set
   // Write to a different stream:
   ByteArrayOutputStream buf2 = new ByteArrayOutputStream();
   ObjectOutputStream o2 = new ObjectOutputStream(buf2);
   o2.writeObject(animals);
   // Now get them back:
   ObjectInputStream in1 = new ObjectInputStream(new ByteArrayInputStream(buf1.toByteArray()));
   ObjectInputStream in2 = new ObjectInputStream(new ByteArrayInputStream(buf2.toByteArray()));
   List animals1 = (List) in1.readObject(),
       animals2 = (List) in1.readObject(),
       animals3 = (List) in2.readObject();
   print("animals1: " + animals1);
   print("animals2: " + animals2);
   print("animals3: " + animals3);
 }
Esempio n. 5
0
  public void writeIndex(String location) {

    System.out.println("Writing index at: " + location);

    ObjectOutputStream objectOutputStream = null;

    try {

      File outputFile = new File(location);
      if (!outputFile.exists()) {
        outputFile.getParentFile().mkdirs();
        outputFile.createNewFile();
      }

      OutputStream file = new FileOutputStream(outputFile);
      BufferedOutputStream buffer = new BufferedOutputStream(file);
      objectOutputStream = new ObjectOutputStream(buffer);
      objectOutputStream.writeObject(tokenCountMap);
      objectOutputStream.writeObject(references);
    } catch (IOException ex) {
      System.out.println(
          "\nError writing index for " + author.getName() + " at location " + location);
    } finally {
      if (objectOutputStream != null)
        try {
          objectOutputStream.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
    }
  }
  /** java.io.ObjectOutputStream#writeUnshared(java.lang.Object) */
  public void test_writeUnshared2() throws Exception {
    // Regression for HARMONY-187
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);

    Object o = new Object[1];
    oos.writeObject(o);
    oos.writeUnshared(o);
    oos.writeObject(o);
    oos.flush();

    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));

    Object[] oa = new Object[3];
    for (int i = 0; i < oa.length; i++) {
      oa[i] = ois.readObject();
    }

    oos.close();
    ois.close();

    // All three conditions must be met
    assertNotSame("oa[0] != oa[1]", oa[0], oa[1]);
    assertNotSame("oa[1] != oa[2]", oa[1], oa[2]);
    assertSame("oa[0] == oa[2]", oa[0], oa[2]);
  }
  /**
   * java.io.ObjectOutputStream#writeInt(int)
   * java.io.ObjectOutputStream#writeObject(java.lang.Object)
   * java.io.ObjectOutputStream#writeUTF(java.lang.String)
   */
  public void testMixPrimitivesAndObjects() throws Exception {
    int i = 7;
    String s1 = "string 1";
    String s2 = "string 2";
    byte[] bytes = {1, 2, 3};
    try {
      oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
      oos.writeInt(i);
      oos.writeObject(s1);
      oos.writeUTF(s2);
      oos.writeObject(bytes);
      oos.close();

      ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));

      int j = ois.readInt();
      assertTrue("Wrong int :" + j, i == j);

      String l1 = (String) ois.readObject();
      assertTrue("Wrong obj String :" + l1, s1.equals(l1));

      String l2 = ois.readUTF();
      assertTrue("Wrong UTF String :" + l2, s2.equals(l2));

      byte[] bytes2 = (byte[]) ois.readObject();
      assertTrue("Wrong byte[]", Arrays.equals(bytes, bytes2));
    } finally {
      try {
        if (oos != null) oos.close();
        if (ois != null) ois.close();
      } catch (IOException e) {
      }
    }
  }
  @Override
  public void write(String path) throws IOException {
    File dir = FileUtils.getFile(path, "ensemble", getName());
    if (!dir.isDirectory()) {
      dir.mkdirs();
    }
    ObjectOutputStream oop =
        new ObjectOutputStream(new FileOutputStream(new File(dir, "similarityCoefficients")));
    oop.writeObject(simlarityCoefficients);
    oop.flush();
    oop.close();

    oop = new ObjectOutputStream(new FileOutputStream(new File(dir, "mostSimilarCoefficients")));
    oop.writeObject(mostSimilarCoefficients);
    oop.flush();
    oop.close();

    oop = new ObjectOutputStream(new FileOutputStream(new File(dir, "similarityInterpolator")));
    oop.writeObject(similarityInterpolator);
    oop.flush();
    oop.close();

    oop = new ObjectOutputStream(new FileOutputStream(new File(dir, "mostSimilarInterpolator")));
    oop.writeObject(mostSimilarInterpolator);
    oop.flush();
    oop.close();
  }
Esempio n. 9
0
    // we create a new socket for every request because don't want to depend on the state of a
    // socket
    // since we are going to do nasty stuff.
    private <E> E execute(String service, Object... args) throws Exception {
      Socket socket = new Socket(InetAddress.getByName(null), WorkerJvmManager.PORT);

      try {
        ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
        oos.writeObject(service);
        for (Object arg : args) {
          oos.writeObject(arg);
        }
        oos.flush();

        ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
        Object response = in.readObject();

        if (response instanceof TerminateWorkerException) {
          System.exit(0);
        }

        if (response instanceof Exception) {
          Exception exception = (Exception) response;
          Utils.fixRemoteStackTrace(exception, Thread.currentThread().getStackTrace());
          throw exception;
        }
        return (E) response;
      } finally {
        Utils.closeQuietly(socket);
      }
    }
Esempio n. 10
0
 private void writeObject(ObjectOutputStream out) throws IOException {
   int i, size;
   out.writeInt(CURRENT_SERIAL_VERSION);
   out.writeObject(name);
   out.writeInt(index);
   size = (destinationNames == null) ? NULL_INTEGER : destinationNames.length;
   out.writeInt(size);
   if (size != NULL_INTEGER) {
     for (i = 0; i < size; i++) {
       out.writeObject(destinationNames[i]);
     }
   }
   size = (destinations == null) ? NULL_INTEGER : destinations.length;
   out.writeInt(size);
   if (size != NULL_INTEGER) {
     for (i = 0; i < size; i++) {
       out.writeObject(destinations[i]);
     }
   }
   size = (labels == null) ? NULL_INTEGER : labels.length;
   out.writeInt(size);
   if (size != NULL_INTEGER) {
     for (i = 0; i < size; i++) out.writeObject(labels[i]);
   }
   out.writeObject(hmm);
 }
 @SuppressWarnings("boxing")
 public void saveCache() {
   try {
     ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(CACHE_FILE));
     this.remoteDiscoveryImpl.syso("save cache");
     try {
       //					syso("size"+this.cache.size());
       out.writeObject(this.cache.size());
       for (Map.Entry<Class<? extends Plugin>, HashMap<RemoteManagerEndpoint, Entry>> he :
           this.cache.entrySet()) {
         //						syso(he.getKey()+" " +he.getValue().size());
         this.remoteDiscoveryImpl.syso(he.getKey().getCanonicalName());
         out.writeObject(he.getKey());
         out.writeObject(he.getValue().size());
         for (Entry me : he.getValue().values()) {
           //							syso("\t"+me);
           out.writeObject(me);
         }
       }
       //					out.writeObject(this.cache);
     } finally {
       out.close();
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 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();
 }
Esempio n. 13
0
 @Override
 public synchronized void run() {
   boolean bName = true;
   while (listening) {
     try {
       Object object = in.readObject();
       if (bName) {
         if (object.getClass().equals(String.class)) {
           String s = (String) object;
           name = s.substring("В комнату вошел игрок ".length(), s.length() - 1);
         }
         bName = false;
       }
       synchronized (oos) {
         for (ObjectOutputStream out : oos) {
           out.writeObject(object);
         }
       }
     } catch (IOException | ClassNotFoundException e) {
       synchronized (oos) {
         oos.remove(forRemove);
         System.out.println("ServerThread " + oos.size());
         for (ObjectOutputStream out : oos) {
           try {
             out.writeObject("Игрок " + name + " покинул комнату\n");
           } catch (IOException e1) {
             /*Nothing TO DO */
           }
         }
       }
       break;
     }
   }
 }
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.writeInt(dataVersion);
   out.writeObject(profilePropName);
   out.writeObject(activeConceptPropName);
   out.writeObject(addressListPropName);
   out.writeObject(positionListPropName);
 }
Esempio n. 15
0
  private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeObject(this.getEncoded());
    out.writeObject(algorithm);
    out.writeBoolean(withCompression);

    attrCarrier.writeObject(out);
  }
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.writeInt(b);
   out.defaultWriteObject();
   out.writeObject(c);
   out.writeObject(d);
   out.writeObject(e);
 }
  /**
   * Used to serialize all children of this <tt>BeanContext</tt>.
   *
   * @param oos the <tt>ObjectOutputStream</tt> to use during serialization
   * @throws IOException if serialization failed
   */
  public final void writeChildren(ObjectOutputStream oos) throws IOException {
    if (serializable <= 0) return;

    boolean prev = serializing;

    serializing = true;

    int count = 0;

    synchronized (children) {
      Iterator i = children.entrySet().iterator();

      while (i.hasNext() && count < serializable) {
        Map.Entry entry = (Map.Entry) i.next();

        if (entry.getKey() instanceof Serializable) {
          try {
            oos.writeObject(entry.getKey()); // child
            oos.writeObject(entry.getValue()); // BCSChild
          } catch (IOException ioe) {
            serializing = prev;
            throw ioe;
          }
          count++;
        }
      }
    }

    serializing = prev;

    if (count != serializable) {
      throw new IOException("wrote different number of children than expected");
    }
  }
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.writeInt(CURRENT_SERIAL_VERSION);
   out.writeObject(name);
   out.writeObject(lexicon);
   out.writeBoolean(ignoreCase);
   out.writeBoolean(indvMatch);
 }
  /** java.io.ObjectOutputStream#useProtocolVersion(int) */
  public void test_useProtocolVersionI() throws Exception {
    // Test for method void
    // java.io.ObjectOutputStream.useProtocolVersion(int)
    oos.useProtocolVersion(ObjectOutputStream.PROTOCOL_VERSION_1);
    ExternalTest t1 = new ExternalTest();
    t1.setValue("hello1");
    oos.writeObject(t1);
    oos.close();
    ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
    ExternalTest t2 = (ExternalTest) ois.readObject();
    ois.close();
    assertTrue(
        "Cannot read/write PROTOCAL_VERSION_1 Externalizable objects: " + t2.getValue(),
        t1.getValue().equals(t2.getValue()));

    // Cannot set protocol version when stream in-flight
    ObjectOutputStream out = new ObjectOutputStream(new ByteArrayOutputStream());
    out.writeObject("hello world");
    try {
      out.useProtocolVersion(ObjectStreamConstants.PROTOCOL_VERSION_1);
      fail("Expected IllegalStateException");
    } catch (IllegalStateException e) {
      // Expected
    }
  }
  static boolean saveDat(String path) {
    try {
      //            DataOutputStream out = new DataOutputStream(new FileOutputStream(path));
      //            out.writeInt(start.length);
      //            for (int i : start)
      //            {
      //                out.writeInt(i);
      //            }
      //            out.writeInt(pair.length);
      //            for (int i : pair)
      //            {
      //                out.writeInt(i);
      //            }
      //            out.close();
      ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(path));
      out.writeObject(start);
      out.writeObject(pair);
      out.close();
    } catch (Exception e) {
      logger.log(Level.WARNING, "在缓存" + path + "时发生异常", e);
      return false;
    }

    return true;
  }
 @Override
 public <T> T run(Callable<T> r) {
   T result = null;
   try {
     synchronized (store) {
       result = r.call();
       File temp = new File(store.getParentFile(), "temp_" + store.getName());
       FileOutputStream file = new FileOutputStream(temp);
       ObjectOutputStream out = new ObjectOutputStream(file);
       out.writeObject(properties);
       out.writeObject(maps);
       out.flush();
       out.close();
       file.flush();
       file.close();
       Files.move(
           temp.toPath(),
           store.toPath(),
           StandardCopyOption.ATOMIC_MOVE,
           StandardCopyOption.REPLACE_EXISTING);
     }
   } catch (Exception e) {
     // If something happened here, that is a serious bug so we need to assert.
     throw Assert.failure("Failure flushing FlatFileKeyValueStorage", e);
   }
   return result;
 }
 /** Responsible for attending or discarding the Server operation request */
 public void run() {
   try (Socket s = communication;
       ObjectInputStream ois = new ObjectInputStream(communication.getInputStream());
       ObjectOutputStream oos = new ObjectOutputStream(communication.getOutputStream())) {
     UnaCloudAbstractMessage clouderServerRequest = (UnaCloudAbstractMessage) ois.readObject();
     System.out.println("message: " + clouderServerRequest);
     switch (clouderServerRequest.getMainOp()) {
       case UnaCloudAbstractMessage.VIRTUAL_MACHINE_OPERATION:
         oos.writeObject(attendVirtualMachineOperation(clouderServerRequest, ois, oos));
         break;
       case UnaCloudAbstractMessage.PHYSICAL_MACHINE_OPERATION:
         oos.writeObject(attendPhysicalMachineOperation(clouderServerRequest));
         break;
       case UnaCloudAbstractMessage.AGENT_OPERATION:
         oos.writeObject(attendAgentOperation(clouderServerRequest));
         break;
       default:
         oos.writeObject(
             new InvalidOperationResponse(
                 "Opeartion "
                     + clouderServerRequest.getMainOp()
                     + " is invalid as main operation."));
         break;
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
Esempio n. 23
0
  public boolean out(OutStoringpo opo) throws Exception {
    // TODO Auto-generated method stub
    FileInputStream fis = new FileInputStream("src/main/java/data/save/outstock.txt");
    ObjectInputStream ois = new ObjectInputStream(fis);
    @SuppressWarnings("unchecked")
    List<OutStoringpo> list = (List<OutStoringpo>) ois.readObject();
    ois.close();
    list.add(opo);
    FileOutputStream fos = new FileOutputStream("src/main/java/data/save/outstock.txt");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(list);
    oos.close();
    FileInputStream fis1 = new FileInputStream("src/main/java/data/save/instock.txt");
    ObjectInputStream ois1 = new ObjectInputStream(fis1);
    @SuppressWarnings("unchecked")
    List<InStoringpo> list1 = (List<InStoringpo>) ois1.readObject();
    for (int i = 0; i < list1.size(); i++) {
      if (((list1.get(i)).getID()).equals(opo.getID())) {
        list1.remove(i);
        i--;
        // System.out.println("Delete ");
      }
    }
    ois1.close();
    FileOutputStream fos1 = new FileOutputStream("src/main/java/data/save/instock.txt");
    ObjectOutputStream oos1 = new ObjectOutputStream(fos1);
    oos1.writeObject(list1);
    oos1.close();

    return true;
  }
 /**
  * Serializes this object to the specified output stream for JDK Serialization.
  *
  * @param out output stream used for Object serialization.
  * @throws IOException if any of this object's fields cannot be written to the stream.
  * @since 1.0
  */
 private void writeObject(ObjectOutputStream out) throws IOException {
   out.defaultWriteObject();
   short alteredFieldsBitMask = getAlteredFieldsBitMask();
   out.writeShort(alteredFieldsBitMask);
   if (id != null) {
     out.writeObject(id);
   }
   if (startTimestamp != null) {
     out.writeObject(startTimestamp);
   }
   if (stopTimestamp != null) {
     out.writeObject(stopTimestamp);
   }
   if (lastAccessTime != null) {
     out.writeObject(lastAccessTime);
   }
   if (timeout != 0l) {
     out.writeLong(timeout);
   }
   if (expired) {
     out.writeBoolean(expired);
   }
   if (host != null) {
     out.writeUTF(host);
   }
   if (!CollectionUtils.isEmpty(attributes)) {
     out.writeObject(attributes);
   }
 }
 public void actionPerformed(ActionEvent event) {
   int i;
   JButton aux = (JButton) event.getSource();
   if (aux == closeCompra) {
     try {
       String[] information = {
         JOptionPane.showInputDialog(null, "nombre"),
         JOptionPane.showInputDialog(null, "numero de targeta")
       };
       ObjectOutputStream oos = new ObjectOutputStream(client.getOutputStream());
       oos.writeObject(information);
       oos.flush();
       oos.writeObject(products);
       oos.flush();
       oos.writeObject(comprados);
       oos.flush();
       cleanTable();
       comprados.clear();
     } catch (Exception e) {
       System.out.print("\nerror al cerrar la compra " + e.getMessage());
     }
     return;
   }
   for (i = 0; aux != mostrador.addCar[i]; i++) {;
   }
   if (products.get(i).getPiesas() > 0) {
     products.get(i).popParts();
     addCompra(products.get(i));
     total.setText("total: " + comprados.getLast().getTotal());
   } else {
     JOptionPane.showMessageDialog(null, "no seas menso ya no hay mas piesas! :@");
   }
 }
  /**
   * Save the state of the Hashtable to a stream (i.e., serialize it).
   *
   * @serialData The <i>capacity</i> of the Hashtable (the length of the bucket array) is emitted
   *     (int), followed by the <i>size</i> of the Hashtable (the number of key-value mappings),
   *     followed by the key (Object) and value (Object) for each key-value mapping represented by
   *     the Hashtable The key-value mappings are emitted in no particular order.
   */
  private void writeObject(java.io.ObjectOutputStream s) throws IOException {
    Entry<Object, Object> entryStack = null;

    synchronized (this) {
      // Write out the threshold and loadFactor
      s.defaultWriteObject();

      // Write out the length and count of elements
      s.writeInt(table.length);
      s.writeInt(count);

      // Stack copies of the entries in the table
      for (Entry<?, ?> entry : table) {

        while (entry != null) {
          entryStack = new Entry<>(0, entry.key, entry.value, entryStack);
          entry = entry.next;
        }
      }
    }

    // Write out the key/value objects from the stacked entries
    while (entryStack != null) {
      s.writeObject(entryStack.key);
      s.writeObject(entryStack.value);
      entryStack = entryStack.next;
    }
  }
Esempio n. 27
0
  public byte[] getContentHash() {
    byte[] bytes = null;

    try {
      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      ObjectOutputStream objectStream = new ObjectOutputStream(byteStream);

      objectStream.writeObject(components);
      objectStream.writeObject(pointers);
      objectStream.flush();

      bytes = byteStream.toByteArray();
    } catch (IOException ioe) {
      // too bad we don't have a good way to throw a serialziation exception
      return null;
    }

    MessageDigest md = null;
    try {
      md = MessageDigest.getInstance("SHA");
    } catch (NoSuchAlgorithmException e) {
      return null;
    }

    md.reset();
    md.update(bytes);

    return md.digest();
  }
Esempio n. 28
0
  /**
   * Saves a global effect predictions data to a binary file.
   *
   * @see EffectAbstract
   * @param fileName a path to the file the data should be saved in
   * @param trainingUserIDs an array containing the user ids from the probe data
   * @param trainingMoviesIDs an array containing the movie ids from the probe data
   * @param trainingRatings the real ratings given for the probe data
   * @param trainingPredictions the ratings values that the effect predicts
   * @param teta the teta values calculated by the effect's
   * @return true if the data had been saved successfully or false otherwise
   */
  public static boolean saveEffectData(
      String fileName,
      int[] trainingUserIDs,
      short[] trainingMoviesIDs,
      byte[] trainingRatings,
      double[] trainingPredictions,
      double[] teta) {

    ObjectOutputStream oos = FileUtils.getObjectOutputStream(fileName);
    boolean retVal = false;

    if (oos != null) {
      try {
        oos.writeObject(trainingUserIDs);
        oos.writeObject(trainingMoviesIDs);
        oos.writeObject(trainingRatings);
        oos.writeObject(trainingPredictions);
        oos.writeObject(teta);
        retVal = true;
      } catch (Exception e) {

      } finally {
        FileUtils.outputClose(oos);
      }
    }

    return retVal;
  }
Esempio n. 29
0
 /**
  * @serialData key comparator, value comparator, number of distinct keys, and then for each
  *     distinct key: the key, number of values for that key, and key values
  */
 @GwtIncompatible("java.io.ObjectOutputStream")
 private void writeObject(ObjectOutputStream stream) throws IOException {
   stream.defaultWriteObject();
   stream.writeObject(keyComparator());
   stream.writeObject(valueComparator());
   Serialization.writeMultimap(this, stream);
 }
Esempio n. 30
0
 private void writeObject(java.io.ObjectOutputStream out) throws IOException {
   out.writeObject(name);
   out.writeInt(resourceId);
   out.writeInt(value);
   if (iptv == null) {
     // No POI vector
     out.writeInt(0);
     return;
   }
   long vectorSize = iptv.size();
   out.writeLong(vectorSize);
   Log.d(TAG, "Written vector size: " + vectorSize);
   for (int j = 0; j < vectorSize; j++) {
     Ipoint p = iptv.get(j);
     out.writeFloat(p.getX());
     out.writeFloat(p.getY());
     out.writeFloat(p.getScale());
     out.writeFloat(p.getOrientation());
     out.writeInt(p.getLaplacian());
     out.writeFloat(p.getDx());
     out.writeFloat(p.getDy());
     out.writeInt(p.getClusterIndex());
     out.writeObject(p.getDescriptor());
   }
 }