[4279] in java-interest

home help back first fref pref prev next nref lref last post

java-interest-digest V1 #237

daemon@ATHENA.MIT.EDU (java.sun.com!owner-java-interest-d)
Fri Dec 15 13:27:17 1995

From: java.sun.com!owner-java-interest-digest@asoft.msk.su
Date: Fri, 27 Oct 1995 16:10:00 -0700
To: java-interest-digest@java.sun.com
Reply-To: java.sun.com!java-interest@asoft.msk.su

java-interest-digest      Friday, 27 October 1995      Volume 01 : Number 237

In this issue:

 	Re: Java eval? 
 	Select System call
 	netscape2.0b1J (java errors)
 	Java object-oriented database
 	Re: Java eval?
 	Re: javadoc suggestion
 	snapping applet width
 	Re: Java eval?
 	RE: How to learn Java
 	Re: How to learn Java
 	Missing Includes for Native Methods
 	Re: Select System call
 	Testing Applets...
 	imagemap?
 	content & protocol handlers and JDK
 	java on NT, Can't find class...?
 	Re: snapping applet width
 	Re: String.substring lies about what exceptions is throws
 	RE: java beta for Win NT/95?
 	Re: content & protocol handlers and JDK
 	Re: How to learn Java
 	Re: java on NT, Can't find class...?
 	Finalize()
 	Re: imagemap?
 	[none]
 	[none]

----------------------------------------------------------------------

From: "Mario Ruggier" <ruggier@ptsun00.cern.ch>
Date: Fri, 27 Oct 1995 09:28:19 +0100
Subject: Re: Java eval? 

Hi,

>Mario Ruggier asked:
>> Is it possible in Java to read a piece of Java code at runtime  and 
>> execute it, as in Lisp, Smalltalk and Perl ? 
>
>Are you asking if you can load a piece of Java code *into* a Perl script and 
>execute it?  Or are you asking if you can cause a Java program to load in 
>another piece of Java code and execute that?
>
>Sean Russell

I am asking whether it is possible to have a Java program calculate
pieces of Java code and execute them. This may be useful for example
when requiring to read data that may be in many formats. A data format
specific class may be computed on the fly and instantiated, facilitating
the manipulation of the data. This is trivial to do in Lisp. 
Is it possible in Java ? 

thanks,

Mario Ruggier
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Programming Techniques Group,                     Bat. 1, R-003
ECP Division, CERN                              +41 22 767 8072
CH-1211 Geneva 23                       ruggier@ptsun00.cern.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                               http://ptsun00.cern.ch/~ruggier/


------------------------------

From: Motohiro Suzuki <motohiro@nwk.cl.nec.co.jp>
Date: Fri, 27 Oct 1995 21:49:58 +0900
Subject: Select System call

I have a couple of questions about Java Language...

○ I want to emulate the select system call. 
○ I want to do the access control of the application by host or user.

Is it possible?

****************************************
	C&C Labs. NEC Corp.
	   Motohiro SUZUKI
    E-mail: motohiro@nwk.cl.nec.co.jp
    Tel   : +81-44-856-2314
    Fax   : +81-44-856-2229
****************************************

   


------------------------------

From: exceed@wwcd.com (exceed group)
Date: Fri, 27 Oct 1995 09:06:28 -0500
Subject: netscape2.0b1J (java errors)

Hi

Getting errors as follows.

********************************************************

Cannot allocate colormap entry for default background

********************************************************

Xerror badwindow (invalid window parameter)
major opcode 25 (x_sendevent)


stderr diagnostics have been truncated

any ideas on these problems?

Thanks Gary

------------------------------

From: qiu@informatik.uni-ulm.de (Shiwei Qiu)
Date: Fri, 27 Oct 95 15:29:26 +0100
Subject: Java object-oriented database

Hi,

anybody knows Java object-oriented database or persistent datastore.
I plan to store java object with programs (methods) persistently in an OODBMS
in my application.

Any hints are very apprieciated.


Regards

Shiwei Qiu

==============================================================
        Shiwei Qiu
        University of Ulm
        Department of Databases and Information Systems
        Einsteinallee 8
        89069 Ulm
        Germany
 
        Tel: 0049-731-502-4230
        Fax: 0049-731-502-4134
        E-mail: qiu@informatik.uni-ulm.de
