Results 1 to 3 of 3
  1. #1
    anurit is offline Member
    Join Date
    Mar 2010
    Rep Power

    Default How write created file on remote host without saving on HDD?

    I create PDF or image file in my programm (applet) and I will send this file in e-mail.
    Now I create file, write on my HDD and connect with PHP script and in POST method send file to remote host.
    I will create file without saving him on HDD (I will not use signed applet).
    How have I transform following code:

    create image:
    BufferedImage bim = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_RGB);
    BufferedImage subbim = bim.getSubimage(170, 26, this.getWidth()-170, this.getHeight()-26);
    AffineTransform tx = new AffineTransform();
    tx.scale(2, 2);
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
    subbim = op.filter(subbim, null);
    try {
    Date data = GregorianCalendar.getInstance().getTime();
    ImageIO.write(subbim, "png", new File("C:/obrazy/screan_2d_" +data.getTime()+ ".png"));

    sending file:
    String destionationPath = "upload.php";
    String fileFieldName = "file";

    File f = new File("C:/obrazy/screan_2d.png");
    FileInputStream in = null;
    DataOutputStream out = null;
    HttpURLConnection con = null;
    in = new FileInputStream(f);
    String path = getCodeBase().toString()+destionationPath;
    URL url = new URL(path);
    con = (HttpURLConnection) url.openConnection();

    con.setRequestProperty("Connection", "Keep-Alive");
    String boundary = "JakisSeparator";
    con.setRequestProperty("Content-Type", "multipart/form-data; boundary="+boundary);

    String endl = "\r\n";
    out = new DataOutputStream(con.getOutputStream());

    out.writeBytes("Content-Disposition: form-data; name=\""+fileFieldName+"\"; filename=\"" + URLEncoder.encode(f.getName()) +"\"" + endl);
    out.writeBytes("Content-Type: application/octet-stream"+endl);

    byte[] bytes = new byte[1024];
    int read = 0;
    while((read = != -1)
    out.write(bytes, 0, read);

    and creating PDF:
    Document document = new Document();
    try {
    Date data = GregorianCalendar.getInstance().getTime();
    FileOutputStream fos1 = new FileOutputStream(new File("C:/obrazy/mydoc_" +data.getTime()+ ".pdf"));

    PdfWriter writer1 = PdfWriter.getInstance(document,fos1);;
    Paragraph nagl = new Paragraph("Start");

    Can someone help, how transform this code to may direct use for example DataInPutStream, DataOutputStram objects or something similar, without saving file on local disc?
    Last edited by anurit; 03-03-2010 at 02:54 PM.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    I was thinking, in theory it might be possible to use the PipedInputStream and PipedOutputStream, ?

    Java Code:
    PipedOutputStream pOut = new PipedOutputStream();
    PipedInputStream pIn = new PipedInputStream(pOut);
    where we have the image creator generate its image output to an instance of PipedOutputStream, and the sending file operation would read from its associated PipedInputStream.

    The catch with using these is we need to have the reading and writing operations done in two threads. If we currently do things successively in the main application thread, perhaps try to create a thread to do the image generation, start it up to start writing to the piped output stream, and then in the main thread start reading the piped input stream

    another option I though of, you can try to encapsulate the logic of sending the file into an object that extends for example

    Where the constructor takes on arguments for the remote URL, and performs any connection operations when the class is created. then passing this fancy output stream to the image writer would cause it to really do the upload as the image is being written.

    I suppose a similar principle could be employed in the generation of the PDF file, but I am not clear how or what it would render out to. an applet is already in the client side, I am not sure it would be possible to have it some how display the pdf from the applet if it was not already a file.

  3. #3
    anurit is offline Member
    Join Date
    Mar 2010
    Rep Power


    Thanks for your help. I try this pipe streams use. Now I use signed applet...

Similar Threads

  1. How to create file into another host from a host
    By varadha in forum Networking
    Replies: 3
    Last Post: 02-10-2010, 10:03 PM
  2. copy file from local host to remote host
    By isotoper in forum New To Java
    Replies: 4
    Last Post: 12-24-2009, 05:41 PM
  3. Need Help on Remote Host Screen Capture
    By krishnaraoveera1294 in forum AWT / Swing
    Replies: 4
    Last Post: 03-13-2009, 11:56 PM
  4. Replies: 0
    Last Post: 10-31-2008, 08:07 PM
  5. How to find file created date.....
    By roshithmca in forum Advanced Java
    Replies: 1
    Last Post: 02-18-2008, 10:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts