示例#1
0
  // Function use to Save Records to File After Deleting the Record of User Choice.
  void deleteFile() {

    try {
      FileOutputStream fos = new FileOutputStream("Bank.dat");
      DataOutputStream dos = new DataOutputStream(fos);
      if (records != null) {
        for (int i = 0; i < total; i++) {
          for (int r = 0; r < 6; r++) {
            dos.writeUTF(records[i][r]);
            if (records[i][r] == null) break;
          }
        }
        JOptionPane.showMessageDialog(
            this,
            "Record has been Deleted Successfuly.",
            "BankSystem - Record Deleted",
            JOptionPane.PLAIN_MESSAGE);
        txtClear();
      } else {
      }
      dos.close();
      fos.close();
    } catch (IOException ioe) {
      JOptionPane.showMessageDialog(
          this,
          "There are Some Problem with File",
          "BankSystem - Problem",
          JOptionPane.PLAIN_MESSAGE);
    }
  }
 public static void writeLogFile(String descript, String filename) {
   File file;
   FileOutputStream outstream;
   // BufferedWriter outstream;
   Date time = new Date();
   long bytes = 30000000;
   try {
     // Get log file
     String logfile = "C:\\" + filename + ".txt";
     file = new File(logfile);
     boolean exists = file.exists();
     if (!exists) {
       // create a new, empty node file
       try {
         file = new File(logfile);
         boolean success = file.createNewFile();
       } catch (IOException e) {
         System.out.println("Create Event Log file failed!");
       }
     }
     try {
       descript = descript + "\n";
       outstream = new FileOutputStream(file, true);
       for (int i = 0; i < descript.length(); ++i) {
         outstream.write((byte) descript.charAt(i));
       }
       outstream.close();
     } catch (IOException e) {
     }
   } catch (java.lang.Exception e) {
   }
 }
示例#3
0
  public void saveState(String extension) {
    String directory = (cartridge.romFileName + extension);

    try {
      FileOutputStream fl = new FileOutputStream(directory);
      DataOutputStream sv = new DataOutputStream(fl);

      saveData(sv, directory);

      // write battery ram
      cartridge.saveData(sv, directory);

      // write graphic memory
      graphicsChip.saveData(sv, directory);

      // write io state
      ioHandler.saveData(sv, directory);

      // stats.printStats();

      sv.close();
      fl.close();

    } catch (FileNotFoundException e) {
      System.out.println("Dmgcpu.saveState: Could not open file " + directory);
      System.out.println("Error Message: " + e.getMessage());
      System.exit(-1);
    } catch (IOException e) {
      System.out.println("Dmgcpu.saveState: Could not write to file " + directory);
      System.out.println("Error Message: " + e.getMessage());
      System.exit(-1);
    }

    System.out.println("Saved stage!");
  }
  public static void saveJPG(Image img, String s) {
    BufferedImage bi =
        new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = bi.createGraphics();
    g2.drawImage(img, null, null);

    FileOutputStream out = null;
    try {
      out = new FileOutputStream(s);
    } catch (java.io.FileNotFoundException io) {
      System.out.println("File Not Found");
    }

    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
    param.setQuality(0.5f, false);
    encoder.setJPEGEncodeParam(param);

    try {
      encoder.encode(bi);
      out.close();
    } catch (java.io.IOException io) {
      System.out.println("IOException");
    }
  }
示例#5
0
 private void saveBin() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(binFilter);
   fileChooser.setFileFilter(binFilter);
   if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = fileChooser.getSelectedFile();
       if (fileChooser.getFileFilter() == binFilter && !binFilter.accept(file)) {
         file = new File(file.getAbsolutePath() + binFilter.getExtensions()[0]);
       }
       if (file.exists()) {
         if (JOptionPane.showConfirmDialog(
                 frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION)
             != JOptionPane.YES_OPTION) {
           return;
         }
       }
       FileOutputStream output = new FileOutputStream(file);
       for (char i : binary) {
         output.write(i & 0xff);
         output.write((i >> 8) & 0xff);
       }
       output.close();
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
示例#6
0
 protected void saveGlyphFile(File a_file) throws FileNotFoundException {
   FileOutputStream output = new FileOutputStream(a_file);
   saveGlyphFile(output);
   try {
     output.close(); // JPEXS
   } catch (IOException ex) {
     Logger.getLogger(GlyphFile.class.getName()).log(Level.SEVERE, null, ex);
   }
 }
 private void saveObject(Object obj, String fName) {
   try {
     FileOutputStream fos = new FileOutputStream(fName);
     ObjectOutputStream oos = new ObjectOutputStream(fos);
     oos.writeObject(obj);
     oos.flush();
     oos.close();
     fos.close();
   } catch (IOException ex) {
     JOptionPane.showMessageDialog(this, "Problemos saugojant Objektus");
   }
 }