==============================================================
 

------------------------------

From: mentor@io.org (David Forster)
Date: Fri, 27 Oct 1995 11:54:56 -0500
Subject: Re: Java eval?

At 17:31 10/26/95, ser@jersey.uoregon.edu wrote:
>Mario Ruggier asked:
>> Is it possible in Java to read a piece of Java code at runtime  and
>> execute it, as in Lisp, Smalltalk and Perl ?
>
>Are you asking if you can load a piece of Java code *into* a Perl script and
>execute it?  Or are you asking if you can cause a Java program to load in
>another piece of Java code and execute that?

No, I think he's asking if there's something like lisp's EVAL in Java,
i.e., can you do something like
  (eval '(print "Hi there!"))
which just executes the PRINT form.  [You'd think this is a pretty silly
thing to do, but it's the basis of the LISP Read-Eval-Print loop, which in
its simplest form is "(loop (print (eval (read))))" -- minus all sorts of
useful history-tracking stuff, of course.]

I don't think you can do this directly, but there's nothing to stop you
shipping code off to a server, compiling it there, and loading it back in.

Cheers,
  David Forster                <br><a href="http://www.io.org/~mentor">
  Mentor Software Solutions    </a><br>
  +1 905 832 4837              <br>



------------------------------

From: Anselm Baird_smith <Anselm.Baird_Smith@inria.fr>
Date: Fri, 27 Oct 1995 15:58:17 +0100
Subject: Re: javadoc suggestion

Hi, 

Find enclosed a small program that implements my suggestion about
javadoc. Given a set of packages, it will dump the full class
hierarchy (ASCII text).

Sample usage:
- -----
# java classtree.tree -p java.lang 
java.lang.Object
  java.lang.Throwable
    java.lang.Error
      java.lang.LinkageError
        java.lang.VerifyError
        java.lang.IncompatibleClassChangeError
          java.lang.AbstractMethodError
          java.lang.NoSuchMethodError
          java.lang.IllegalAccessError
          java.lang.InstantiationError
          java.lang.NoSuchFieldError
        java.lang.ClassCircularityError
...
- -----

Enjoy,

Anselm.
BTW: the code is quiet ugly, I'll probably make a version spitting
HTML instead of ASCII, with links to the doc directory.

- ----- ~/myclasses/classtree/Tree.java
package classtree ;

import java.io.* ;
import java.util.* ;

public class Tree {
    public static Tree      root       = null ;
    public static Hashtable registered = new Hashtable() ;

    static {
	root = makeTree ("java.lang.Object") ;
	root.installed = true ;
    }

    Class   cls        = null ;
    Vector  subclasses = null ;
    boolean installed  = false ;	// shouldn't be need, poorly designed

    /**
     * Emit an error and exit.
     * @param msg The error message.
     */

    public static void error (String msg) {
	System.out.println (msg) ;
	System.exit (1) ;
    }

    /**
     * Emit a warning.
     * @param msg The warning to emit.
     */

    public static void warning (String msg) {
	System.out.println (msg) ;
    }

    /**
     * Create a new Tree entry.
     * @param cls The subclass to install
     */
    
    private static Tree makeTree (Class cls) {
	Tree entry = (Tree) registered.get (cls.getName()) ;
	if ( entry == null ) {
	    entry = new Tree () ;
	    entry.cls        = cls ;
	    entry.subclasses = null ;
	    registered.put (cls.getName(), entry) ;
	}
	return entry ;
    }

    private static Tree makeTree (String clsname) {
	Class cls = Class.forName (clsname) ;
	return makeTree (cls) ;
    }

    /**
     * Insert a class in the class structure.
     * @param cls The class to insert in the hierarchy.
     * @return The Tree entry of this class.
     */
     
    public static Tree insertClass (Class cls) {
	Tree entry = makeTree (cls) ;
	if ( entry.installed )
	    return entry ;
	// Install the class and all its superclass:
	Class superclass = cls.getSuperclass() ;
	Tree  superentry = insertClass (superclass) ;
	if ( superentry.subclasses == null )
	    superentry.subclasses = new Vector(5) ;
	superentry.subclasses.addElement (entry) ;
	entry.installed = true ;
	return entry ;
    }

    public static void dumpAll (String prefix, Tree node) {
	System.out.println (prefix+node.cls.getName()) ;
	if ( node.subclasses != null) {
	    for (int i = 0 ; i < node.subclasses.size() ; i++)
		dumpAll (prefix+"  ", (Tree) node.subclasses.elementAt(i)) ;
	}
    }

    public static void doPackage (File pkgdir, String pkg) {
	String files[] = pkgdir.list() ;
	for (int i = 0 ; i < files.length ; i++) {
	    String filename = files[i] ;
	    if ( ! filename.endsWith (".class") )
		continue ;
	    // okay, this looks like a proper class, add it in hierarchy image
	    String clsname = pkg+"."+filename.substring(0, filename.length()-6);
	    Class  cls = null ;
	    try {
		cls = Class.forName(clsname) ;
		insertClass (cls) ;
	    } catch (Exception e) {
		warning ("Couldn't find class " + clsname + ", skipping.") ;
	    }
	}
    }

    public static void doPackage (File pathes[], String pkg) {
	String pkgpath[] = parsePackage (pkg) ;
	// First, try to locate the package:
	for (int i = 0 ; i < pathes.length ; i++) {
	    File pkgdir = pathes[i] ;
	    for (int j = 0 ; j < pkgpath.length ; j++) 
		pkgdir = new File (pkgdir, pkgpath[j]) ;
	    if ( pkgdir.exists() ) {
		doPackage (pkgdir, pkg) ;
		return ;
	    }
	}
    }

    public static String[] parsePackage (String pkg) {
	Vector pkgs = new Vector() ;
	int isep  = 0 ;
	int len   = pkg.length() ;
	int start = 0 ;
	while ((isep = pkg.indexOf('.', start)) >= 0) {
	    if ( isep == start ) {
		start = isep+1 ;
		continue ;
	    }
	    pkgs.addElement (pkg.substring(start, isep)) ;
	    start = isep+1 ;
	}
	if ( start < len ) 
	    pkgs.addElement(pkg.substring (start)) ;
	String packages[] = new String[pkgs.size()] ;
	pkgs.copyInto (packages) ;
	return packages ;
    }

    public static File[] parseClasspath () {
	String clspath = (String) System.getProperty ("java.class.path") ;
	if ( clspath == null )
	    error ("[properties] Couldn't find class path.") ;
	String pathsep = (String) System.getProperty ("path.separator") ;
	if ( pathsep == null )
	    error ("[properties] Couldn't find path separator.") ;
	Vector pathes = new Vector() ;
	int    isep   = 0 ;
	int    seplen = pathsep.length() ;
	int    start  = 0 ;
	int    len    = clspath.length() ;
	while ((isep = clspath.indexOf (pathsep, start)) >= 0 ) {
	    // Skip empty items:
	    if ( isep == start ) {
		start = isep + 1 ;
		continue ;
	    } 
	    // Get current item:
	    pathes.addElement (new File(clspath.substring (start, isep))) ;
	    start = (isep+seplen) ;
	}
	if ( start < len )
	    pathes.addElement (new File (clspath.substring (start))) ;
	File p[] = new File[pathes.size()] ;
	pathes.copyInto (p) ;
	return p ;
    }
	
    public static void main (String args[]) {
	Vector packages = new Vector() ;
	for (int i = 0 ; i < args.length ; i++) {
	    if (args[i].equals("-p") && (i+1 < args.length)) {
		packages.addElement (args[++i]) ;
	    } else {
		System.out.println ("classtree.tree -p <package>") ;
	    }
	}
	File pathes[] = parseClasspath () ;
	for (int i = 0 ; i < packages.size() ; i++)
	    doPackage (pathes, (String) packages.elementAt(i)) ;
	Tree.dumpAll("", root) ;
    }

}



------------------------------

From: Suzanna Lewis <suzi@fruitfly.berkeley.edu>
Date: Fri, 27 Oct 1995 09:44:16 -0700
Subject: snapping applet width

Hi someone,

My application includes displaying an indefinitely long string (a DNA
sequence).  The most desirable behaviour would be to have the width of
the applet snap to the maximum that is currently visible in the
browser.  Furthermore if the user resized the browser window then the
applet should follow suit and resize accordingly.

In the alpha version I had this sort of working (limited by the fact
that I wasn't able to capture the resize event directly, only catching
it when some other event came down to the applet).

In the pre-beta version it isn't immediately obvious to me how to
locate the information.  The parental width information only contains
width as it is set in the html file. Is snapping to the browser width
philosophically at odds to the browser-applet relationship?  I hope
I haven't missed something obvious, and any help/information is
appreciated.

- -S

------------------------------

From: "Tim Pearson (Starwave)" <TimPE@starwave.com>
Date: Fri, 27 Oct 95 09:02:00 PDT
Subject: Re: Java eval?

>> Is it possible in Java to read a piece of Java code at runtime  and
>> execute it, as in Lisp, Smalltalk and Perl ?
>
>Are you asking if you can load a piece of Java code *into* a Perl script 
and
>execute it?  Or are you asking if you can cause a Java program to load in
>another piece of Java code and execute that?

He wants to compile and execute a string (of Java code) at runtime.  It's a 
common thing to do in most interpreted languages.  Does anyone know how to 
do this?

Tim Pearson
timpe@starwave.com


------------------------------

From: "Tim Pearson (Starwave)" <TimPE@starwave.com>
Date: Fri, 27 Oct 95 09:13:00 PDT
Subject: RE: How to learn Java

I'd recommend picking up a copy of "Java!" by Tim Ritchey 
(http://www.mcp.com/newriders/), I found it at Barnes & Noble.  The only 
other book out is called "Presenting Java" and its not worth the paper its 
printed on.

Tim Pearson
timpe@starwave.com

------------------------------

From: Jay Allen <kimberl1@gramercy.ios.com>
Date: Fri, 27 Oct 1995 13:11:05 -0400 (EDT)
Subject: Re: How to learn Java

While Tim Ritchey's "Java!" contains a good, quick-and-dirty 
description of OOP, Grady Booch's "Object-Oriented Design and 
Analysis" is much more thorough. Tackle those two books, and you 
should be in very good shape.

- -J-

------------------------------

From: jonathan@athenanow.com (Jonathan Taylor)
Date: Fri, 27 Oct 1995 13:17:22 -0400
Subject: Missing Includes for Native Methods

I'm trying to implement some native methods with the Alpha 3 release on NT.

StubPreamble.h evidently also requires typedefs_md.h and possibly also
oobj_md.h.  Where can I find / how can I create these files?

Thanks.





------------------------------

From: Michael Lorton <mlorton@eshop.com>
Date: Fri, 27 Oct 1995 10:43:07 -0700
Subject: Re: Select System call

> I have a couple of questions about Java Language...
> + I want to emulate the select system call. 

No, you *think* you want to emulate the select system call.  select()
is what Unix uses because it doesn't have threads.  Java has threads.
So create one for each file descriptor and wait.

> + I want to do the access control of the application by host or user.

I don't understand that statement.

> Motohiro SUZUKI

I used to know a Motorcycle Suzuki...


M.

------------------------------

From: Christopher Wang <cwang@cs.columbia.edu>
Date: Fri, 27 Oct 1995 14:12:32 -0400
Subject: Testing Applets...

Hi, I was wondering what the best way to test applets is. Reloading 
from the browser doesn't work since it just re-executes the program, it
doesn't fetch it again. I tried using the AppletView from the Sun homepage
but I keep getting the same stupid errors

java.lang.NoClassDefFoundException AppletViewerDisplayItem
        at AppletViewer.initApplet(AppletViewer.java:42)
        at AppletViewer.main(AppletViewer.java:80)


I'm using 1.0alpha3 on Solaris. Any help would be appreciated. Thanks.



------------------------------

From: chwright@goesser.mit.edu
Date: Fri, 27 Oct 1995 15:13:56 -0400 (EDT)
Subject: imagemap?

I've been trying to RTFM, as suggested, but some things I
can't figure out.  Can I have an imagemap-type link from
a hot spot in an applet to some URL?

Thanks,
Chantal

------------------------------

From: edanuff@protagonist.com (Ed Anuff)
Date: Fri, 27 Oct 1995 13:44:38 -0800
Subject: content & protocol handlers and JDK

Has anyone gotten a content or protocol handler running under the JDK,
particularly with Netscape.  Does Netscape support Java-based content and
protocol handlers?

Thanks

Ed


Ed Anuff
Protagonist Interactive
edanuff@protagonist.com
http://www.protagonist.com/



------------------------------

From: "C. Max Chase" <C.Max.Chase>
Date: Fri, 27 Oct 1995 17:19:02 -0500
Subject: java on NT, Can't find class...?

Hi, 

I am very interested in Java and Hotjava and have just loaded Alpha3 
for Win95 and NT (I have NT 3.51). Hotjava runs well and I can run a 
local applet I compiled (Helloworld). 

However, for some reason I can not run an application with plain 
java. It ALWAYS returns the error "Can't find class helloworldapp". 
No matter what I try to do with CLASSPATH or -classpath, or where I 
put the complied class file, etc???  If I use the -verbose switch, 
java indicates that it is loading all the needed classes, EVEN the one 
in question, but when it goes to run it, NO dice.

C:\internet\hotjava\applications\helloworldapp>java -verbose helloworldapp
[Loaded c:\internet\hotjava\classes\java\lang\Thread.class]
[Loaded c:\internet\hotjava\classes\java\lang\Object.class]
[Loaded c:\internet\hotjava\classes\java\lang\Class.class]
[Loaded c:\internet\hotjava\classes\java\lang\NoClassDefFoundException.class]
[Loaded c:\internet\hotjava\classes\java\lang\Exception.class]
[Loaded c:\internet\hotjava\classes\java\lang\OutOfMemoryException.class]
[Loaded .\helloworldapp.class]
Can't find class helloworldapp

I would be VERY grateful if someone could give me a "hint" as to 
what I am doing wrong. I realize, of course, that I will feel VERY 
stupid when I get an answer, but I'm willing to risk it, Java looks 
like it is worth the risk!!!

Thanks,

Max

Max Chase, N2XHF - mchase@waterw.com
7 Reid's Ferry Ct., Medford, NJ 08055

------------------------------

From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
Date: Fri, 27 Oct 1995 11:12:20 -0700
Subject: Re: snapping applet width

Hi Suzi,

> My application includes displaying an indefinitely long string (a DNA
> sequence).  The most desirable behaviour would be to have the width of
> the applet snap to the maximum that is currently visible in the
> browser.  Furthermore if the user resized the browser window then the
> applet should follow suit and resize accordingly.

There is an undocumented feature in the Netscape navigator that lets
you set the width as a percentage. Try setting it to 100%.

Have fun,

	Arthur van Hoff

------------------------------

From: tball@scndprsn.Eng.Sun.COM (Thomas Ball)
Date: Fri, 27 Oct 1995 14:26:41 -0700
Subject: Re: String.substring lies about what exceptions is throws

Sami Shaio says:  You don't need to declare them since they're runtime 
exceptions.

Tom

>  From daemon@java  Thu Oct 26 17:37:58 1995
>  To: java-interest@java.Eng.Sun.COM
>  Subject: String.substring lies about what exceptions is throws
>  X-Info: To unsubscribe, send 'unsubscribe' to java-interest-request@java.sun.com
>  
>  	
>      public String substring(int beginIndex, int endIndex) {
>  	if (beginIndex > endIndex) {
>  	    int tmp = beginIndex;
>  	    beginIndex = endIndex;
>  	    endIndex = tmp;
>  	}
>  	if (beginIndex < 0) {
>  	    throw new StringIndexOutOfBoundsException(beginIndex);
>  	} 
>  	if (endIndex > count) {
>  	    throw new StringIndexOutOfBoundsException(endIndex);
>  	}
>  	return ((beginIndex == 0) && (endIndex == count)) ? this :
>  		   new String(value, offset + beginIndex, endIndex - beginIndex);
>      }
>  
>  It doesn't declare it's throwing any exceptions ...  Was the prebeta
>  release compiled with the prebeta compiler?  I think not.
>  -
>  This message was sent to the java-interest mailing list
>  Info: send 'help' to java-interest-request@java.sun.com
>  

------------------------------

From: Thomas.Ball@Eng.Sun.COM (Thomas Ball)
Date: Fri, 27 Oct 1995 14:33:35 -0700
Subject: RE: java beta for Win NT/95?

>  Notice how the Sun Java engineers who used to post answers to this list on
>  an almost daily basis have hardly posted anything in the last several days?
>  They're probably spending every minute they have on the Win NT JDK.  I think
>  they know there are literally hundreds of us out there who log in every day
>  hoping that it's ready.

Right the first time. :-)

>  Of course, if they rush it out the door full of bugs, we'll all yell at them
>  for not taking the time to do it right...

Oh, boy -- I knew I was looking forward to getting this release out for a
reason...

Tom Ball
Java Products Group (currently hacking the Win32 AWT)

------------------------------

From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
Date: Fri, 27 Oct 1995 14:35:16 -0700
Subject: Re: content & protocol handlers and JDK

Hi Ed,

> Has anyone gotten a content or protocol handler running under the JDK,
> particularly with Netscape.  Does Netscape support Java-based content and
> protocol handlers?

Netscape won't support protocol handlers as part of their 2.0 releases.

Have fun,

	Arthur van Hoff

------------------------------

From: Alain_Avakian@andor.com (Alain Avakian)
Date: 27 Oct 1995 10:37:02 GMT
Subject: Re: How to learn Java

Get the book JAVA! from Tim Titchey published by New Riders:
www.mcp.com/newriders. 

This book includes comprehensive coverage of Java and explains the
differences between Java, C, and C++. It also includes tricks and tips to
serve, configure, administer, and support Java on an Internet server. It also
contains a CD-ROM with ready to use Java applets. The book costs $35.00.

- -=Alain=-

------------------------------

From: flar@bendenweyr.Eng.Sun.COM (Jim Graham)
Date: Fri, 27 Oct 1995 14:51:49 -0700
Subject: Re: java on NT, Can't find class...?

> However, for some reason I can not run an application with plain 
> java. It ALWAYS returns the error "Can't find class helloworldapp". 

Are you sure that it is implementing a main() method with the right
signature?

	public static void main(String argv[]) {
	}

				...jim

------------------------------

From: Richard Williamson <richwill@infoscape.com>
Date: Fri, 27 Oct 95 15:04:50 -0700
Subject: Finalize()

This comment in the Java documentation was pointed out to me:

>When a user defines the void finalize() method in a class  
>definition, finalization is enabled for objects of that class.  
>Finalization of an object consists of the system calling the  
>object's finalize() method. Finalization normally occurs  
>asynchronously at some time after the garbage collection mechanism  
>identifies an object as inaccessible. Users can invoke their  
>finalize() method explicitly but this doesn't guarantee that the  
>system will not call it again at a later time. If a finalized  
object >references another finalized object, the objects are  
finalized in *>the reverse order of their creation. Java does not  
guarantee
*>when or if a given finalized object will have its finalize()  
method *>called. Thus, finalization should not be relied on for  
program *>correctness. Rather, finalization should be thought of as  
an *>optimization.

The final few sentences is this footnote are somewhat alarming.   
How can finalize() be used for ANYTHING if it isn't reliably called?

- - Richard Williamson
richwill@infoscape.com

------------------------------

From: flar@bendenweyr.Eng.Sun.COM (Jim Graham)
Date: Fri, 27 Oct 1995 15:14:13 -0700
Subject: Re: imagemap?

> I've been trying to RTFM, as suggested, but some things I
> can't figure out.  Can I have an imagemap-type link from
> a hot spot in an applet to some URL?

Any applet can call the "showDocument(URL)" method to switch to another
URL at any time.  It is up to the applet to do this at the appropriate
time (such as when the user clicks on some part of the applet which is
serving as an anchor)...

				...jim

------------------------------

From: bazzi@rennes.enst-bretagne.fr (Mohamed Bazzi)
Date: Fri, 27 Oct 1995 23:26:04 +0100
Subject: [none]

Hello,
My purpose is to write an applet to get a remote file. And to create an 
local entry. The URL of the file is given in a HTML page as parameter.

Here is the applet :

import java.applet.Applet;
import java.net.URL;
import java.io.InputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.*;



public class WBTest extends java.applet.Applet  {

	String StrUrl;
	URL Nurl;
	public void init() {
		StrUrl = getParameter("pt");
/* please see the HTML page below */
		resize(500,20);
		} 



public void start() {
	 	System.out.println(StrUrl);
		Nurl = new URL(StrUrl);
		System.out.println("Nurl");

		InputStream is = Nurl.openStream(); 
		System.out.println("is");

		int cpt = is.read(); 
		System.out.println("cpt");
/* at that stage "cpt" not displayed, so the read operation has failled */
		File f = new File("/usr/tmp","bocage.donnees");
		FileOutputStream fis = new FileOutputStream(f);

		while (cpt != -1) {
			System.out.println("cpt");
			fis.write(cpt);
			cpt = is.read();
		} 
		
	}

} 


Here is the HTML page :

<HTML>
<HEAD>
<TITLE>FILE MANIPULATION</TITLE>
</HEAD>

<BODY>
HERE IS THE OUTPUT OF MY PROGRAM:
<APPLET CODE="WBTest.class"	WIDTH=150  HEIGHT=25>
<param name= pt value="http://bloodmoney/cours_c">
</APPLET>
</BODY>
</HTML>

bloodmoney is the name of the server, and cours_c is the name of the file.

When i run the applet with appletviewer i had the following message :

Thread-5 find class WBTest
Opening stream to: file:/homes/bazzi/.www/WBTest.class to get WBTest
http://bloodmoney/cours_c
Nurl
*** Security Exception: socket.connect:->bloodmoney ***
sun.applet.AppletSecurityException security.socket.connect: ->bloodmoney
        at java.lang.Throwable.<init>(Throwable.java)
        at java.lang.Exception.<init>(Exception.java)
        at java.lang.RuntimeException.<init>(RuntimeException.java)
        at java.lang.SecurityException.<init>(SecurityException.java)
        at sun.applet.AppletSecurityException.<init>(AppletSecurityException.java:36)
        at sun.applet.AppletSecurity.checkConnect(AppletSecurity.java:299)
        at sun.applet.AppletSecurity.checkConnect(AppletSecurity.java:271)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:100)
        at sun.net.www.http.HttpClient.get(HttpClient.java:225)
        at sun.net.www.http.HttpClient.handleUrl(HttpClient.java:423)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:452)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:56)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:124)
        at java.net.URL.openStream(URL.java)
        at WBTest.start(WBTest.java:25)
        at sun.applet.AppletPanel.run(AppletPanel.java:268)
        at java.lang.Thread.run(Thread.java)


