Results 1 to 3 of 3
- 03-03-2010, 11:44 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 3
- Rep Power
- 0
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);
this.paintAll(bim.getGraphics());
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;
try
{
in = new FileInputStream(f);
String path = getCodeBase().toString()+destionationPath;
URL url = new URL(path);
con = (HttpURLConnection) url.openConnection();
con.setUseCaches(false);
con.setDefaultUseCaches(false);
con.setRequestMethod("POST");
con.setRequestProperty("Connection", "Keep-Alive");
String boundary = "JakisSeparator";
con.setRequestProperty("Content-Type", "multipart/form-data; boundary="+boundary);
con.setDoOutput(true);
con.setDoInput(true);
String endl = "\r\n";
out = new DataOutputStream(con.getOutputStream());
out.writeBytes("--"+boundary+endl);
out.writeBytes("Content-Disposition: form-data; name=\""+fileFieldName+"\"; filename=\"" + URLEncoder.encode(f.getName()) +"\"" + endl);
out.writeBytes("Content-Type: application/octet-stream"+endl);
out.writeBytes(endl);
byte[] bytes = new byte[1024];
int read = 0;
while((read = in.read(bytes)) != -1)
{
out.write(bytes, 0, read);
}
out.writeBytes(endl+"--"+boundary+"--"+endl);
out.flush();
con.connect();
}
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);
document.open();
Paragraph nagl = new Paragraph("Start");
document.add(nagl);
//(...)
document.close();
}
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 01:54 PM.
- 03-04-2010, 03:06 AM #2
I was thinking, in theory it might be possible to use the PipedInputStream and PipedOutputStream, ?
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.Java Code:PipedOutputStream pOut = new PipedOutputStream(); PipedInputStream pIn = new PipedInputStream(pOut);
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 java.io.OutputStream. 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.
- 03-04-2010, 11:33 AM #3
Member
- Join Date
- Mar 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
How to create file into another host from a host
By varadha in forum NetworkingReplies: 3Last Post: 02-10-2010, 09:03 PM -
copy file from local host to remote host
By isotoper in forum New To JavaReplies: 4Last Post: 12-24-2009, 04:41 PM -
Need Help on Remote Host Screen Capture
By krishnaraoveera1294 in forum AWT / SwingReplies: 4Last Post: 03-13-2009, 10:56 PM -
Unable to connect to MySQL on another (unix) host from Eclipse on my windows host
By kairamr in forum EclipseReplies: 0Last Post: 10-31-2008, 07:07 PM -
How to find file created date.....
By roshithmca in forum Advanced JavaReplies: 1Last Post: 02-18-2008, 09:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks