comp.lang.java.programmer
http://groups-beta.google.com/group/comp.lang.java.programmer
[EMAIL PROTECTED]

Today's topics:

* CPU increasing slowly up to 100% - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3970cf07d01d1d5c
* Challenge: Triangles puzzle - 9 messages, 7 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5e013ca5d7daa5f0
* license question? - viral nature of GPL - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d7680dfef2acffd6
* Deobfuscation tool - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f91581e118d9a7ed
* force installing older plugin - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/85517288db341f21
* building an object index - data structure question - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a06239c8e3bcc672
* DOM parsing - Document root element is missing. - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f08ad4f7dca18bf2
* Copy the contents of an image - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c5f059e5ad5319b9
* java/jython - newbie question - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6e49cb3577db8262
* How connect to hsqldb database in jar? - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/abc3be4fb59cfd19
* Am I the only one who questions JSTL, Struts Tags, XSL Tags? - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/48683f1f07068c7d
* Need help w. Image Servlet. - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1bd066386cd1860
* problem with jboss startguide tutorial (dukes bank app) - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f1c074d82599e1f0
* Stuck on a caching issue. - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9caf57d6aa519122
  
==========================================================================
TOPIC: CPU increasing slowly up to 100%
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3970cf07d01d1d5c
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 17 2004 5:25 am
From: "John B. Matthews" <[EMAIL PROTECTED]> 

In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (SLL) wrote:

> Paul Lutus <Paul Lutus <[EMAIL PROTECTED]>> wrote in message 
> news:<[EMAIL PROTECTED]>...
> 
> 
> > 
> > Tell us if this is a new problem with existing software, or a new problem
> > with new software. Tell us if you have access to, and control over, the
> > source code for the software.
> 
> This is a new problem in new software, manifested only on our
> production system (4 CPU machines).
> We are not able to reproduce such a behavoir in our development (1 CPU
> machines) and test bed (2 CPU machines) environments.
> We have total control over source code. The application logging system
> reveals no anomalies during CPU increase, the number of threads used
> is more or less constant (50-60).
> Any ideas for further investigation?

Is there any reason to suspect the CPU measurement tool? For 
example, top initially reports CPU usage over a long period and then 
reports interval usage after the first update. Until that first 
update, the apparent usage may be distorted by recent heavy usage.

-- 
John
----
jmatthews at wright dot edu
www dot wright dot edu/~john.matthews/




==========================================================================
TOPIC: Challenge: Triangles puzzle
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5e013ca5d7daa5f0
==========================================================================

== 1 of 9 ==
Date:   Sun,   Oct 17 2004 5:54 am
From: "Yogo" <n o s p a m> 

>
> a 0/0/180 triangle is a THREE SIDED POLYGON
>

A polygon is a closed figure (each line segment must intersects exactly two 
other line segments). You don't get a closed figure with that.

Besides that, not only the sum of the three angles of a triangle must be 
equal to 180, the sum of two angles must also be less than two right angles.

A line segment is just a line segment.






== 2 of 9 ==
Date:   Sun,   Oct 17 2004 4:57 am
From: Jim Newton <[EMAIL PROTECTED]> 

why do you think a 0/0/180 triangle is not closed?

-jim

Yogo wrote:
>>a 0/0/180 triangle is a THREE SIDED POLYGON
>>
> 
> 
> A polygon is a closed figure (each line segment must intersects exactly two 
> other line segments). You don't get a closed figure with that.
> 
> Besides that, not only the sum of the three angles of a triangle must be 
> equal to 180, the sum of two angles must also be less than two right angles.
> 
> A line segment is just a line segment.
> 
> 
> 




== 3 of 9 ==
Date:   Sun,   Oct 17 2004 5:02 am
From: Jim Newton <[EMAIL PROTECTED]> 

in a 0/0/180 triangle each side intersects its two neighboring
sides.

why do you think that the sum of two angles must also be less
than two right angles?

I think you are trying to put a lot of additional requirements
on the definition of a triangle.  You are making it harder than
it is.




Yogo wrote:
>>a 0/0/180 triangle is a THREE SIDED POLYGON
>>
> 
> 
> A polygon is a closed figure (each line segment must intersects exactly two 
> other line segments). You don't get a closed figure with that.
> 
> Besides that, not only the sum of the three angles of a triangle must be 
> equal to 180, the sum of two angles must also be less than two right angles.
> 
> A line segment is just a line segment.
> 
> 
> 