示例#8
0
 private void physWriteTextFile(File file, String text) {
   // physically write file
   try {
     FileOutputStream fo = new FileOutputStream(file);
     fo.write(text.getBytes());
     fo.close();
   } catch (FileNotFoundException e) {
     // not sure how this can happen
     showErrorDialog("Saving failed due to file not found error?");
   } catch (IOException e) {
     // This happens if e.g. file already exists and
     // we do not have write permissions
     showErrorDialog("Saving failed due I/O error.");
   }
 }
示例#9
0
  private static void exportScreenshotEpsGraphics(
      Component target, File selectedFile, boolean paintOffscreen) throws IOException {

    if (!SnapshotUtilities.canExportScreenshotEps()) {
      String msg =
          "ERROR: EPS output requires EPSGraphics library. See https://www.broadinstitute.org/software/igv/third_party_tools#epsgraphics";
      log.error(msg);
      return;
    }

    Graphics2D g = null;
    FileOutputStream fos = null;
    try {
      Class colorModeClass = RuntimeUtils.loadClassForName(EPSColorModeClassName, null);
      Class graphicsClass = RuntimeUtils.loadClassForName(EPSClassName, null);

      Constructor constructor =
          graphicsClass.getConstructor(
              String.class,
              OutputStream.class,
              int.class,
              int.class,
              int.class,
              int.class,
              colorModeClass);

      Object colorModeValue = Enum.valueOf(colorModeClass, "COLOR_RGB");

      // EpsGraphics stores directly in a file
      fos = new FileOutputStream(selectedFile);
      g =
          (Graphics2D)
              constructor.newInstance(
                  "eps", fos, 0, 0, target.getWidth(), target.getHeight(), colorModeValue);

      choosePaint(target, g, paintOffscreen);

      graphicsClass.getMethod("close").invoke(g);

    } catch (Exception e) {
      log.error(e.getMessage(), e);
    } finally {
      if (fos != null) {
        fos.flush();
        fos.close();
      }
    }
  }
