예제 #1
0
  public static void writeByteBuffer(ByteBuffer bbuf, String filename) {
    // Write bbuf to filename
    File file;
    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 {
        // Create a writable file channel
        FileChannel wChannel = new FileOutputStream(file, true).getChannel();
        // Write the ByteBuffer contents; the bytes between the ByteBuffer's
        // position and the limit is written to the file
        wChannel.write(bbuf);

        // Close the file
        wChannel.close();
      } catch (IOException e) {
      }
    } catch (java.lang.Exception e) {
    }
  }
예제 #2
0
 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) {
   }
 }
  public static void processBrRequisitionFile(
      java.io.File filePortrait2Process,
      biz.systempartners.claims.ClaimsViewer claimsViewer,
      java.util.Vector invoiceVector,
      java.util.Vector filesVector) {

    biz.systempartners.claims.XMLClaimFile xmlClaimFile =
        new biz.systempartners.claims.XMLClaimFile();

    xmlClaimFile.processFile(filePortrait2Process);

    javax.swing.JTable tempInvoiceTable;

    java.util.Vector headerInvoiceVector = new java.util.Vector(1, 1);

    headerInvoiceVector.addElement("Invoice No.");

    //     claimsTable = new javax.swing.JTable(5,4);
    // claimsTable = claimsViewer.getInvoiceTable();
    claimsTable = xmlClaimFile.xmlClaim.getInvoiceTable();
    invoiceTable = claimsViewer.getInvoiceListTable();

    javax.swing.JPanel claimsViewerPanel = claimsViewer.getClaimsViewerPanel();

    javax.swing.JScrollPane jScrollPane11 = claimsViewer.getScrollPane();

    javax.swing.JScrollPane invoiceScrollPane = claimsViewer.getInvoiceListScrollPane();

    invoiceVector = claimsViewer.getInvoiceVector();

    java.util.Vector invoiceChildVector = new java.util.Vector(1, 1);
    javax.swing.JTextField patientNo = claimsViewer.getPatientNo();
    javax.swing.JTextField patientName = claimsViewer.getPatientName();
    javax.swing.JTextField schemeMemberNo = claimsViewer.getSchemeMemberNo();
    javax.swing.JTextField schemeName = claimsViewer.getSchemeName();
    javax.swing.JTextField schemePayer = claimsViewer.getSchemePayer();
    javax.swing.JTextField accountNo = claimsViewer.getAccountNo();
    javax.swing.JTextField invoiceNo = claimsViewer.getInvoiceNo();
    javax.swing.JTextField healthCareProvider = claimsViewer.getHealthCareProvider();

    jScrollPane11.setViewportView(claimsTable);
    if (claimsViewer.isShowing()) {
      claimsViewer.validate();
    } else {
      claimsViewer.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
      claimsViewer.setVisible(true);
    }

    claimsViewer.invalidate();

    // try {

    //     try {

    //   java.io.FileInputStream requisFileIOStream = new
    // java.io.FileInputStream(filePortrait2Process);

    //   java.io.ObjectInputStream requisObjInStream = new
    // java.io.ObjectInputStream(requisFileIOStream);

    //                javax.swing.table.JTableHeader claimsTableHeader =
    // (javax.swing.table.JTableHeader)requisObjInStream.readObject();

    //  requisTable = (javax.swing.JTable)requisObjInStream.readObject();

    //  String invoiceNoString = (java.lang.String)requisObjInStream.readObject();
    String invoiceNoString = xmlClaimFile.xmlClaim.getInvoiceNumber();
    invoiceNo.setText(invoiceNoString);

    //  patientNo.setText((java.lang.String)requisObjInStream.readObject());
    patientNo.setText(xmlClaimFile.xmlClaim.getPatientNumber());
    System.out.println(
        "PATIENT NUMBER : "
            + xmlClaimFile.xmlClaim.getPatientNumber()
            + "   "
            + xmlClaimFile.xmlClaim.getPatientName()
            + "  "
            + xmlClaimFile.xmlClaim.getSchemeName());
    // patientName.setText((java.lang.String)requisObjInStream.readObject());
    patientName.setText(xmlClaimFile.xmlClaim.getPatientName());
    //   schemeMemberNo.setText((java.lang.String)requisObjInStream.readObject());
    schemeMemberNo.setText(xmlClaimFile.xmlClaim.getSchemeMemberNumber());
    //   schemeName.setText((java.lang.String)requisObjInStream.readObject());
    schemeName.setText(xmlClaimFile.xmlClaim.getSchemeName());
    //  schemePayer.setText((java.lang.String)requisObjInStream.readObject());
    schemePayer.setText(xmlClaimFile.xmlClaim.getSchemePayer());
    //  accountNo.setText((java.lang.String)requisObjInStream.readObject());
    accountNo.setText(xmlClaimFile.xmlClaim.getAccountNumber());
    healthCareProvider.setText(xmlClaimFile.xmlClaim.getHealthCareProvider());

    tempInvoiceTable = new javax.swing.JTable(invoiceVector, headerInvoiceVector);
    invoiceChildVector.add(invoiceNoString);
    invoiceChildVector.add(filePortrait2Process.getPath());
    if (filesVector == null) {
      filesVector = new java.util.Vector(1, 1);
    }

    filesVector.add(filePortrait2Process.getAbsolutePath());
    claimsViewer.filesVector = filesVector;
    if (invoiceVector == null) {
      invoiceVector = new java.util.Vector(1, 1);
    }
    invoiceVector.add(invoiceChildVector);
    /*
    invoiceNo.setText(invoiceNoString);
    invoiceChildVector.add(invoiceNoString);
    invoiceChildVector.add(filePortrait2Process.getPath());
    filesVector.add(filePortrait2Process.getAbsolutePath());
    //                System.out.println("Child Cector Size ="+invoiceChildVector.size());
    //                System.out.println("File saved in child vector ="+filePortrait2Process.getPath());
    invoiceVector.add(invoiceChildVector);
    //                            for (int j = 0; j < invoiceChildVector.capacity(); j++) {
    //                System.out.println("Child entry ["+invoiceChildVector.elementAt(j)+"]");
    //            }
    patientNo.setText((java.lang.String)requisObjInStream.readObject());

    patientName.setText((java.lang.String)requisObjInStream.readObject());

    schemeMemberNo.setText((java.lang.String)requisObjInStream.readObject());

    schemeName.setText((java.lang.String)requisObjInStream.readObject());

    schemePayer.setText((java.lang.String)requisObjInStream.readObject());

    accountNo.setText((java.lang.String)requisObjInStream.readObject());
    */
    tempInvoiceTable = new javax.swing.JTable(invoiceVector, headerInvoiceVector);

    System.out.println("Starting to populate tables ...");
    /**
     * for (int i = 0; i < requisTable.getModel().getRowCount(); i++) {
     *
     * <p>for (int j = 0; j < requisTable.getModel().getColumnCount(); j++){
     *
     * <p>if (requisTable.getValueAt(i,0) != null) {
     *
     * <p>claimsTable.setValueAt(requisTable.getValueAt(i,j), i, j);
     *
     * <p>System.out.println(requisTable.getValueAt(i,j)); } } }
     */
    for (int i = 0; i < tempInvoiceTable.getModel().getRowCount(); i++) {

      for (int j = 0; j < tempInvoiceTable.getModel().getColumnCount(); j++) {

        if (tempInvoiceTable.getValueAt(i, 0) != null) {

          invoiceTable.setValueAt(tempInvoiceTable.getValueAt(i, j), i, j);
          System.out.println("Invoices : " + tempInvoiceTable.getValueAt(i, j));
          System.out.println(tempInvoiceTable.getValueAt(i, j));
        }
      }
    }

    //        claimsTable.setModel(requisTable.getModel());

    gridBagConstraints = new java.awt.GridBagConstraints();

    gridBagConstraints.gridx = 0;

    gridBagConstraints.gridy = 0;

    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;

    gridBagConstraints.weightx = 1.0;

    gridBagConstraints.weighty = 100.0;

    claimsViewerPanel.removeAll();

    claimsViewerPanel.add(jScrollPane11, gridBagConstraints);

    invoiceScrollPane.setViewportView(invoiceTable);

    jScrollPane11.setViewportView(claimsTable);

    claimsViewerPanel.validate();

    for (int i = 0; i < invoiceVector.size(); i++) {

      java.util.Vector childVector = (java.util.Vector) invoiceVector.elementAt(i);

      for (int j = 0; j < childVector.size(); j++) {

        //               System.out.println("Child entry at ---- !!! ["+j+"] is
        // ["+childVector.elementAt(j)+"]");

        File file2SelectedInvoice;

        file2SelectedInvoice = new java.io.File(childVector.elementAt(j).toString());

        System.out.println("Selected File ---- !!!!! [" + file2SelectedInvoice.getPath() + "]");
      }

      //           for (int j = 0; j < childVector.size(); j++) {

      //            if  (childVector.elementAt(0).toString().equalsIgnoreCase(invoiceNo)) {

      //           }
      //        }

    }

    //   } catch(java.lang.ClassNotFoundException cnfExec) {

    //       javax.swing.JOptionPane.showMessageDialog(new java.awt.Frame(), cnfExec.getMessage());

    //    }

    // } catch(java.io.IOException ioExec) {

    //    javax.swing.JOptionPane.showMessageDialog(new java.awt.Frame(), ioExec.getMessage());

    //  }
  }
  public static void dumpPart(Part p, biz.systempartners.claims.ClaimsViewer claimsViewer)
      throws Exception {
    if (p instanceof Message) dumpEnvelope((Message) p);

    /**
     * Dump input stream ..
     *
     * <p>InputStream is = p.getInputStream(); // If "is" is not already buffered, wrap a
     * BufferedInputStream // around it. if (!(is instanceof BufferedInputStream)) is = new
     * BufferedInputStream(is); int c; while ((c = is.read()) != -1) System.out.write(c);
     */
    String ct = p.getContentType();
    try {
      pr("CONTENT-TYPE: " + (new ContentType(ct)).toString());
    } catch (ParseException pex) {
      pr("BAD CONTENT-TYPE: " + ct);
    }
    String filename = p.getFileName();
    if (filename != null) pr("FILENAME: " + filename);

    /*
     * Using isMimeType to determine the content type avoids
     * fetching the actual content data until we need it.
     */
    if (p.isMimeType("text/plain")) {
      pr("This is plain text");
      pr("---------------------------");
      if (!showStructure && !saveAttachments) System.out.println((String) p.getContent());
    } else if (p.isMimeType("multipart/*")) {
      pr("This is a Multipart");
      pr("---------------------------");
      Multipart mp = (Multipart) p.getContent();
      level++;
      int count = mp.getCount();
      for (int i = 0; i < count; i++) dumpPart(mp.getBodyPart(i), claimsViewer);
      level--;
    } else if (p.isMimeType("message/rfc822")) {
      pr("This is a Nested Message");
      pr("---------------------------");
      level++;
      dumpPart((Part) p.getContent(), claimsViewer);
      level--;
    } else {
      if (!showStructure && !saveAttachments) {
        /*
         * If we actually want to see the data, and it's not a
         * MIME type we know, fetch it and check its Java type.
         */
        Object o = p.getContent();
        if (o instanceof String) {
          pr("This is a string");
          pr("---------------------------");
          System.out.println((String) o);
        } else if (o instanceof InputStream) {
          pr("This is just an input stream");
          pr("---------------------------");
          InputStream is = (InputStream) o;
          int c;
          while ((c = is.read()) != -1) System.out.write(c);
        } else {
          pr("This is an unknown type");
          pr("---------------------------");
          pr(o.toString());
        }
      } else {
        // just a separator
        pr("---------------------------");
      }
    }

    /*
     * If we're saving attachments, write out anything that
     * looks like an attachment into an appropriately named
     * file.  Don't overwrite existing files to prevent
     * mistakes.
     */
    if (saveAttachments && level != 0 && !p.isMimeType("multipart/*")) {
      String disp = p.getDisposition();
      // many mailers don't include a Content-Disposition
      if (disp == null || disp.equalsIgnoreCase(Part.ATTACHMENT)) {
        if (filename == null) filename = "Attachment" + attnum++;
        pr("Saving attachment to file " + filename);
        try {
          File f = new File(System.getProperty("user.dir"), filename);
          /*  if (f.exists())
          // XXX - could try a series of names
          throw new IOException("file exists");*/
          OutputStream os = new BufferedOutputStream(new FileOutputStream(f));
          InputStream is = p.getInputStream();
          int c;
          while ((c = is.read()) != -1) os.write(c);
          os.close();
          if (p.isMimeType("text/xml") || p.isMimeType("application/octet-stream")) {
            processBrRequisitionFile(
                f, claimsViewer, claimsViewer.getInvoiceVector(), claimsViewer.getFilesVector());
          }
          System.out.println("I have saved file [" + f.getAbsolutePath() + "]");
        } catch (IOException ex) {
          pr("Failed to save attachment: " + ex);
        }
        pr("---------------------------");
      }
    }
  }