== 4 of 9 ==
Date:   Sun,   Oct 17 2004 6:17 am
From: Wanja Gayk <[EMAIL PROTECTED]> 

Raymond Martineau said...

> 0 degrees is still an angle, as is 180.  These angles are generally
> significant as they indicate parallel lines, but can be valid in figures.  

The problem is, that parallel lines cannot form a triangle.

Greets,
-Wanja-

-- 
"Gewisse Schriftsteller sagen von ihren Werken immer: 'Mein Buch, mein 
Kommentar, meine Geschichte'. [..] Es wäre besser, wenn sie sagten: 
'unser Buch, unser Kommentar, unsere Geschichte'; wenn man bedenkt, dass 
das Gute darin mehr von anderen ist als von ihnen." [Blaise Pascal]



== 5 of 9 ==
Date:   Sun,   Oct 17 2004 6:33 am
From: Wanja Gayk <[EMAIL PROTECTED]> 

Jim Newton said...
> in a 0/0/180 triangle each side intersects its two neighboring
> sides.

Nope, it intersects in an unlimited number of points, which harms the 
definition of a triangle, because there are more than 3 intersections.

If you bring the area of a triangle down to zero, it stops being a 
triangle: you get either a point or a line.

Say you would shorten each side of a triamgle to a length of 0, you 
would get a single point, which is less than 3, which allows no angle, 
no intersections and thus is no triangle at all. Same problem, 
basically.

Greets,
-Wanja-

-- 
"Gewisse Schriftsteller sagen von ihren Werken immer: 'Mein Buch, mein 
Kommentar, meine Geschichte'. [..] Es wäre besser, wenn sie sagten: 
'unser Buch, unser Kommentar, unsere Geschichte'; wenn man bedenkt, dass 
das Gute darin mehr von anderen ist als von ihnen." [Blaise Pascal]



== 6 of 9 ==
Date:   Sun,   Oct 17 2004 8:31 am
From: [EMAIL PROTECTED] (Raymond Martineau) 

On Sun, 17 Oct 2004 15:17:21 +0200, Wanja Gayk <[EMAIL PROTECTED]>
wrote:

>Raymond Martineau said...
>
>> 0 degrees is still an angle, as is 180.  These angles are generally
>> significant as they indicate parallel lines, but can be valid in figures.  
>
>The problem is, that parallel lines cannot form a triangle.
>

They can if they overlap - which is the exact problem one of the posters
was pointing out.

There's also the case with non-euclidian geometry, where a 2D drawing
surface forms a sphere (and nothing is allowed to pass through.)  With
something like this, you can draw three individual lines to surround the
equator, and attempt to call it a triangle.  

That's why you need definitions on what constitutes as a triangle and what
doesn't.  If you don't define things clearly, then you will end up with
confusion and arguments on what really counts as a triangle and what
doesn't.





== 7 of 9 ==
Date:   Sun,   Oct 17 2004 8:47 am
From: Julián Albo <[EMAIL PROTECTED]> 

Hello.

The problem is that the C++ Ansi/Iso standard has not definition of
"trinagle". Then the definition is implementation dependant or undefined
behaviour and seems that you are using different implementatios ;)

-- 
Salu2



== 8 of 9 ==
Date:   Sun,   Oct 17 2004 9:23 am
From: Markus Malkusch <[EMAIL PROTECTED]> 

Jim Newton:

> the sum of the angles in a triangle is 180 degrees.  and a  0, 0, 180
> triangle is still a triangle.

I don't know why you are discussing about it. You're talking about a line. A
triangle is an area. If you decide that a triangle may be a line, then a
rectancle can also be a line. A box can be a rectangle and this can be a
line. And a line could be a point.

So a point is a triangle, rectangle, pyramid, and every other geometrical
structure? I think it's wrong if you decide that an area may be a line. 

Volume, area, line and point are different worlds. And you can't decide that
a line has an exact area of 0, otherwise the sum of lines would be 0, but
it is an area > 0.
-- 
<http://www.domaininformation.de/> - Whoisabfrage 



== 9 of 9 ==
Date:   Sun,   Oct 17 2004 12:42 pm
From: "John McGrath" <[EMAIL PROTECTED]> 

On 10/16/2004 at 9:47:02 PM, Raymond Martineau wrote:

> On Sat, 16 Oct 2004 23:29:52 +0200, "Yogo" <n o s p a m> wrote:
> 
> > A triangle with an area equal to zero doesn't exist. 
> 
> Not as far as a computer is concerned.

That depends on the programming, doesn't it?

Check the dictionary:

   tri·an·gle   n.

   1.  a. The plane figure formed by connecting three points 
          not in a straight line by straight line segments; 
          a three-sided polygon.

   http://dictionary.reference.com/search?q=triangle

-- 
Regards,

John McGrath




==========================================================================
TOPIC: license question? - viral nature of GPL
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d7680dfef2acffd6
==========================================================================

== 1 of 2 ==
Date:   Sun,   Oct 17 2004 7:03 am
From: [EMAIL PROTECTED] (Steve Schefter) 

"Shmuel (Seymour J.) Metz" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
PROTECTED]>...
> In <[EMAIL PROTECTED]>, on 10/15/2004
>    at 09:06 AM, [EMAIL PROTECTED] (Steve Schefter) said:
> 
> >    Linus opinion on this is irrelevant. Neither I nor the FSF nor
> >    many others have released code under anything but the vanilla GPL.
> >    By merging such code Linus lost his ability to vary the license.
> 
> What do you mean by "such code"? 

First of all, this is a quote from Alan Cox, so you'd have to ask him
what he meant by that to be sure.  However, given the context (see my
orginal quote for the complete post), it appears to me that he's referring
to the bits of the code which he and others wrote and is now part of the
Linux kernel.

> What code is Linus distributing under
> the kernel GPL that he does not have the right to so distribute? 

Neither Alan's quote (to my reading of it) nor my post make such a claim.
I was addressing what restrictions there might be on the licensing of
code writen for kernel add-ons.  That is, if I write a kernel add-on,
might I have to put it under GPL too since the kernel is.

And before I get jumped on by folks reading this posting for saying that
I claim that all kernel add-ons must be under GPL, I offer no opinion.  I 
was simply replying to the note which indicated that "GPL or LGPL is NOT 
viral" by saying that, where GPL in concerned at least, "there are differing 
opinions".

> Don't
> confuse Linux with a Linux distribution.

While I realize that other postings in this thread talked of distributions,
I do not.  I spoke strictly of the kernel and the kernel GPL.

         Steve



== 2 of 2 ==
Date:   Sun,   Oct 17 2004 11:07 am
From: John Thompson <[EMAIL PROTECTED]> 

["Followup-To:" header set to comp.os.linux.misc.]
On 2004-10-17, Tor Iver Wilhelmsen <[EMAIL PROTECTED]> wrote:

> "Shmuel (Seymour J.) Metz" <[EMAIL PROTECTED]> writes:
>
>> What do you mean by "such code"? What code is Linus distributing under
>> the kernel GPL that he does not have the right to so distribute? Don't
>> confuse Linux with a Linux distribution. 

> Not to mention that the copyright holder is free to publish his works
> under any (multiple) licenses they feel like, e.g. releasing a GPL
> version of some program, and then release the same program (perhaps
> with more features) under a commercial license, and for instance keep
> working on the commercial codebase.
>
> Case in point: Sendmail.

But sendmail is not licensed under the GPL:

http://www.sendmail.org/license-info.html

-- 

-John ([EMAIL PROTECTED])




==========================================================================
TOPIC: Deobfuscation tool
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f91581e118d9a7ed
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 17 2004 6:34 am
From: Oscar kind <[EMAIL PROTECTED]> 

FU <[EMAIL PROTECTED]> wrote:
> Tor Iver Wilhelmsen wrote:
> 
>> FU <[EMAIL PROTECTED]> writes:
>> 
>>> Can someone give me any links to deobfuscation tools, cant find any
>>> ;/.
>> 
>> Use a decompiler to generate Java source, then change the obfuscated
>> names using a refactoring tool.
> 
> Hmm, I will try this, but I think its not the only problem in reversing this
> app, during decompiling I got a lot of such errors:
> 
> Couldn't resolve all exception handlers in method i
> Couldn't fully decompile method j
> 
> and so on, maybe this is the main reason why I can not find alghoitm Im
> looking for in it...?

You are aware of the fact that Java bytecode is low-level enough that any
Java statements translates into several bytecode commands? This is used by
several obfuscators to mangle class files in such a way that they are
semantically the same, but decompilers get confused and fail.

Deobfuscating a well-obfuscated program is difficult, time-consuming and
mainly handwork. Try to estimate the time/cost needed to do it versus the
price of retreiving the source code or even using similar software.


-- 
Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2




==========================================================================
TOPIC: force installing older plugin
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/85517288db341f21
==========================================================================

== 1 of 2 ==
Date:   Sun,   Oct 17 2004 8:08 am
From: [EMAIL PROTECTED] (Vadim) 

I'd like to force installing an older plugin from java.sun.com or
keep a set of files on my own web site and force instaling from there.

My current code:
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" 
ID = "MyApplet"
WIDTH = 600 HEIGHT = 25 
NAME = "MyApplet" ALIGN = top VSPACE = 0 HSPACE = 0 
codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0";>
...

installs jre 1.3_13 and I'd like the version 1.3_04 be installed
ALWAYS.

Any ideas are appreciated



== 2 of 2 ==
Date:   Sun,   Oct 17 2004 9:37 am
From: Andrew Thompson <[EMAIL PROTECTED]> 

On 17 Oct 2004 08:08:56 -0700, Vadim wrote:

> I'd like to force installing an older plugin from java.sun.com or
> keep a set of files on my own web site and force instaling from there.
> 
> My current code:
> <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" 

You are using what is known as 'dynamic versioning',
the OBJECT element is instructed to download any Java
equal to or greater than the one specified.

You need 'static versioning'
<http://java.sun.com/products/plugin/versions.html>

> installs jre 1.3_13 and I'd like the version 1.3_04 be installed
> ALWAYS.

Look at the HTMLConverter options carefully and see if
you can regenerate your HTML for static versioning.

Alternatively, you might be able to figure the right way
by looking at this..
<http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/using_tags.html#new_object_tag>
..and this..
<http://java.sun.com/j2se/1.4.2/docs/guide/deployment/autodl/autodl-files.html>

HTH

-- 
Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane




==========================================================================
TOPIC: building an object index - data structure question
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a06239c8e3bcc672
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 17 2004 8:17 am
From: [EMAIL PROTECTED] (Raj) 

> The best way would be to include the search criteria in the DB query
> in the first place. THAT'S WHAT A DB IS FOR!!!
> 

I have to look up this object map several hundred / thousand times for
every time this program is executed (which runs in a batch fashion)
and so I need this data structure in memory so as to save needless
database calls. and besides, making changes to the stored procedures
returning the data is not an option in the current development
environment due to political and other reasons.

Thanks
-Raj




==========================================================================
TOPIC: DOM parsing - Document root element is missing.
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f08ad4f7dca18bf2
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 17 2004 8:39 am
From: "xarax" <[EMAIL PROTECTED]> 

"Rico" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> The following piece of code :
>
> DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
> .newInstance();
> DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
> Document doc = docBuilder.parse(filename);
>
>
> ends in "Document root element is missing" for the following XML:
>
> <?xml version="1.0" encoding="utf-8"?>
> <EmailSender>
>     <db_name>master</db_name>
>     <document_type>document_New</document_type>
>     <emailID />
>     <document_ID>23983</document_ID>
> </EmailSender>
>
>
> I don't really know how the XML is being produced but a space between the
> last double-quote and the last '?' seems to solve the problem.
> So does changing double-quotes to single-quotes.
>
> Is it something wrong with the XML document or am I missing something
> about the usage of the API ?

The first line of the XML file is not XML syntax.
That's according to the rules of XML.

<?xml version='1.0' encoding='UTF-8' ?>

The first line above is an example of a correct
XML header. It is *not* XML, because the keywords
must be specified in the correct order. (Attribute
keywords that appear within the XML body can be
specified in any order.) I use single quotes in
preference to double quotes, but the space appearing
before the final ? is required.







==========================================================================
TOPIC: Copy the contents of an image
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c5f059e5ad5319b9
==========================================================================

== 1 of 2 ==
Date:   Sun,   Oct 17 2004 8:49 am
From: Abs <[EMAIL PROTECTED]> 

  Hi!

I need to copy the contents of an image (bufferedimage or volatileimage) 
unto another for backup purposes. Is it enough to do a simple variable 
assignation like this ?


Image im1;
Image im2;
...
im1=im2;



thanks in advance



== 2 of 2 ==
Date:   Sun,   Oct 17 2004 9:59 am
From: "VisionSet" <[EMAIL PROTECTED]> 


"Abs" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
>   Hi!
>
> I need to copy the contents of an image (bufferedimage or volatileimage)
> unto another for backup purposes. Is it enough to do a simple variable
> assignation like this ?
>
>
> Image im1;
> Image im2;
> ...
> im1=im2;

im1 & im2 now point to the same object (that is the object that im2 pointed
to)

If this object is mutated via either variable then both variables will
reflect this change since they point to the same object.

You are therefore not making a copy.

--
Mike W






==========================================================================
TOPIC: java/jython - newbie question
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6e49cb3577db8262
==========================================================================

== 1 of 2 ==
Date:   Sun,   Oct 17 2004 10:26 am
From: [EMAIL PROTECTED] (GP) 

Hi, I'm trying to teach myself a bit of jython and I am trying to run
the code below.  But I keep on getting the error message:
"package org.python.util does not exist
import org.python.util.PythonInterpreter; "
When I try to compile it.  Any ideas would be appriciated.

Thanks!

import org.python.util.PythonInterpreter; 
import org.python.core.*; 

public class SimpleEmbedded { 
    public static void main(String []args)
    throws PyException
    { 
    PythonInterpreter interp =
        new PythonInterpreter();

    System.out.println("Hello, brave new world");
    interp.exec("import sys");
    interp.exec("print sys");

    interp.set("a", new PyInteger(42));
    interp.exec("print a");
    interp.exec("x = 2+2");
    PyObject x = interp.get("x");

    System.out.println("x: "+x);
    System.out.println("Goodbye, cruel world");
    }
}



== 2 of 2 ==
Date:   Sun,   Oct 17 2004 11:55 am
From: "andreas kinell" <[EMAIL PROTECTED]> 

> Hi, I'm trying to teach myself a bit of jython and I am trying to run
> the code below.  But I keep on getting the error message:
> "package org.python.util does not exist
> import org.python.util.PythonInterpreter; "
> When I try to compile it.  Any ideas would be appriciated.
>
> Thanks!
>

reading the error message and combining "sherlock holmes"-like, i would 
consider the possibility that maybe package org.python.util does not exist!

"assume it is on the computer" would watson add.
holmes instantly askes himself who wrote this error message and comes up 
with "the compiler!".
so the compiler thinks this package does not exist, although it is on the 
computer.

watson, clueless, remarks: "so how could the compiler know the package 
exists?"

holmes triumphs "by pointing to it using -classpath !" and closes yet 
another case.

andreas 






==========================================================================
TOPIC: How connect to hsqldb database in jar?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/abc3be4fb59cfd19
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 17 2004 11:27 am
From: Jon Martin Solaas <[EMAIL PROTECTED]> 

Brzezi wrote:
> sob, 16 paź 2004 o 21:07 GMT, Andrew Thompson napisał(a):

> 
> I`v just visited hsqldb homepage, and I saw new version since I were there
> before, so I checked the changelog of this release, and now it is posible
> connect to database which is placed in jar file... so my problem doesen`t
> exist now :)
> 
> solution is:
> 
> jdbc:hsqldb:res:<path in jar>

Well, that's a feature that might come in handy one day, thanks for the 
information ...

-- 
jonmartin.solaas¤h0tm4i1




==========================================================================
TOPIC: Am I the only one who questions JSTL, Struts Tags, XSL Tags?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/48683f1f07068c7d
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 17 2004 1:14 pm
From: [EMAIL PROTECTED] (Greg Smith) 

> I guess it comes down to how you design the application. I'm not trying
> to dodge anything here, merely noting that if you have complex logic to
> execute then it properly belongs in the servlet, not the JSP.
> As I mentioned previously, JSP is all about presentation. About the only
> logic I generally incorporate involves checking for roles or errors and
> displaying accordingly.
> Remember that the servlet has the choice as to which page to forward to;
> don't try to make a single page suffice for all situations when you can
> instead have multiple processing paths. Such an approach would obviate
> the need for complex logic processing at the page level, don't you think?

i hear you... it does seem to me that we're forgetting the lessons
learned over the last 30 years of software engineering. to make
multiple pages when one (plus a little logic) will do, increases the
cost of maintenance. and maintenance is the most expensive phase of
the life cycle. but that may be a different thread.

thanks for your help.




==========================================================================
TOPIC: Need help w. Image Servlet.
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1bd066386cd1860
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 17 2004 1:35 pm
From: Steve Burrus <[EMAIL PROTECTED]> 

Jon, I tried this code here to see the image ("images/31.jpeg") in a
servlet, but it still failed on me at runtime with an exception saying
"File Not Found"! What now am I doing wrong?? :

 >>"// Here is the code again that i "lifted" off of a web page I was
    //pointed to.

            package org.fun.servlets;

            import java.io.*;
            import java.awt.*;
            import javax.servlet.*;
            import javax.servlet.http.*;

public class Outputstream_Img extends HttpServlet {
         // This method is called by the servlet container to process a 
//GET request.
     public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
         // Get the absolute path of the image
         ServletContext sc = getServletContext();
         String realPath = getServletContext().getRealPath("images/") +
"31.jpeg";

         // Get the MIME type of the image
         String mimeType = sc.getMimeType("images/31.jpeg");
         if (mimeType == null) {
             sc.log("Could not get MIME type of " +"images/31.jpeg");
             resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
             return;
         }

         // Set content type
         resp.setContentType(mimeType);

         // Set content size
         File file = new File("images/31.jpeg");
         resp.setContentLength((int)file.length());

         // Open the file and output streams
         FileInputStream in = new FileInputStream(file);
         OutputStream out = resp.getOutputStream();

         // Copy the contents of the file to the output stream
         byte[] buf = new byte[1024];
         int count = 0;
         while ((count = in.read(buf)) >= 0) {
             out.write(buf, 0, count);
         }
         in.close();
         out.close();
       }
}"<<

Jon Martin Solaas wrote:
> snip

> If the problem occurs at runtime, it might have something to do with
> the fact that you are using a file and not a path as parameter to the
>  getRealPath() method. Look in the javadocs, you are supposed to feed
> it a relative path, and the servlet container will prepend/prefix it
> so that it makes up an absolute path instead. I suppose some quasi
> code could look like
> 
> String realPath = getServletContext().getRealPath("images/") +
> "image.gif";
> 
> Now realPath would be something like 
> "/home/tomcat/applications/my_application/public_html/images/image.gif"
>  or something ...
> 




==========================================================================
TOPIC: problem with jboss startguide tutorial (dukes bank app)
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f1c074d82599e1f0
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 17 2004 2:04 pm
From: [EMAIL PROTECTED] (Phoneix) 

hello ,
 i am getting the same error, 
did u reslove it ? 

thanks in advance

-v




==========================================================================
TOPIC: Stuck on a caching issue.
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9caf57d6aa519122
==========================================================================

== 1 of 1 ==
Date:   Sun,   Oct 17 2004 2:07 pm
From: [EMAIL PROTECTED] (Inertia_sublimation) 

Hello everyone. Im developing a program the requires heavy usage of
recursive folder size computation, and need to speed it up immensely.

I thought the use of a cache to store the result of recursively
getting the size of a folder would be ideal, but am having a problem
with it: Its not working.

The size is recomputed every time the sizeRecursive() method is called
on a CachedDirectory.

Also, please forgive the amount of code I'm posting, I think all of it
is pertinant though.
 
Note the comments in DirectoryCache.CachedDirectory.sizeRecursive()'s
for loop, In order to work on the Directorys contained in the
Directory[] as CachedDirectorys, I have to wrap them in a new instance
of CachedDirectory. I don't know how to get around the lastComputed
field of the new CachedDirectory being set to -1 (forcing the new
CachedDirectory to recompute its value instead of looking in the cache
for it).
Please help!

PS - Is there any where I can put a line break in the declaration of a
generic Collection? The lines where I declare them at the top of the
class get kinda long, and they look ugly.

-------------------Class DirectoryCache-------------------
import java.util.*;
import java.io.*;

/**
 * Provides one place where CachedDirectories can be
 * instantiated, that all use the same cache.
 * To instantiate a CachedDirectory from this cache 
 * use this code:
 * DirectoryCache cache = new DirectoryCache();
 * CachedDirectory dir = cache.new CachedDirectory(...);
 */

public class DirectoryCache {
    // The storage facility:
    private static HashMap<Directory, Long> dirSizes = new
HashMap<Directory, Long>();
    
    /**
     * This class subclasses Directory to add caching of the result of
     * calling sizeRecursive().
     */
    public class CachedDirectory extends Directory {
        /** The last time the recusrive size was computed. */
        private long lastComputed = -1;
        
        /** This is provided as an alternative to 
         *  typing DirectoryCache.this */
        private final DirectoryCache cache = DirectoryCache.this;
        
        public CachedDirectory (final String pathName) 
                throws NotADirectoryException {
            super(pathName);
        }
        
        public CachedDirectory(final Directory f) throws IOException {
            super(f);
        }
        
