コード例 #1
0
ファイル: MsReaderTest.java プロジェクト: wyu/ms2ms
  @Test
  public void serializing() throws Exception {
    // grab a new scan
    MsnSpectrum[] scans = firstScan(root + "20081129_Orbi6_NaNa_SA_FASP_blacktips_01.mzXML", 2, 2);
    MsnSpectrum scan = scans[0], scan2 = scans[1];

    FileOutputStream f_out = new FileOutputStream("/tmp/myobject.data");

    // Write object with ObjectOutputStream
    ObjectOutputStream obj_out = new ObjectOutputStream(f_out);

    // Write object out to disk
    long p1 = f_out.getChannel().position();
    obj_out.writeObject(MsSpectrum.adopt(scan));
    long p2 = f_out.getChannel().position();
    obj_out.writeObject(MsSpectrum.adopt(scan2));

    obj_out.close();
    f_out.close();

    FileInputStream f_in = new FileInputStream("/tmp/myobject.data");

    ObjectInputStream obj_in = new ObjectInputStream(f_in);
    MsSpectrum m1 = (MsSpectrum) obj_in.readObject();
    obj_in.close();
    f_in.close();

    f_in = new FileInputStream("/tmp/myobject.data");
    obj_in = new ObjectInputStream(f_in);

    f_in.getChannel().position(p1);
    //    MsSpectrum m3 = (MsSpectrum )obj_in.readObject();
    f_in.getChannel().position(p2);
    long p3 = f_in.getChannel().position();

    MsSpectrum m4 = (MsSpectrum) obj_in.readObject();
    obj_in.close();
    f_in.close();
  }
コード例 #2
0
ファイル: MsReaderTest.java プロジェクト: wyu/ms2ms
  @Test
  public void serializingViaBytes() throws Exception {
    // grab a new scan
    MsnSpectrum[] scans = firstScan(root + "20081129_Orbi6_NaNa_SA_FASP_blacktips_01.mzXML", 2, 2);
    MsnSpectrum scan = scans[0], scan2 = scans[1];

    RandomAccessFile f = new RandomAccessFile("/tmp/myobject2.data", "rw");

    // Write object out to disk
    long p1 = MsIO.write(f, MsSpectrum.adopt(scan));
    long p2 = MsIO.write(f, MsSpectrum.adopt(scan2));

    f.close();

    f = new RandomAccessFile("/tmp/myobject2.data", "r");
    MsSpectrum m1 = MsIO.readSpectrumIdentifier(f);
    f.close();

    f = new RandomAccessFile("/tmp/myobject2.data", "r");
    MsSpectrum m3 = MsIO.readSpectrumIdentifier(f, p1);
    MsSpectrum m4 = MsIO.readSpectrumIdentifier(f, p2);

    f.close();
  }