示例#1
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));
  }
示例#2
0
    @SuppressWarnings("unchecked")
    private ArrayList<T> load(Context ctx, String name, String folder) {
      ArrayList<T> data = null;

      File file;
      if (!folder.isEmpty()) {
        File fileDir = new File(ctx.getFilesDir(), folder);
        if (!fileDir.exists() || !fileDir.isDirectory()) {
          fileDir.mkdir();
        }
        file = new File(fileDir, name);
      } else {
        file = new File(ctx.getFilesDir(), name);
      }

      if (file.exists()) {
        try {
          ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
          data = (ArrayList<T>) ois.readObject();
          ois.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      if (data == null) {
        data = new ArrayList<>();
      }

      return data;
    }
  /**
   * This method initializes this
   *
   * @return void
   * @throws IOException
   * @throws FileNotFoundException
   * @throws ClassNotFoundException
   */
  private void initialize() throws IOException, ClassNotFoundException {
    this.setSize(300, 258);
    this.setContentPane(getJContentPane());
    this.setTitle("LinkedIn Friends Output");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Center(this);
    if (file.exists()) {
      // if the file exists we assume it has the AuthHandler in it - which in turn contains the
      // Access Token
      ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(file));
      AuthHandler authHandler = (AuthHandler) inputStream.readObject();
      accessToken = authHandler.getAccessToken();
      jLabel1.show(false);
      jLabel2.show(false);
      getJButton1().show(false);
      getJTextField1().show(false);
      getJButton().setLocation(150, 5);
      setSize(265, 120);
      getJProgressBar().setSize(240, 22);
      getJProgressBar().setLocation(5, 45);

      flag = true;
    } else {
      flag = false;
      getJButton2().show(false);
    }
  }
 // This assertion will not come into existence the other way around. This is
 // probably caused by different serialization mechanism used by RI and
 // Harmony.
 @TestTargetNew(
     level = TestLevel.PARTIAL,
     notes = "Make sure all fields have non default values.",
     method = "!SerializationGolden",
     args = {})
 @KnownFailure("Deserialized object is not equal to the original object." + "Test passes on RI.")
 public void test_RIHarmony_compatible() throws Exception {
   ObjectInputStream i = null;
   try {
     DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.FRANCE);
     i =
         new ObjectInputStream(
             getClass()
                 .getClassLoader()
                 .getResourceAsStream("serialization/java/text/DecimalFormatSymbols.ser"));
     DecimalFormatSymbols symbolsD = (DecimalFormatSymbols) i.readObject();
     assertEquals(symbols, symbolsD);
   } catch (NullPointerException e) {
     assertNotNull("Failed to load /serialization/java/text/" + "DecimalFormatSymbols.ser", i);
   } finally {
     try {
       if (i != null) {
         i.close();
       }
     } catch (Exception e) {
     }
   }
   assertDecimalFormatSymbolsRIFrance(dfs);
 }
示例#5
0
 /** 克隆Serializable */
 @SuppressWarnings("unchecked")
 public static <T> T cloneSerializable(T src) throws RuntimeException {
   ByteArrayOutputStream memoryBuffer = new ByteArrayOutputStream();
   ObjectOutputStream out = null;
   ObjectInputStream in = null;
   T dest = null;
   try {
     out = new ObjectOutputStream(memoryBuffer);
     out.writeObject(src);
     out.flush();
     in = new ObjectInputStream(new ByteArrayInputStream(memoryBuffer.toByteArray()));
     dest = (T) in.readObject();
   } catch (Exception e) {
     throw new RuntimeException(e);
   } finally {
     if (out != null) {
       try {
         out.close();
         out = null;
       } catch (Exception e) {
       }
     }
     if (in != null) {
       try {
         in.close();
         in = null;
       } catch (Exception e) {
       }
     }
   }
   return dest;
 }
 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;
 }
 public static TodoList todoListFromString(String todoListData)
     throws IOException, ClassNotFoundException {
   ByteArrayInputStream bis =
       new ByteArrayInputStream(Base64.decode(todoListData, Base64.DEFAULT));
   ObjectInputStream ois = new ObjectInputStream(bis);
   return (TodoList) ois.readObject();
 }
 public static Object readObject(Context context, String key)
     throws IOException, ClassNotFoundException {
   FileInputStream fis = context.openFileInput(key);
   ObjectInputStream ois = new ObjectInputStream(fis);
   Object object = ois.readObject();
   return object;
 }
