wood burning stoves 2.0*
The moose likes Applets and the fly likes applet access file on his server? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "applet access file on his server?" Watch "applet access file on his server?" New topic
Author

applet access file on his server?

hassan ali
Ranch Hand

Joined: Apr 23, 2006
Posts: 127
hi

I am trying to open image in server side , i tryied getCodeBase()+filename
but applet throws NullpointerException how can i get path on server and read from or right to ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
That hard to say without knowing which object is null, and what the code is trying to do at that point. (In other words, post the relevant lines of code, and the full stack trace of the exception.)
[ March 31, 2008: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
hassan ali
Ranch Hand

Joined: Apr 23, 2006
Posts: 127
thanks

this the full applet
//////////////

import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.net.URL;
import java.io.File;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JPanel;

import javax.media.jai.JAI;
import javax.media.jai.*;
import com.sun.media.jai.codec.*;
import java.awt.image.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import javax.imageio.*;
import java.awt.Image;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.sun.media.jai.codec.TIFFDecodeParam;
import java.awt.image.renderable.ParameterBlock;

public class readFileApplet extends Applet implements ActionListener{
String fileToRead = "test1.txt";
String fileToRead2 = "nour.tif";
StringBuffer strBuff;
TextArea txtArea;
Graphics g;

public void init(){
txtArea = new TextArea(100, 100);
txtArea.setEditable(false);
add(txtArea, "center");
String prHtml =fileToRead ;
if (prHtml != null) fileToRead = new String(prHtml);
readFile();
}
public void actionPerformed(ActionEvent e) {}
public void readFile(){
String line;
URL url = null;
try{
url = new URL(getCodeBase(), fileToRead);
}
catch(MalformedURLException e){}
try{


InputStream in = url.openStream();
BufferedReader bf = new BufferedReader(new InputStreamReader(in));

strBuff = new StringBuffer();
while((line = bf.readLine()) != null){
strBuff.append(line + "\n");
}
txtArea.append("File Name : " + fileToRead + "\n");
txtArea.append("File Name : " + getDocumentBase()+ fileToRead);


Image im=getImage(new URL(getCodeBase() + fileToRead2));
RenderedImage image = JAI.create("fileload",fileToRead2);
BufferedImage jj = (BufferedImage)image;

Graphics2D g = jj.createGraphics();

g.drawImage(im, 0, 0,this.getWidth(),this.getHeight(), this);
g.drawString("Hassan Ali Hassan",90,100);
g.dispose();
RenderedImage image3 = jj;
String filename2=getCodeBase() + "nour2.tif";
txtArea.append("File Name : " + filename2 + "\n");
String format2 = "TIFF";

/////////////////???

RenderedOp op = JAI.create("filestore", image3,"nour2.tif", format2);

////////////////???


}catch(Exception ds){

txtArea.append(ds.toString());
}


}
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
So which line is causing the exception? Which object is null? What is the full stack trace?


Completely ignoring exceptions is rarely a good idea, and definitely not here.
hassan ali
Ranch Hand

Joined: Apr 23, 2006
Posts: 127
hi
this Console message .
i need to write TIFF file(nour2.tif) after loding nour.tiff and get Graphic(g) object and draw using it and save it as nour2.tiff


liveconnect: Invoking JS method: document
liveconnect: Invoking JS method: URL
basic: Referencing classloader: sun.plugin.ClassLoaderInfo@5d173, refcount=1
basic: Added progress listener: sun.plugin.util.GrayBoxPainter@ab95e6
basic: Loading applet ...
basic: Initializing applet ...
basic: Starting applet ...
basic: completed perf rollup
security: Loading Root CA certificates from D:\PROGRA~1\Java\JRE16~1.0_0\lib\security\cacerts
security: Loaded Root CA certificates from D:\PROGRA~1\Java\JRE16~1.0_0\lib\security\cacerts
security: Loading certificates from Deployment session certificate store
security: Loaded certificates from Deployment session certificate store
security: Loading certificates from Internet Explorer ROOT certificate store
security: Loaded certificates from Internet Explorer ROOT certificate store
security: Loading certificates from Internet Explorer TrustedPublisher certificate store
security: Loaded certificates from Internet Explorer TrustedPublisher certificate store
security: Validate the certificate chain using CertPath API
security: Obtain certificate collection in Root CA certificate store
security: Obtain certificate collection in Root CA certificate store
security: The CRL support is disabled
security: The OCSP support is disabled
security: No timestamping info available
security: Checking if certificate is in Deployment denied certificate store
security: Checking if certificate is in Deployment permanent certificate store
security: Checking if certificate is in Deployment session certificate store
security: Checking if certificate is in Internet Explorer TrustedPublisher certificate store
security: User has granted the priviledges to the code for this session only
security: Adding certificate in Deployment session certificate store
security: Added certificate in Deployment session certificate store
security: Saving certificates in Deployment session certificate store
security: Saved certificates in Deployment session certificate store
basic: Loaded image: file:/D:/Documents%20and%20Settings/hasssan/Desktop/jaiapplet/nour.tif
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
That's not a stack trace, those are just startup message sof the Java Plugin. But you said there was an exception, and for figuring out what causes that it's important to know where that occurs. So you need to tell us which line of code causes the exception, and -since you said it's a NullPointerException- you should start with examining which object is null.
hassan ali
Ranch Hand

Joined: Apr 23, 2006
Posts: 127
hi

this is the
exception

java.lang.IllegalArgumentException: FileStore IOException encountered in file creation test: The filename, directory name, or volume label syntax is incorrect

String filename2=getCodeBase() + "nour2.tif";
String format2 = "TIFF";
/////////////////???
RenderedOp op = JAI.create("filestore", image3,filename2, format2);
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
So what does getCodeBase() return? Is filename2 a valid file name?
hassan ali
Ranch Hand

Joined: Apr 23, 2006
Posts: 127
getCodeBase()+filename2

that return
file:/D:/Documents%20and%20Settings/hasssan/Desktop/jaiapplet/nour2.tif


where filename2=nour2.tif

[ April 01, 2008: Message edited by: hassan ali ]
[ April 02, 2008: Message edited by: hassan ali ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: applet access file on his server?
 
Similar Threads
ach! do applets and filestreams not mix?
my applet can't connect to database
Applet interacts with server.
connect applet to database?
How to make an applet signed?