I have done the same with a stand-alone application and it works well, here the program :
import java.applet.Applet;
import java.net.URL;
import java.io.InputStream;
import java.io.File;
import java.io.FileOutputStream;

public class Test2WB  {

	String StrUrl = "http://bloodmoney/cours_c";
	URL  Nurl;

	public void ecrire() {
		
		Nurl = new URL(StrUrl);
		InputStream is = Nurl.openStream();
		System.out.println(StrUrl);
		int cpt = is.read(); 
		System.out.println("cpt");
		File f = new File("/usr/tmp","cours_c");
		FileOutputStream fis = new FileOutputStream(f);
		while (cpt != -1) {
			fis.write(cpt);
			cpt = is.read();
			System.out.println("cpt");
			} 
		}

	public static void main(String args[]) {

		Test2WB wb = new Test2WB();
		wb.ecrire();
	}

		
} 

Thanks to show me what's wrong with the applet.


------------------------------

From: ser@jersey.uoregon.edu
Date: Fri, 27 Oct 1995 16:06:19 -0700
Subject: [none]

Hi, Mohamed,

Although I have never tried this, I suspect that you may have trouble writing 
to files from an applet.

To read in a file given an URL,

	URL msg = new URL(getParameter("pt));
	DataInputStream fin = new DataInputStream(msg.getStream());

This will give you a stream you can read strings from.

If file output is allowed from java applets on the local host, this is how you 
would do it:

        String output = "Hello my baby\n";
	DataOutputStream fout = new DataOutputStream(
                                new FileOutputStream("/usr/tmp/blah.txt"));
        fout.writeBytes(output);                // You can output Strings
        fout.writeBytes("Hello my darling\n");  // in any form
        fout.close();

- --- SER



------------------------------

End of java-interest-digest V1 #237
***********************************



-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post