示例#9
0
  /** Reads a class using safe encoding to workaround java 1.3 serialization bug. */
  private Class readAnyClass(ObjectInputStream in) throws IOException, ClassNotFoundException {
    // read back type class safely
    if (in.readBoolean()) {
      // it's a type constant
      switch (in.readInt()) {
        case BOOLEAN_TYPE:
          return Boolean.TYPE;
        case BYTE_TYPE:
          return Byte.TYPE;
        case CHAR_TYPE:
          return Character.TYPE;
        case DOUBLE_TYPE:
          return Double.TYPE;
        case FLOAT_TYPE:
          return Float.TYPE;
        case INT_TYPE:
          return Integer.TYPE;
        case LONG_TYPE:
          return Long.TYPE;
        case SHORT_TYPE:
          return Short.TYPE;
        default:
          // something's gone wrong
          throw new StreamCorruptedException(
              "Invalid primitive type. "
                  + "Check version of beanutils used to serialize is compatible.");
      }

    } else {
      // it's another class
      return ((Class) in.readObject());
    }
  }
示例#10
0
 /**
  * A getter for the high scores list. Reads it directly from file and throws an error if the file
  * is not found (!working on this!).
  *
  * @return Object[][] where [i][0] is the rank (String), [i][1] is the name (String) and [i][2] is
  *     the score (Integer).
  */
 public static Object[][] getHighScore() {
   if (!new File("HighScores.dat").exists()) {
     // This object matrix actually stores the information of the high scores list
     Object[][] highScores = new Object[10][3];
     // We fill the high scores list with blank entries:  #.    " "    0
     for (int i = 0; i < highScores.length; i++) {
       highScores[i][0] = (i + 1) + ".";
       highScores[i][1] = " ";
       highScores[i][2] = 0;
     }
     // This actually writes and makes the high scores file
     try {
       ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("HighScores.dat"));
       o.writeObject(highScores);
       o.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   try {
     // Read and return the read object matrix
     ObjectInputStream o = new ObjectInputStream(new FileInputStream("HighScores.dat"));
     Object[][] highScores = (Object[][]) o.readObject();
     o.close();
     return highScores;
   } catch (IOException | ClassNotFoundException e) {
     e.printStackTrace();
   }
   return null;
 }
 /**
  * Load history.
  *
  * @param filename the filename
  * @throws Exception the exception
  */
 @SuppressWarnings("unchecked")
 public void loadHistory(String filename) throws Exception {
   FileInputStream fis = new FileInputStream(filename);
   ObjectInputStream ois = new ObjectInputStream(fis);
   setHistory((Map<Double, Double>) ois.readObject());
   ois.close();
 }
示例#12
0
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   in.defaultReadObject();
   _data = new int[in.readInt()];
   for (int i = 0; i < _size; i++) {
     _data[i] = in.readInt();
   }
 }
示例#13
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);
 }
 /**
  * Charge le projet depuis le chemin <code>cheminSauvegarde</code>, et rétabli les attributs et
  * les observeur tel qu'avant la sauvergarde.
  *
  * @param cheminSauvegarde
  * @return le projet chargé et initialisé.
  * @throws FileNotFoundException
  * @throws IOException
  * @throws ClassNotFoundException
  */
 public static Projet chargerProjetDepuisFichier(File cheminSauvegarde)
     throws FileNotFoundException, IOException, ClassNotFoundException {
   ObjectInputStream in = new ObjectInputStream(new FileInputStream(cheminSauvegarde));
   Projet projetCharge = (Projet) in.readObject();
   projetCharge.initialisationApresChargement();
   return projetCharge;
 }
示例#15
0
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   forms = (String[]) in.readObject();
   plemmas = (String[]) in.readObject();
   ppos = (String[]) in.readObject();
   heads = (int[]) in.readObject();
   labels = (String[]) in.readObject();
 }
示例#16
0
  public static CharMappingSaveData[] readCharMappingFromResource(Context context) {
    InputStream is = context.getResources().openRawResource(R.raw.albhabet);
    CharMappingSaveData[] saveData = null;

    ObjectInputStream ois = null;
    try {
      ois = new ObjectInputStream(is);
      saveData = (CharMappingSaveData[]) ois.readObject();
    } catch (IOException ex) {
      Log.e(TAG, "Failed to read char mapping from resource.", ex);
    } catch (ClassNotFoundException ex) {
      Log.e(TAG, "Failed to read char mapping from resource.", ex);
    } finally {
      try {
        is.close();
      } catch (IOException ex) {
      }
      if (ois != null) {
        try {
          ois.close();
        } catch (IOException e) {
        }
      }
    }

    return saveData;
  }
 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;
     }
   }
 }
示例#18
0
 private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
   stream.defaultReadObject();
   int maxPrototypeId = stream.readInt();
   if (maxPrototypeId != 0) {
     activatePrototypeMap(maxPrototypeId);
   }
 }
示例#19
0
  private void readObject(java.io.ObjectInputStream in) throws IOException {
    float x = in.readFloat();
    float y = in.readFloat();
    float z = in.readFloat();
    String world = in.readUTF();
    World w = Spout.getEngine().getWorld(world);
    try {
      Field field;

      field = Vector3.class.getDeclaredField("x");
      field.setAccessible(true);
      field.set(this, x);

      field = Vector3.class.getDeclaredField("y");
      field.setAccessible(true);
      field.set(this, y);

      field = Vector3.class.getDeclaredField("z");
      field.setAccessible(true);
      field.set(this, z);

      field = Point.class.getDeclaredField("world");
      field.setAccessible(true);
      field.set(this, w);
    } catch (Exception e) {
      if (Spout.debugMode()) {
        e.printStackTrace();
      }
    }
  }
 /**
  * Because the readArchive() method requires unchecked casting, the compiler throws a warning at
  * compile time. Since we already know the data type we are extracting from the file we can safely
  * suppress this warning.
  */
 @SuppressWarnings("unchecked")
 public AbstractRoom[] readArchive() throws IOException, ClassNotFoundException {
   ObjectInputStream in = new ObjectInputStream(new FileInputStream("RoomArchive.txt"));
   roomArr = (AbstractRoom[]) in.readObject();
   in.close();
   return roomArr;
 }
示例#21
0
  public Card readCard(File filePath) {

    Card card = null;

    try {
      FileInputStream fis = new FileInputStream(filePath);
      ObjectInputStream ois = new ObjectInputStream(fis);

      card = (Card) ois.readObject();

      System.out.println(
          "Card " + card.getName() + " converted mana cost " + card.getConvertedManacost());
      fis.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }

    return card;
  }
示例#22
0
 public Object stringToObj(String s) throws IOException, ClassNotFoundException {
   byte[] data = Base64.getDecoder().decode(s);
   ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
   Object o = ois.readObject();
   ois.close();
   return o;
 }
 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();
   }
 }
示例#24
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;
  }