예제 #5
0
  public static int decompress(byte[] source) {

    int codingparameter, lengthofpacket;
    int numdecodedsamples;
    int packetbytes_length;
    int denomexponent = 14;
    int muexponent = 15;
    int biasscalebits = 8;
    int halfmu = (1 << (muexponent - 1)) - 1;
    int biasscalealmosthalf = (1 << (biasscalebits - 1)) - 1;
    int Msg_head = 24; // Message header in bytes
    int weightqshift = denomexponent + capexponent - weightquantbits + 1;

    packetbytes_length = source.length - Msg_head;
    decodepacketbitpointer = 0;
    decodepacketbytepointer = 0;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 84; j++) {
        destination[i][j] = 0;
      }
    }
    decodedfoldedsamples = new int[2048];
    decodedunfoldedsamples = new int[2048];
    packetdebiasedsamples = new int[2048];
    for (int k = 0; k < 2048; k++) {
      decodedfoldedsamples[k] = 0;
      decodedunfoldedsamples[k] = 0;
      packetdebiasedsamples[k] = 0;
    }
    // Create a logfile

    String logfile = "C:\\" + "test_compression_ratio" + ".txt";
    compress_logfile = new File(logfile);
    boolean exists = compress_logfile.exists();
    if (!exists) {
      // create a new, empty node file
      try {
        compress_logfile = new File(logfile);
        boolean success = compress_logfile.createNewFile();
      } catch (IOException e) {
        System.out.println("Create Event Log file failed!");
      }
    }

    time_s = "";
    // System.out.println("--------Decompressing start*****************************" + "\n");

    numdecodedsamples =
        decodepacket(
            codeoverheadbits, packetbytes_length, source, Msg_head); // 1 sample costs 2 bytes

    // Reset bias estimate based on quantized value just read from packet
    // int biasestimate_r = decoderbiasestimate_r;

    // System.out.println("The decoded number of sample in the packet =" + numdecodedsamples + " | "
    // + "decoded biasestimate: " + biasestimate_r + "\n");

    // Reset weight vector based on quantized components just read from packet
    for (int i = 0; i < order; i++) {

      if (decodedweightquant[i] > 0) {
        weight_r[i] = (decodedweightquant[i]) << weightqshift;
      } else if (decodedweightquant[i] < 0) {
        weight_r[i] = -((-decodedweightquant[i]) << weightqshift);
      } else {
        weight_r[i] = 0;
      }
      // System.out.println("decodedweightquant[i]:"+decodedweightquant[i]+"weight_r"+ weight_r[i]+
      // "| weightqshift" + weightqshift + "\n");
    }

    // At this point we have bias estimate and weight vector, and a packet of folded samples.
    // follow the prediction procedure to decode each sample given the folded value
    for (int i = 0; i < numdecodedsamples; i++) {
      int j;
      int predicteddebiased_r;
      long predictedsample_r;
      int err_r; // error in prediction of de-biased signal
      int maxsample_r = ((1 << (bitdepth)) - 1) << denomexponent;
      int minsample_r = (-(1 << (bitdepth))) << denomexponent;

      // System.out.println("max sample value:" + (maxsample_r>>denomexponent) + "\n");

      predicteddebiased_r = predictdebiasedsample_r(i);
      predictedsample_r = predicteddebiased_r + decoderbiasestimate_r;

      // predicted sample value cannot exceed the known instrument dynamic range
      if (predictedsample_r > maxsample_r) predictedsample_r = maxsample_r;
      if (predictedsample_r < minsample_r) predictedsample_r = minsample_r;

      decodedunfoldedsamples[i] = unfoldsample(decodedfoldedsamples[i], predictedsample_r);

      // System.out.println("predicteddebiased_r:" + predicteddebiased_r + "decoderbiasestimate_r" +
      // decoderbiasestimate_r + "\n");

      // System.out.println("Decoded folded sample value:" + decodedfoldedsamples[i] +
      // "predictedsample_r" + predictedsample_r + "\n");

      // System.out.println("Sample: " + i + "Decoded unfolded samples:" + decodedunfoldedsamples[i]
      // + "\n");

      packetdebiasedsamples[i] =
          decodedunfoldedsamples[i] - ((decoderbiasestimate_r + almosthalf) >> denomexponent);
      /* update weight vector if we have sufficient samples in the packet */
      if (i >= order) {
        err_r = predicteddebiased_r - (packetdebiasedsamples[i] << denomexponent);

        if (err_r < 0)
          for (j = 1; j <= order; j++)
            weight_r[j - 1] +=
                ((packetdebiasedsamples[i - j] << denomexponent) + halfmu) >> muexponent;
        else
          for (j = 1; j <= order; j++)
            weight_r[j - 1] -=
                ((packetdebiasedsamples[i - j] << denomexponent) + halfmu) >> muexponent;
      }

      /* update bias estimate */
      decoderbiasestimate_r -=
          (decoderbiasestimate_r
                  - (decodedunfoldedsamples[i] << denomexponent)
                  + biasscalealmosthalf)
              >> biasscalebits;

      /* At this point, decodedsample is our decoded sample value and the prediction information has been updated to decode the next sample. */
    }

    write_Byte_array(
        Msg_head,
        packetbytes_length,
        numdecodedsamples,
        source); // judge whether the generated array is contained in one packet.

    /*int arr_num = (numdecodedsamples / 28)+1;
    	for (int k=0;k<arr_num-1 ;k++ )
    	{
    		decodepacketbitpointer = 0;
    		decodepacketbytepointer = 28;
    		for (int i=0;i<28 ;i++ )
    		{
    			System.out.println("***Samples decompressed from each packet K : " + k + " | " + readint(16,destination[k]) + "\n");
    		}
    	}
    	if ((numdecodedsamples % 28) != 0)
    	{
    		decodepacketbitpointer = 0;
    		decodepacketbytepointer = 28;
    		for (int k=0;k< numdecodedsamples % 28 ;k++ )
    		{
    			System.out.println("***Samples decompressed from each packet :  " + (numdecodedsamples % 28) + " | "+ readint(16,destination_last_row) + "\n");
    		}
    	}
    */
    return numdecodedsamples;
  }