        public long sizeRecursive() throws IOException {
            /* If this CachedDirectory is NOT in the cache, 
             *      or if it was modified: */
            if (!cache.dirSizes.containsKey(this) 
                    || lastModified() > lastComputed) {
                // Debug output:
                if (lastModified() > lastComputed)
                    System.out.println(this.toString() 
                        + " was modified.");
                if (!cache.dirSizes.containsKey(this))
                    System.out.println(this.toString() 
                        + " is not cached.");
                
                // Recompute the recursive size of this directory:
                
                lastComputed = lastModified();
                
                // Get the size of all files in this directory:
                long newSize = size();
                
                // Get all directories in this CachedDirectory:
                Directory[] dirs = listDirectories();

                for (Directory dir : dirs) {
                    /* TODO: Check if there's a better way to do this
                     * that doesn't involve creating a new instance.
                     * since this "fools" the equals() method... 
                     * or does it?
                     * 
                     * After some thought, becasuse its a new instance
                     * of CachedDirectory, its lastComputed variable
                     * is -1, meaning it will always recompute its
                     * size "manually". This is a bad thing, and 
                     * I dont know how to fix it.
                     */
                    dir = new CachedDirectory(dir);
                    newSize += dir.sizeRecursive();
                }
                
                // Cache and return new size:
                cache.dirSizes.put(this, newSize);
                return newSize;
            } else { // This is in the cache and hasn't been modified.
                System.out.println(this.toString() + " is cached.");
                return cache.dirSizes.get(this);
            }
        }
    }
}
-------------------Class Directory-------------------
import java.io.*;
import java.util.*;

/** 
 * This class represents a directory, othewise known as a folder.
 * It provides a method of differentiating between Files and
Directories
 * contained within the folder. Breaking from the java.io.File
"standard",
 * this class provides a method of getting files and folders contained
within
 * a folder seperately.
 */
public class Directory {
    /** Internal representation of this directory. */
    private final File representation;
    
    /** The last time that the files and dirs arrays were refreshed.
*/
    private long lastRefreshed = -1;
    
    /** Contains the files stored in this directory. */
    private File[] files;
    
    /** Contains the directories stored in this directory. */
    private Directory[] dirs;

    public Directory(String pathname) throws NotADirectoryException {
        this(new File(pathname));
    }
    
    public Directory(File f) throws NotADirectoryException {
        if (f.exists() && f.isFile())
            throw new NotADirectoryException(f);
        representation = f;
    }
    
    /**
     * Constructs a new Directory object pointing to the same
     * data on disk.
     * @todo Make constructors call each other (via this()).
     */
    public Directory(Directory dir) {
        /* 
         * TODO: Try to make all constructors call each other.
         * right now, I cant call this(dir.representation)
         * since I need to catch the NotADirectoryException.
         */
        representation = dir.representation;
    }
    