示例#25
0
 /*
  * recovery a class from path's file
  */
 @SuppressWarnings("finally")
 public Object readSerializableData(String path) {
   Object yyc = null;
   try {
     FileInputStream fis = new FileInputStream(path);
     ObjectInputStream ois = new ObjectInputStream(fis);
     yyc = (Object) ois.readObject();
     ois.close();
     return yyc;
   } catch (FileNotFoundException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (StreamCorruptedException 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 {
     return yyc;
   }
 }
示例#26
0
  public static SummaryCollection getSummaryCollections() throws Exception {
    PreparedStatement pstmt = conn.prepareStatement(READ_OBJECT_SQL_ALL);

    ResultSet rs = pstmt.executeQuery();
    SummaryCollection sc = new SummaryCollection();

    while (rs.next()) {
      byte[] buf = rs.getBytes(1);
      ObjectInputStream objectIn = null;
      if (buf != null) {
        objectIn = new ObjectInputStream(new ByteArrayInputStream(buf));
      }
      Object sumObject = objectIn.readObject();
      Summary sum = (Summary) sumObject;
      sc.appendSummary(sum);
    }

    try {
      if (rs != null) {
        rs.close();
      }
      if (pstmt != null) {
        pstmt.close();
      }
    } catch (Exception E) {
      metrixLogger.log.log(
          Level.SEVERE, "Error in closing resource sets of SQL Connection. {0}", E.toString());
    }

    return sc;
  }
示例#27
0
文件: Storing.java 项目: jacksenma/-2
  public String[] SearchUncheckedinstock() {
    // TODO Auto-generated method stub
    int count = 0;
    try {
      FileInputStream fis = new FileInputStream("src/main/java/data/save/instock.txt");
      ObjectInputStream ois = new ObjectInputStream(fis);
      List<InStoringpo> list = (List<InStoringpo>) ois.readObject();
      ois.close();

      for (int i = 0; i < list.size(); i++) {
        System.out.println(list.get(i).getID());
        if (list.get(i).getExamineType().equals(IsExamineType.NOApproval)) count++;
      }
      int k = 0;
      String result[] = new String[count];
      for (int i = 0; i < list.size(); i++) {
        if (list.get(i).getExamineType().equals(IsExamineType.NOApproval)) {
          result[k] = list.get(i).getID();
          k++;
        }
      }
      System.out.println("find unchecked");
      return result;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
示例#28
0
 private void dispatchEvents(LoggerContext lc) {
   try {
     socket.setSoTimeout(acceptConnectionTimeout);
     ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
     socket.setSoTimeout(0);
     addInfo(receiverId + "connection established");
     while (true) {
       ILoggingEvent event = (ILoggingEvent) ois.readObject();
       Logger remoteLogger = lc.getLogger(event.getLoggerName());
       if (remoteLogger.isEnabledFor(event.getLevel())) {
         remoteLogger.callAppenders(event);
       }
     }
   } catch (EOFException ex) {
     addInfo(receiverId + "end-of-stream detected");
   } catch (IOException ex) {
     addInfo(receiverId + "connection failed: " + ex);
   } catch (ClassNotFoundException ex) {
     addInfo(receiverId + "unknown event class: " + ex);
   } finally {
     CloseUtil.closeQuietly(socket);
     socket = null;
     addInfo(receiverId + "connection closed");
   }
 }
示例#29
0
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   int version = in.readInt();
   this.encoding = (String) in.readObject();
   if (encoding.equals("null")) {
     encoding = null;
   }
 }
示例#30
0
    @SuppressWarnings("unchecked")
    public T loadGlobalObject(Context ctx, String name) {
      String folder = FILDER_GLOBAL;
      T data = null;

      File file;
      if (!folder.isEmpty()) {
        File fileDir = new File(ctx.getFilesDir(), folder);
        if (!fileDir.exists() || !fileDir.isDirectory()) {
          fileDir.mkdir();
        }
        file = new File(fileDir, name);
      } else {
        file = new File(ctx.getFilesDir(), name);
      }

      if (file.exists()) {
        try {
          ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
          data = (T) ois.readObject();
          ois.close();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      return data;
    }