示例#10
0
  public static void main(String[] args) {
    try {

      DecimalFormatSymbols dfs = new DecimalFormatSymbols();
      System.out.println(
          "Default currency symbol in the default locale : " + dfs.getCurrencySymbol());
      dfs.setCurrencySymbol("*SpecialCurrencySymbol*");
      System.out.println("The special currency symbol is set : " + dfs.getCurrencySymbol());
      FileOutputStream ostream = new FileOutputStream("DecimalFormatSymbols.142");
      ObjectOutputStream p = new ObjectOutputStream(ostream);
      p.writeObject(dfs);
      ostream.close();
      System.out.println("DecimalFormatSymbols saved ok.");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#11
0
 /**
  * xlsxファイルのファイル出力
  *
  * @param workbook ワークブック
  * @param filePath ファイルパス
  * @return ファイル出力の成否
  */
 public static boolean saveAs(XSSFWorkbook workbook, String filePath) {
   boolean result = true;
   FileOutputStream out = null;
   try {
     out = new FileOutputStream(filePath);
     workbook.write(out);
   } catch (IOException e) {
     result = false;
   } finally {
     try {
       out.close();
     } catch (IOException e) {
       result = false;
     }
   }
   return result;
 }
示例#12
0
  public String paintDendrogram(File f, Cluster clustering) {
    // ArrayList clusters = null;
    lowThreshold = 0;
    threshold = (int) maxMergeValue + 1;

    do {
      threshold = threshold - 1;
      clusters = getClusters(clustering, threshold);
    } while (clusters.size() > maxVertLines);

    int size = clusters.size();
    factor = 1000 / size;
    if (factor < 4) factor = 4;

    int xSize = factor * size + 50;
    int ySize = 500 + 50;
    BufferedImage image = new BufferedImage(xSize + 1, ySize + 1, BufferedImage.TYPE_BYTE_INDEXED);
    g = (Graphics2D) image.getGraphics();

    g.setColor(Color.WHITE);
    g.fillRect(0, 0, 30 + xSize, 30 + ySize);
    g.setPaintMode();

    paintCoords(xSize, ySize);

    mapString = "<map name=\"Dendrogram\">\n";
    minX = 50;
    minY = 10;
    maxY = ySize - 40;
    drawCluster(clustering);
    g.setColor(Color.GRAY);
    g.drawLine(clustering.x, clustering.y, clustering.x, minY);

    try {
      FileOutputStream fo = new FileOutputStream(f);
      GIFEncoder encode = new GIFEncoder(image);
      encode.write(fo);
      fo.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return mapString + "</map>";
  }
示例#13
0
 // write a buffered image to a jpeg file.
 protected static void saveJPG(Image img, String filename) {
   BufferedImage bi = imageToBufferedImage(img);
   FileOutputStream out = null;
   try {
     out = new FileOutputStream(filename);
   } catch (java.io.FileNotFoundException io) {
     System.out.println("File Not Found");
   }
   JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
   JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
   param.setQuality(0.8f, false);
   encoder.setJPEGEncodeParam(param);
   try {
     encoder.encode(bi);
     out.close();
   } catch (java.io.IOException io) {
     System.out.println("IOException");
   }
 }
示例#14
0
 private static String writeFileBytes(String path, byte[] data) {
   try {
     if (data.length>=524288 && !path.endsWith("JmolApplet.jar") ){ //gzip it
       path += ".gz";
       GZIPOutputStream gzFile = new GZIPOutputStream(new FileOutputStream(path));
       gzFile.write(data);
       LogPanel.log("      ..." + GT._("compressing large data file to") + "\n");
       gzFile.flush();
       gzFile.close();
     } else {
       FileOutputStream os = new FileOutputStream(path);
       os.write(data);
       os.flush();
       os.close();
     }
   } catch (IOException e) {
     LogPanel.log(e.getMessage());
   }
   return path;
 }
示例#15
0
  private void speichern(Path saveName) {
    Properties prop = new Properties();

    if (!quellListModel.isEmpty())
      for (int i = 0; i < quellListModel.getSize(); i++)
        prop.setProperty(
            String.format("quellMenu%d", i),
            quellListModel.getElementAt(i).getValueMember().toString());

    if (!zielListModel.isEmpty())
      for (int i = 0; i < zielListModel.getSize(); i++)
        prop.setProperty(
            String.format("zielMenu%d", i),
            zielListModel.getElementAt(i).getValueMember().toString());

    try {
      FileOutputStream out = new FileOutputStream(saveName.toString());
      prop.store(out, null);
      out.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private void dumpDDS() {
    List<MessageBean> beans = messageTable.getBeans();
    HashMap<Integer, Message> map = new HashMap<Integer, Message>(2 * beans.size());

    for (MessageBean mb : beans) {
      map.put(mb.m.hashCode(), mb.m);
    }

    if (fileChooser == null)
      fileChooser = new FileManager(null, null, null, (PreferencesExt) prefs.node("FileManager"));

    String defloc = (raf.getLocation() == null) ? "." : raf.getLocation();
    int pos = defloc.lastIndexOf(".");
    if (pos > 0) defloc = defloc.substring(0, pos);
    String filename = fileChooser.chooseFilenameToSave(defloc + ".txt");
    if (filename == null) return;

    try {
      File file = new File(filename);
      FileOutputStream fos = new FileOutputStream(file);

      int count = 0;
      for (Message m : map.values()) {
        Formatter f = new Formatter(fos);
        m.dump(f);
        f.flush();
        count++;
      }
      fos.close();
      JOptionPane.showMessageDialog(
          BufrMessageViewer.this, count + " successfully written to " + filename);

    } catch (IOException e1) {
      JOptionPane.showMessageDialog(BufrMessageViewer.this, e1.getMessage());
      e1.printStackTrace();
    }
  }
  public final void run() {
    if (socketthread) {
      socketrun();
      return;
    }
    socketthread = true;
    try {
      boolean flag = false;
      try {
        String s = getParameter("member");
        int i = Integer.parseInt(s);
        if (i == 1) flag = true;
      } catch (Exception _ex) {
      }
      loading = getImage(new URL(getCodeBase(), "loading.jpg"));
      mt = new MediaTracker(this);
      mt.addImage(loading, 0);
      m = MessageDigest.getInstance("SHA");
      System.out.println(link.class);
      String s1 = ".file_store_32/";
      if (s1 == null) return;
      link.uid = getuid(s1);
      link.mainapp = this;
      link.numfile = 0;
      for (int j = 0; j < 14; j++)
        if (flag || !internetname[j].endsWith(".mem")) {
          for (int k = 0; k < 4; k++) {
            if (k == 3) return;
            byte abyte0[] = loadfile(s1 + localname[j], sha[j]);
            if (abyte0 != null) {
              if (j > 0) link.putjag(internetname[j], abyte0);
              break;
            }
            try {
              URL url = new URL(getCodeBase(), internetname[j]);
              DataInputStream datainputstream = new DataInputStream(url.openStream());
              int l = size[j];
              byte abyte1[] = new byte[l];
              for (int i1 = 0; i1 < l; i1 += 1000) {
                int j1 = l - i1;
                if (j1 > 1000) j1 = 1000;
                datainputstream.readFully(abyte1, i1, j1);
                showpercent(nicename[j], (i1 * 100) / l, barpos[j]);
              }

              datainputstream.close();
              FileOutputStream fileoutputstream = new FileOutputStream(s1 + localname[j]);
              fileoutputstream.write(abyte1);
              fileoutputstream.close();
            } catch (Exception _ex) {
            }
          }
        }
      System.out.println(cloader.class);
      cloader cloader1 = new cloader();
      cloader1.zip = new ZipFile(s1 + localname[0]);
      cloader1.link = Class.forName("link");
      inner = new mudclient_Debug();
      loadMacros();
      // inner = (Applet)cloader1.loadClass("mudclient").newInstance();
      inner.init();
      inner.start();
      return;
    } catch (Exception exception) {
      System.out.println(exception + " " + exception.getMessage());
      exception.printStackTrace();
      return;
    }
  }
示例#18
0
  public static void main(String[] arg) {
    if (arg.length != 2) {
      System.err.println("usage: java ScpFrom user@remotehost:file1 file2");
      System.exit(-1);
    }

    FileOutputStream fos = null;
    try {

      String user = arg[0].substring(0, arg[0].indexOf('@'));
      arg[0] = arg[0].substring(arg[0].indexOf('@') + 1);
      String host = arg[0].substring(0, arg[0].indexOf(':'));
      String rfile = arg[0].substring(arg[0].indexOf(':') + 1);
      String lfile = arg[1];

      String prefix = null;
      if (new File(lfile).isDirectory()) {
        prefix = lfile + File.separator;
      }

      JSch jsch = new JSch();
      Session session = jsch.getSession(user, host, 22);

      // username and password will be given via UserInfo interface.
      UserInfo ui = new MyUserInfo();
      session.setUserInfo(ui);
      session.connect();

      // exec 'scp -f rfile' remotely
      String command = "scp -f " + rfile;
      Channel channel = session.openChannel("exec");
      ((ChannelExec) channel).setCommand(command);

      // get I/O streams for remote scp
      OutputStream out = channel.getOutputStream();
      InputStream in = channel.getInputStream();

      channel.connect();

      byte[] buf = new byte[1024];

      // send '\0'
      buf[0] = 0;
      out.write(buf, 0, 1);
      out.flush();

      while (true) {
        int c = checkAck(in);
        if (c != 'C') {
          break;
        }

        // read '0644 '
        in.read(buf, 0, 5);

        long filesize = 0L;
        while (true) {
          if (in.read(buf, 0, 1) < 0) {
            // error
            break;
          }
          if (buf[0] == ' ') break;
          filesize = filesize * 10L + (long) (buf[0] - '0');
        }

        String file = null;
        for (int i = 0; ; i++) {
          in.read(buf, i, 1);
          if (buf[i] == (byte) 0x0a) {
            file = new String(buf, 0, i);
            break;
          }
        }

        // System.out.println("filesize="+filesize+", file="+file);

        // send '\0'
        buf[0] = 0;
        out.write(buf, 0, 1);
        out.flush();

        // read a content of lfile
        fos = new FileOutputStream(prefix == null ? lfile : prefix + file);
        int foo;
        while (true) {
          if (buf.length < filesize) foo = buf.length;
          else foo = (int) filesize;
          foo = in.read(buf, 0, foo);
          if (foo < 0) {
            // error
            break;
          }
          fos.write(buf, 0, foo);
          filesize -= foo;
          if (filesize == 0L) break;
        }
        fos.close();
        fos = null;

        if (checkAck(in) != 0) {
          System.exit(0);
        }

        // send '\0'
        buf[0] = 0;
        out.write(buf, 0, 1);
        out.flush();
      }

      session.disconnect();

      System.exit(0);
    } catch (Exception e) {
      System.out.println(e);
      try {
        if (fos != null) fos.close();
      } catch (Exception ee) {
      }
    }
  }
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jbSaveLayer) {
      try {
        FileOutputStream fout = new FileOutputStream(jtfCengMing.getText() + ".wyf");
        ObjectOutputStream oout = new ObjectOutputStream(fout);
        oout.writeObject(itemArray);
        oout.close();
        fout.close();
      } catch (Exception ea) {
        ea.printStackTrace();
      }
    } else if (e.getSource() == jbLoadLayer) {
      try {
        FileInputStream fin = new FileInputStream(jtfCengMing.getText() + ".wyf");
        ObjectInputStream oin = new ObjectInputStream(fin);
        itemArray = (Item[][]) oin.readObject();

        oin.close();
        fin.close();
        this.flush();
      } catch (Exception ea) {
        ea.printStackTrace();
      }
      lvp.repaint();
    } else if (e.getSource() == jbLoadAll) { // 全部铺上当前选中

      for (int row = 0; row < 40; row++) {
        for (int col = 0; col < 60; col++) {
          Item item = ((Item) (jl.getSelectedValue())).clone();
          itemArray[row][col] = item;
          if (item != null) {
            item.setPosition(col, row);
          }
        }
      }

      lvp.repaint();
    } else if (e.getSource() == jbCreate) { // 生成源代码

      try {
        FileOutputStream fout = null;
        DataOutputStream dout = null;
        fout = new FileOutputStream("maps.so");
        dout = new DataOutputStream(fout);
        int totalBlocks = 0;

        for (int i = 0; i < 40; i++) {
          for (int j = 0; j < 60; j++) {
            Item item = itemArray[i][j];
            if (item != null) {
              totalBlocks++;
            }
          }
        }
        System.out.println("totalBlocks=" + totalBlocks);

        // 写入不空块的数量
        dout.writeInt(totalBlocks);

        for (int i = 0; i < 40; i++) {
          for (int j = 0; j < 60; j++) {
            Item item = itemArray[i][j];
            if (item != null) {
              int w = item.w; // 元素的图片宽度
              int h = item.h; // 元素的图片高度
              int col = item.col; // 元素的地图列
              int row = item.row; // 元素的地图行
              int pCol = item.pCol; // 元素的占位列
              int pRow = item.pRow; // 元素的占位行
              String leiMing = item.leiMing; // 类名

              int[][] notIn = item.notIn; // 不可通过
              int[][] keYu = item.keYu; // 可遇矩阵

              // 计算图片下标
              int outBitmapInxex = 0;
              if (leiMing.equals("Grass")) {
                outBitmapInxex = 0;
              } else if (leiMing.equals("XiaoHua1")) {
                outBitmapInxex = 1;
              } else if (leiMing.equals("MuZhuang")) {
                outBitmapInxex = 2;
              } else if (leiMing.equals("XiaoHua2")) {
                outBitmapInxex = 3;
              } else if (leiMing.equals("Road")) {
                outBitmapInxex = 4;
              } else if (leiMing.equals("Jing")) {
                outBitmapInxex = 5;
              }

              dout.writeByte(outBitmapInxex); // 记录图片下标
              dout.writeByte(0); // 记录可遇标志 0-不可遇 底层都不可遇
              dout.writeByte(w); // 图片宽度
              dout.writeByte(h); // 图片高度
              dout.writeByte(col); // 总列数
              dout.writeByte(row); // 总行数
              dout.writeByte(pCol); // 占位列
              dout.writeByte(pRow); // 占位行

              int bktgCount = notIn.length; // 不可通过点的数量
              dout.writeByte(bktgCount); // 写入不可通过点的数量

              for (int k = 0; k < bktgCount; k++) {
                dout.writeByte(notIn[k][0]);
                dout.writeByte(notIn[k][1]);
              }
            }
          }
        }

        dout.close();
        fout.close();

      } catch (Exception ea) {
        ea.printStackTrace();
      }
    }
  }
示例#20
0
  public static void write_Byte_array(
      int Msg_head, int packetbytes_length, int numdecodedsamples, byte[] source) {
    int i = 0;
    int k = 0;
    int quote = 0;
    int residule = 0;
    long min, sec, millisec, time_pre;
    String descript_string = "";

    // System.out.println("Destination[0][0]:" + destination[0][0] + "\n " );
    // System.out.println("decodepacketbytepointer " + decodepacketbytepointer + " " +
    // decodepacketbitpointer + "\n " );

    // decompressed data less than packetbytes_length
    if (numdecodedsamples <= (packetbytes_length / 2 - 2)) // one sample is stored by two bytes
    {
      // change length here
      TOS_length = (Msg_head - 10 + 4 + numdecodedsamples * 2);
      APP_length = (TOS_length - 14);
      source[0] &= ~(0xff); // TOS_Msg length
      source[21] &= ~(0xff); // APP_Msg length
      source[0] |= (TOS_length & 0xff); // only one byte can be written
      source[21] |= (APP_length & 0xff); // only one byte can be written
      // System.out.println(" Length ****** " + source[0] + " " + source[21] + " "+ k + "\n " );
      source[20] &= ~(0xff);
      source[20] |= (SEISMIC_DATA_TYPE & 0xff); // only one byte can be written

      for (i = 0; i < (Msg_head + timestampbits / 8); i++) {
        // System.out.println(Msg_head + " " + timestampbits);
        // System.out.println(source[i] + " " + i);
        writeint(0, 8, source[i]);
      }
      // writeint(0,4,source[i]);//codingparameter written
      for (i = 0; i < numdecodedsamples; i++) {
        writeint(0, 16, decodedunfoldedsamples[i]);
      }
      // System.out.println("decodepacketbytepointer " + decodepacketbytepointer + " " +
      // decodepacketbitpointer + "\n " );
      /* reset variables for next packet read */
      decodepacketbitpointer = 0;
      decodepacketbytepointer = 0;
      // System.out.println("Destination[0][0]:" + destination[0][0] + "\n " );
      // Write to a file with the timestamp and numdecodedsamples
      // descript_string  += time_s;
      // descript_string += " ";
      descript_string += numdecodedsamples;
      // descript_string += " ";
      // descript_string +=decodedfoldedsamples[5];
      // descript_string += " ";
      // descript_string += decodedunfoldedsamples[1];
      // descript_string += " ";
      // descript_string += decodedunfoldedsamples[numdecodedsamples-2];
      descript_string += "\r\n";
      try {
        FileOutputStream outstream;
        outstream = new FileOutputStream(compress_logfile, true);
        for (int m = 0; m < descript_string.length(); ++m) {
          outstream.write((byte) descript_string.charAt(m));
        }
        outstream.close();
      } catch (IOException e) {
      }

    }
    // The number of bytes after decompression is longer than the compressed one, it should be
    // seperated into several packets
    // It should go here more frequently
    else {
      try {
        FileOutputStream outstream;
        outstream = new FileOutputStream(compress_logfile, true);

        quote = numdecodedsamples / (packetbytes_length / 2 - 2);
        // System.out.println("#####The Number of decompressed packets =  " + numdecodedsamples +
        // "quote " + quote + "\n");

        for (k = 0; k < quote; k++) {
          // change data type here
          source[20] &= ~(0xff);
          source[20] |= (SEISMIC_DATA_TYPE & 0xff); // only one byte can be written

          // change the sequence number here
          source[22] &= ~(0xff);
          source[23] &= ~(0xff);
          source[22] |= ((APP_seqo + k) & 0x00ff); // only one byte can be written
          source[23] |= ((APP_seqo + k) & 0xff00) >> 8; // only one byte can be written
          // System.out.println("Changing seqno ****** " + (APP_seqo+k) + " || " +
          // Integer.toHexString(source[23]) + " " + Integer.toHexString(source[22]) + "k" + k + "\n
          // " );

          for (i = 0; i < Msg_head; i++) {
            writeint(k, 8, source[i]);
          }
          if (k > 0) {
            // change time_stamp here
            timestamp += ((packetbytes_length) / 2 - 2) * timeinterval;
          }
          time_pre = timestamp;
          min = (timestamp / 60000);
          writeint(k, 6, min); // write minute byte
          timestamp = timestamp % 60000;
          sec = (timestamp / 1000);
          writeint(k, 6, sec); // write second byte
          timestamp = timestamp % 1000;
          millisec = timestamp;
          writeint(k, 10, millisec); // write millisecond byte
          writeint(k, 10, timeinterval); // write time interval
          timestamp = time_pre;

          // System.out.println("Changing timestamp******** " + timestamp + "| k ==" + k + "\n " );

          for (i = k * (packetbytes_length / 2 - 2);
              i < (k + 1) * (packetbytes_length / 2 - 2);
              i++) {
            writeint(k, 16, decodedunfoldedsamples[i]); // one sample costs two bytes
          }
          // System.out.println("decodepacketbytepointer " + decodepacketbytepointer + " " +
          // decodepacketbitpointer + "\n " );
          // reset variables for next packet read
          decodepacketbitpointer = 0;
          decodepacketbytepointer = 0;

          // System.out.println("Destination[0][0]:" + destination[0][0] + "\n " );

        }
        // Write to a file with the timestamp and numdecodedsamples
        // descript_string  += time_s;
        // descript_string += " ";
        descript_string += numdecodedsamples;
        descript_string += " ";
        // descript_string +=decodedfoldedsamples[1];
        // descript_string += " ";
        // descript_string += decodedunfoldedsamples[1];
        // descript_string += " ";
        // descript_string += decodedunfoldedsamples[numdecodedsamples-2];
        descript_string += "\r\n";

        for (int m = 0; m < descript_string.length(); ++m) {
          outstream.write((byte) descript_string.charAt(m));
        }
        descript_string = "";

        if ((residule = (numdecodedsamples) % (packetbytes_length / 2 - 2)) != 0) {
          // System.out.println("For the residule***************"  + "\n " );
          // change length here
          TOS_length = (Msg_head - 10 + 4 + residule * 2);
          APP_length = (TOS_length - 14);
          source[0] &= ~(0xff); // TOS_Msg length
          source[21] &= ~(0xff); // APP_Msg length
          source[0] |= (TOS_length & 0xff); // only one byte can be written
          source[21] |= (APP_length & 0xff); // only one byte can be written

          // change data type here
          source[20] &= ~(0xff);
          source[20] |= (SEISMIC_DATA_TYPE & 0xff); // only one byte can be written

          // change the sequenceNum here
          source[22] &= ~(0xff);
          source[23] &= ~(0xff);
          source[22] |= ((APP_seqo + quote) & 0x00ff); // only one byte can be written
          source[23] |= ((APP_seqo + quote) & 0xff00) >> 8; // only one byte can be written
          // System.out.println("Changing seqno ****** " + (APP_seqo+quote) + " || " +
          // Integer.toHexString(source[23]) + " " + Integer.toHexString(source[22]) + "quote" +
          // quote + "\n " );

          destination_last_row = new byte[TOS_length + 10];

          for (i = 0; i < Msg_head; i++) {
            writeint_last_row(8, source[i]);
          }

          // change time_stamp here
          timestamp += ((packetbytes_length) / 2 - 2) * timeinterval;
          time_pre = timestamp;
          min = (timestamp / 60000);
          writeint_last_row(6, min); // write minute byte
          timestamp = timestamp % 60000;
          sec = (timestamp / 1000);
          writeint_last_row(6, sec); // write second byte
          timestamp = timestamp % 1000;
          millisec = timestamp;
          writeint_last_row(10, millisec); // write millisecond byte
          writeint_last_row(10, timeinterval); // write time interval
          timestamp = time_pre;

          // System.out.println("Changing timestamp******** " + timestamp + "| residule ==" +
          // residule + "\n " );

          for (i = quote * (packetbytes_length / 2 - 2);
              i < ((quote) * (packetbytes_length / 2 - 2) + residule);
              i++) {
            writeint_last_row(16, decodedunfoldedsamples[i]);
          }
          // reset variables for next packet read
          decodepacketbitpointer = 0;
          decodepacketbytepointer = 0;
          // Write to a file with the timestamp and numdecodedsamples
          /*descript_string  += time_s;
          descript_string += " ";
          descript_string += residule;
          descript_string += "\r\n";
          for (int m=0; m<descript_string.length();++m){
          	outstream.write((byte)descript_string.charAt(m));
          }
          descript_string = "";*/
        }

        outstream.close();
      } catch (IOException e) {
      }
      // return 1;
    }
  }