    /**
     * If recursive is false, gets the sum of all the sizes 
     * of the files contained in this Directory.
     */
    public long size() throws IOException {
        //System.out.println("Computing size for " + toString());
        long size = 0;
        File[] files = listFiles();
        //System.out.println("File[] files == " +
Arrays.toString(files));
        for (File file : files) {
            size += file.length();
        }
        return size;
    }
    
    /**
     * This method gets the sum of all the sizes of 
     * the files contained within this Directory, 
     * including those contained within the directories 
     * within this directory. 
     */
    public long sizeRecursive() throws IOException {
        long size = size();
        
        Directory[] directories = listDirectories();
        //System.out.println("Directory[] directories == " +
Arrays.toString(directories));
        for (Directory dir : directories) {
            //System.out.println("Directory currently scanning == " +
dir);
            size += dir.sizeRecursive();
        }
        return size;
    }
    
    /**
     * Repopulates the arrays containing the files and directories
     * contained within this directory.
     */
    private void refreshContentArrays() throws IOException {
        lastRefreshed   = representation.lastModified();
        File[] contents = representation.listFiles();
        
        // contents shouldnt be null unless this directory doesn't
exist.
        if (contents == null) {
            this.dirs = null;
            this.files = null;
            return;
        }
        
        // A directory, at most, has contents.length files/directories
in it.
        List<File>          newFiles = new
ArrayList<File>(contents.length);
        List<Directory>     newDirs  = new
ArrayList<Directory>(contents.length);
        for (File item : contents) {
            // TODO: Why does this need to be here?
            if (item.exists() && !isSymbolicLink(item)) {
                if (item.isFile()) {
                    newFiles.add(item);
                } else { // Item is directory
                    try {
                        newDirs.add(new Directory(item));
                    } catch (NotADirectoryException nade) {
                        nade.printStackTrace();
                    }
                    // NotADirectoryException shouldn't happen.
                }
            }
        }
        // Store new data in the fields:
        this.dirs  = new Directory[newDirs.size()];
        this.files = new File[newFiles.size()];
        newDirs.toArray(dirs);
        newFiles.toArray(files);
    }
    
    /** 
     * Lists all the directories contained within this directory.
     * Note: This doesn't recurse into the directories.
     * The special .. (parent) and . (this) directories are excluded.
     * Returns null if this directory does not exist.
     * @todo Move content array validity check to setLastModified().
     */
    public Directory[] listDirectories() throws IOException {
        // Make sure contents arrays are up-to-date.
        // TODO: Check if I can just override setLastModified() to do
this.
        long lastModified = representation.lastModified();
        if (lastModified > lastRefreshed) {
            refreshContentArrays();
        }
        
        Directory[] ret = null;
        if (dirs != null) {
            // Cant pass a refrence to the field, since
            // its not immutable (can I use an UnmodifiableSet?)
            ret = new Directory[dirs.length];
            System.arraycopy(dirs, 0, ret, 0, dirs.length);
        }
        return ret;
    }
    
    /**
     * Returns all the files contained within this directory.
     * Contrary to java.io.File's listFiles() method, this returns
     * only the *files* in this directory, not the directories.
     */
    public File[] listFiles() throws IOException {
        // Make sure contents arrays are up-to-date.
        // TODO: Check if I can just override setLastModified() to do
this.
        long lastModified = representation.lastModified();
        if (lastModified > lastRefreshed) {
            refreshContentArrays();
        }
        
        File[] ret = null;
        if (files != null) {
            // Cant pass a refrence to the field, since
            // its not immutable (can I use an UnmodifiableList?)
            ret = new File[files.length];
            System.arraycopy(files, 0, ret, 0, files.length);
        }
        return ret;
    }
    
    private static boolean isSymbolicLink(File f) throws IOException {
        return !f.getAbsolutePath().equals(f.getCanonicalPath());
    }
    
    /** 
     * @see java.io.File#lastModified()
     */
    public long lastModified() {
        return representation.lastModified();
    }
    
    /**
     * @see java.io.File#exists()
     */
    public boolean exists() {
        return representation.exists();
    }
    
    /**
     * @see java.io.File#mkdir()
     */
    public boolean mkdir() {
        return representation.mkdir();
    }
    
    /**
     * @see java.io.File#delete()
     */
    public boolean delete() {
        return representation.delete();
    }
    
    /**
     * @see java.io.File#toString()
     */
    public String toString() {
        return representation.toString();
    }
    
    /**
     * @see java.io.File#hashCode()
     */
    public int hashCode() {
        return representation.hashCode();
    }
    
    /**
     * @see java.io.File#equals(Object)
     */
    public boolean equals(Object o) {
        return representation.equals(o);
    }
    
    public int compareTo(Directory pathname) {
        return representation.compareTo(pathname.representation);
    }
    
    /**
     * @see java.io.File#getCanonicalPath()
     */
    public String getCanonicalPath() throws IOException {
        return representation.getCanonicalPath();
    }
    
    /**
     * @see java.io.File#getPath()
     */
    public String getPath() {
        return representation.getPath();
    }
}
-------------------Class NotADirectoryException-------------------
import java.io.File;

/**
 * This exception is thrown when a Directory is constructed
 * via a File that already exists as a file on the storage media.
 * @todo See if this should instead subclass RuntimeException.
 */
public class NotADirectoryException extends Exception {
    private final File file;
    public NotADirectoryException(File file) {
        this.file = file;
    }
    
    public NotADirectoryException(String filePath) {
        this(new File(filePath));
    }
    
    public String getMessage() {
        return file.toString() + " is not a directory.";
    }
}



=======================================================================

You received this message because you are subscribed to the
Google Groups "comp.lang.java.programmer".  

comp.lang.java.programmer
[EMAIL PROTECTED]

Change your subscription type & other preferences:
* click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe

Report abuse:
* send email explaining the problem to [EMAIL PROTECTED]

Unsubscribe:
* click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe


=======================================================================
Google Groups: http://groups-beta.google.com 

Reply via email to