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

Today's topics:

* PLEASE HELP!!! String conversion problem with BigInteger class - 1 messages,
1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5edb9effc512c707
* Ejb: best way to implement an update method with BMP - 2 messages, 2 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2fadf7c755facb41
* Correct Semaphore Implementation in Java - 3 messages, 2 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8259aec1ceed4f8f
* ByteBuffer and arrays - 2 messages, 2 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/670f596e0e700bac
* <jsp:param> Problem - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9718021160ca6f6b
* Web Search Engine - 2 messages, 2 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9d8197f0a3a6d7b9
* [REPOST] java.awt.Image problem - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7f984034b7d7f294
* Java and C# Dll ... - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9865ceaba8831282
* Abstract class problem - 2 messages, 2 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/257e0a9eda9e65da
* where to find the *.jar files which SOAP needs? - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/89831c27a3a193ee
* Reproducing du/ls in Java - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3b6930f360088c78
* please recommend a design pattern book in java - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/99dfc42b6357856
* Comparing two strings - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/64fe8d36ff4a5ff1
* Struts Newbie - problems with Action Forwards - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/337c322e6607f24c
* Best way to do this - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8e38d69ac964c0ee
* adding jars to classpath on runtime without -cp option - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e98c253d97fad483
* Best Practices for running J2EE applications on machine with 192 CPUs? - 1 
messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/670df86c61aad2c5
* Advanced question about generics - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/70947db3058ccce1
* java web start can run console app? - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a49fe32937c92583

==============================================================================
TOPIC: PLEASE HELP!!! String conversion problem with BigInteger class
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5edb9effc512c707
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 10:41 am
From: Michael Borgwardt 
 

Gandu wrote:
> The print statement prints a starnge looking String. However, if I use
> BigInteger bigInt = new BigInteger("1234567890"); 
> instead of BigInteger bigInt = new BigInteger(byteArray); in above,
> the
> output is 1234567890

It shouldn't. Either the code you've posted isn't the one you're
running or it's not that code that does the printing. Or something
is seriously wrong with your RSA code.

http://www.physci.org/codes/sscce.jsp

> Could someone please point out what I am doing wrong?

The code ypu've posted looks right.




==============================================================================
TOPIC: Ejb: best way to implement an update method with BMP
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2fadf7c755facb41
==============================================================================

== 1 of 2 ==
Date: Mon, Nov 29 2004 10:24 am
From: Andrea Desole  

I see. On the other side, I might want to call my setter without 
changing the database. For example, if I call setA without setB, I might 
leave the database in an inconsistent state. Not to mention the 
performance, of course.
There would be no point otherwise in having the possibility to configure 
the transaction type for every method

Sudsy wrote:
> Andrea Desole wrote:
> <snip>
> 
>> I looked at it, but that should happen usually if the method has a 
>> transaction associated. At least, that's what I understand from the 
>> J2EE 1.4 tutorial, (page 936), and from the book "Enterprise 
>> Javabeans", pages 250-251. From this documentation, and from the 
>> specification, I also understand that the container can call these 
>> methods whenever it is considered necessary.
>> Not every method has to have a transaction. So, if I configure my 
>> transaction properly in the ejb-jar file, there should be no need to 
>> call ejbStore from my setters, and it will be called only in update.
>> Right?
> 
> 
>  From the book I mentioned earlier:
> "All business methods, even if they only perform a data lookup, /must/
> execute within a transaction in order for the EJB container to ensure
> data integrity between the in-memory entity bean and the database."
> (pp. 212, emphasis mine)
> 



== 2 of 2 ==
Date: Mon, Nov 29 2004 6:57 am
From: Sudsy  

Andrea Desole wrote:
> I see. On the other side, I might want to call my setter without 
> changing the database. For example, if I call setA without setB, I might 
> leave the database in an inconsistent state. Not to mention the 
> performance, of course.
> There would be no point otherwise in having the possibility to configure 
> the transaction type for every method
<snip>

Not to be condescending, but you /really/ should do some more reading on
some of the basic concepts, particularly transactions. If you specify a
transaction-type of Required then a new transaction is started only if
the client isn't ALREADY in a transaction.
The usual way of doing things is to incorporate the business login in a
stateless session bean which has methods specified with a transaction-type
of Required. The entity EJBs can then utilize the same transaction as the
SLSB. If any of the updates fail then the entire transaction is rolled-
back, satisfying ACID requirements.
You had to figure that the J2EE architects would have addressed these
kinds of issues, right?

-- 
Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.





==============================================================================
TOPIC: Correct Semaphore Implementation in Java
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8259aec1ceed4f8f
==============================================================================

== 1 of 3 ==
Date: Mon, Nov 29 2004 11:13 am
From: Andrea Desole  


> 
> Well ....  But semaphores are a rather general synchronization
> mechanism that can be used for things other than "acquire a resource
> / release the resource."  An example is a producer/consumer setup,
> where you have one thread "producing" things and putting them in a
> shared buffer, and another thread "consuming" them.  A reasonable way
> to make the consumer wait if there is nothing to consume is by using
> a semaphore, with the producer doing "V" operations and the consumer
> doing "P" operations.

I think in general you are right. Still, often semaphores are intended 
as resource control mechanism (see for example 
http://mindprod.com/jgloss/semaphore.html ). In this case you shouldn't 
theoretically check, because the clients of the semaphore are 
"perfectly" calling P and V an even number of times, but practically it 
  would be better. And I don't think there are different constructs for 
these two different situations. And I would be glad to know if there are.



== 2 of 3 ==
Date: Mon, Nov 29 2004 10:59 am
From: Andrea Desole  

Well, I would say it's a very good point, and a good opportunity for me 
to rethink about multithreading issues.
Thank you for the remark.


xarax wrote:
> "Andrea Desole" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> 
>>>The problem is not related to spurious wake-ups. The code
>>>in the procure method P() was broken, because it only used
>>>"if(count==0)" rather than "while(count==0)". The code poster
>>>asserted a fallacy about the efficacy of the implementation,
>>>that it was impossible to return from the "wait()" without
>>>being immediately able to take ownership of the semaphore.
>>>
>>>The while loop is required not due to spurious wake-ups,
>>>but rather due to the fact that "wait()" releases the monitor
>>>and then tries to re-acquire the monitor before returning to
>>>the code that called wait(). A timing issue arises when two
>>>or more threads concurrently attempting P() which will cause
>>>the broken code to proceed with two threads holding the
>>>semaphore. The while loop fixes that bug.
>>>
>>
>>the code is synchronized, I don't see any problem with more threads
>>accessing P, except the lack of a FIFO queue. Can you be clearer? I'm
>>not sure I get this.
> 
> 
> The code is not always synchronized, because wait() releases
> the monitor. When notify() is called, the target thread becomes
> dispatchable and it must compete with other threads to re-acquire
> the monitor before returning from wait(). There may be another
> thread already suspended at the outer synchronized block that
> will get the monitor *after* the V() method exits and *before*
> the wait() returns.
> 
> IIRC, the original posted Semaphore class is something
> like this (please advise if there is any substantive
> difference between this and the original code):
> =====================================
> public class Semaphore
> {
>     private int count = 1;
> 
>     public void procure()
>     throws InterruptedException
>     {
>         synchronized(this)
>         {
>             if(count == 0) /* Should be while(count==0) */
>             {
>                 /* releases the monitor, then re-acquires later */
>                 wait();
>             }
>             count--;
>         }
>     }
> 
>     public void vacate()
>     {
>         synchronized(this)
>         {
>             if(count == 0)
>             {
>                 notify();
>             }
>             count++;
>         }
>     }
> }
> =====================================
> 
> The design starts the semaphore.count field
> at 1, which means that the semaphore is available.
> Acquiring the semaphore changes the count to 0.
> Releasing the semaphore changes the count to 1.
> 
> btw: I factored out the InterruptedException to
> get rid of the recovery path. It's not relevant
> to this discussion.
> 
> Now assume there are 3 threads, A, B, and C. Thread
> A calls procure(), and the other threads are doing
> something else so there is no contention for the
> semaphore.
> 
> Thread A has acquired the semaphore and returned
> from procure(). Now thread B calls procure(), which
> acquires the monitor, checks for if(count==0) and sees
> that another thread has already acquired the semaphore.
> So, thread B calls wait(), which releases the monitor.
> 
> Now thread A calls vacate(), which acquires the
> monitor. Then thread C calls procure(), which attempts
> to acquire the monitor, but is blocked because thread
> A already has the monitor. Meanwhile, thread B is still
> waiting inside wait().
> 
> Thread A calls notify() which awakens thread B. Thread
> B now attempts to re-acquire the monitor. Thread C is
> still trying to acquire the monitor. Both thread B
> and thread C are now competing for the monitor.
> 
> When thread A exits the vacate() method, the monitor
> is released and it is unpredictable whether thread B
> or thread C will acquire the monitor. If thread B
> acquires the monitor, then all is well. However, if
> thread C acquires the monitor, then it will see that
> (count != 0) and it will proceed to change "count"
> to 0, so that it will own the semaphore.
> 
> When thread C exits procure(), the monitor is released
> and now thread B can acquire the monitor and return
> from wait(). Since procure() does not loop back to
> re-test the value of count (which is 0), thread B will
> proceed to assume that it has acquired the semaphore
> (thread C actually has acquired the semaphore). Thus,
> both thread B and C will return from procure(), with
> each thread believing that it has acquired the semaphore.
> 
> Both threads, believing they each have acquired the
> mutex semaphore, will now enter their critical sections
> and clobber each other.
> 
> In actual practice, the semaphore paradigm is much
> more complicated, and is properly synchronized to avoid
> the race condition described above. The above sample
> Semaphore class is woefully broken to handle either
> exclusive or shared semaphores.
> 
> Hope this helps.
> 



== 3 of 3 ==
Date: Mon, Nov 29 2004 7:21 am
From: "Matt Humphrey"  


<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> In article <[EMAIL PROTECTED]>,
> Andrea Desole  <[EMAIL PROTECTED]> wrote:
> >
> >>
> >> Well ....  But semaphores are a rather general synchronization
> >> mechanism that can be used for things other than "acquire a resource
> >> / release the resource."  An example is a producer/consumer setup,
> >> where you have one thread "producing" things and putting them in a
> >> shared buffer, and another thread "consuming" them.  A reasonable way
> >> to make the consumer wait if there is nothing to consume is by using
> >> a semaphore, with the producer doing "V" operations and the consumer
> >> doing "P" operations.
> >
> >I think in general you are right. Still, often semaphores are intended
> >as resource control mechanism (see for example
> >http://mindprod.com/jgloss/semaphore.html ).
>
> Usually I find Roedy's stuff clear and helpful.  The above-mentioned
> page is an exception -- "setting" semaphores seems imprecise (does
> he mean performing a V/up operation?), and I'm skeptical about the
> claim that semaphores are a generalization of monitors -- I'd have
> said it was more the other way around.  But a quick Google search
> isn't finding anything I like much better ....

An exercise we had to perform many years ago was to implement monitors using
semaphores and semaphores using monitors.  They are equally powerful
although they are each better suited to particular kinds of problems.

Cheers,
Matt Humphrey  [EMAIL PROTECTED]   http://www.iviz.com/






==============================================================================
TOPIC: ByteBuffer and arrays
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/670f596e0e700bac
==============================================================================

== 1 of 2 ==
Date: Mon, Nov 29 2004 10:47 am
From: Michael Borgwardt 
 

Jesper Sahner wrote:
> Let's say that you wan't to

Misusing apostrophes like that makes Baby Jesus cry!

> read a sequence of e.g. integers a, b, c,
> d and e. An array x[5] can be read directly using an IntBuffer or
> using ByteBuffer.asIntBuffer().
> 
> Is it possible to read a, b, c, d and e the same way, meaning in one
> read?

You mean putting the values into four separate variables?

> If NOT you'll have to:
> 1) read a, b, c, d and e one by one
> or:
> 2) read into an array x[5] and then put a=x[0],...,e=x[4]
> 
> Neither of these methods are elegant or (even worse) fast ways to read
> data.

Well, having five variables named a, b, c, d and e isn't an elegant way
to *represent* data. And your speed worries are totally unfounded.
Even if the language or API had syntactic sugar to do what you want,
it would end up doing one of these things.



== 2 of 2 ==
Date: Mon, Nov 29 2004 1:36 am
From: [EMAIL PROTECTED] (Jesper Sahner) 

Hi!

Using the Buffer-classes in Java NIO you can read blocks/arrays of
data by using allocate() or wrap() on an existing array. Further you
can use a view-buffer to read integers, doubles etc. into a ByteBuffer
as if it was integers, doubles etc. you were reading.

So far so good.

Let's say that you wan't to read a sequence of e.g. integers a, b, c,
d and e. An array x[5] can be read directly using an IntBuffer or
using ByteBuffer.asIntBuffer().

Is it possible to read a, b, c, d and e the same way, meaning in one
read?

If NOT you'll have to:
1) read a, b, c, d and e one by one
or:
2) read into an array x[5] and then put a=x[0],...,e=x[4]

Neither of these methods are elegant or (even worse) fast ways to read
data.

Any suggestions for improvements?

Regards,
Jesper




==============================================================================
TOPIC: <jsp:param> Problem
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9718021160ca6f6b
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 5:40 am
From: Trent L  

Heiner Kücker wrote:
> Trent wrote
> 
>>Hello,
>>
>>I am trying to use the <jsp:include> and <jsp:param> actions.  For
>>whatever reason, I am having zero luck getting the param to be
>>recognized in the included file.  I have two files: index.jsp and
>>header.jsp:
>>
>>+++++ index.jsp +++++
>><html>
>><body>
>><jsp:include page="header.jsp">
>>    <jsp:param name="subTitle" value="test 1 2 3"/>
>></jsp:include>
>>This is in index.jsp
>></body>
>></html>
>>
>>+++++ header.jsp +++++
>>Value: ${param.subTitle} <br />
>>
>>
>>++++++ Output +++++++
>>Value: ${param.subTitle}
>>This is in index.jsp
>>
>>
>>Why is my parameter not getting recognized?  This is driving me crazy.
>> Any help appreciated.
> 
> 
> Supports your JSP/Servlet Container the specification JSP 2.0 ?
> 
> Try
> 
> +++++ header.jsp +++++
> <%= "" + request.getAttribute( "subTitle" ) %>
> or
> <%= "" + request.getParameter( "subTitle" ) %>
> 
> Good luck
> 


Thanks, that worked.  I'll have to double-check 
which JSP spec my container is using.  I'm running 
on JRun 4.




==============================================================================
TOPIC: Web Search Engine
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9d8197f0a3a6d7b9
==============================================================================

== 1 of 2 ==
Date: Mon, Nov 29 2004 11:57 am
From: "Heiner Kücker"  

Harindu00 wrote
> I am developing a web search engine. Which technology should i use
> JSP Or Servlets If any body has a tip please tell me

You will need an client technologie like apache http client for scanning web 
sites.

For user client is JSP an good choice.

-- 
Heiner Kuecker
Internet: http://www.heiner-kuecker.de
JSP WorkFlow PageFlow FlowControl Navigation: http://www.control-and-command.de
Expression Parser: http://www.heinerkuecker.de/Expression.html





== 2 of 2 ==
Date: Mon, Nov 29 2004 2:03 am
From: [EMAIL PROTECTED] (Harindu007) 

I am developing a web search engine. Which technology should i use 
JSP Or Servlets If any body has a tip please tell me




==============================================================================
TOPIC: [REPOST] java.awt.Image problem
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7f984034b7d7f294
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 12:08 pm
From: "MaSTeR"  

The problem is quite straighforward:
I am double buffering an image which represents an horizontal table, as you
might expect this could get really wide. If the table changes (row deleted
or added) I redraw the buffer otherwise I only draw the image that's in the
buffer.

I do my development in J# using visual studio 2003 because I like the IDE
and the debugger is just the best. Then (since I'm not using .Net api) I
just recompile my code with the SUN sdk. So far so good. The problem is that
the image is drawn perfectly using the microsoft VM but when I run it with
SUN's the image is created correctly (on row deletion, insertion) but when
just redrawing the buffer it gets screwed up.

Here's an example : http://217.158.134.37/MobileJava/ticker.jpg
At the top the right one.

Ah the 'thing' is sitting inside a class deriving from Java.awt.Panel and I
just use awt. It works fine if I use it inside an applet in a browser that
run microsoft VM 1.1. It goes funny anyway with sun VM ( 1.4.2 ).

Thanks for any help.






==============================================================================
TOPIC: Java and C# Dll ...
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9865ceaba8831282
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 12:02 pm
From: "MaSTeR"  

"Piccolo Max" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Hello everybody,
> I have developer a .dll (.net assembly) that contain 2 Class.
>
> I want to know If I can load this dll from Java and use the 2 Class.
> Can i do it ?
>
> max;
>
You can easily do it. Create a COM typed library for your assembly, then use
the COM object from Java.






==============================================================================
TOPIC: Abstract class problem
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/257e0a9eda9e65da
==============================================================================

== 1 of 2 ==
Date: Mon, Nov 29 2004 12:22 pm
From: "Heiner Kücker"  

Neil wrote
> I am having trouble with abstract classes.
>
> I want an abstract class DataWrapper that has a method generateHtml()
>
> I want to be able to have specific classes that extend DataWrapper so
> that I can store data specific to each one but is responsible for
> generating its own html eg Company extends DataWrapper.
>
> Then in my code I want to be able to have different classes that can
> be treated as DataWrappers so I can just call the generateHtml method
> and let them handle there own thing.
>
> Basically I have written code to generate a tree structure of nodes
> and also some code to turn it into a html tree, with dhtml to do the
> expand etc.
>
> I need each node to generate its own HTML so I can store different
> information on each line of the tree without having to rewrite the
> HTML tree generation bit.
>
> However I cant seem to use the DataWrapper object as I thought.
>
> eg:
>
> DataWrapper obj = root.getData();
> html.append("<div style='background:#b0c4de'><img align='absmiddle'
> src='" + settings.closedRoot + "' id='rc" + idCounter++ + "'>");
> //* We use the wrapper object to generate its own information
> //* line so that this can be overidden and changed on a per
> application basis
> html.append(obj.generateHtml());
>
> I have tried all sorts of casting and variations of declaring a
> DataWrapper but instatiating a Company class etc and cant seem to get
> anything to work.
>
> Any help would be much appreciated!
>
> Cheers,
>
> Neil.

You must call the obj.generateHtml() method recursiv.

In node class:

public String generateHtml()
{
    StringBuffer strBuff = new StringBufer();
    for ( int i = 0 ; i < nodeList.size() ; i++ )
    {
        // recursiv call
        strBuff.append( ( (DataWrapper) nodeList.get( i )  ).generateHtml() );
    }
    return strBuff.toString();
}

In leaf class:

public String generateHtml()
{
    StringBuffer strBuff = new StringBuffer();
    strBuff.append( "<html...
    ...
    return strBuff.toString();
}

Heiner Kuecker
Internet: http://www.heiner-kuecker.de
JSP WorkFlow PageFlow FlowControl Navigation: http://www.control-and-command.de
Expression Parser: http://www.heinerkuecker.de/Expression.html





== 2 of 2 ==
Date: Mon, Nov 29 2004 3:07 am
From: [EMAIL PROTECTED] (Neil) 

I am having trouble with abstract classes.

I want an abstract class DataWrapper that has a method generateHtml()

I want to be able to have specific classes that extend DataWrapper so
that I can store data specific to each one but is responsible for
generating its own html eg Company extends DataWrapper.

Then in my code I want to be able to have different classes that can
be treated as DataWrappers so I can just call the generateHtml method
and let them handle there own thing.

Basically I have written code to generate a tree structure of nodes
and also some code to turn it into a html tree, with dhtml to do the
expand etc.

I need each node to generate its own HTML so I can store different
information on each line of the tree without having to rewrite the
HTML tree generation bit.

However I cant seem to use the DataWrapper object as I thought.

eg:

DataWrapper obj = root.getData();
html.append("<div style='background:#b0c4de'><img align='absmiddle'
src='" + settings.closedRoot + "' id='rc" + idCounter++ + "'>");
//* We use the wrapper object to generate its own information
//* line so that this can be overidden and changed on a per
application basis
html.append(obj.generateHtml());

I have tried all sorts of casting and variations of declaring a
DataWrapper but instatiating a Company class etc and cant seem to get
anything to work.

Any help would be much appreciated!

Cheers,

Neil.




==============================================================================
TOPIC: where to find the *.jar files which SOAP needs?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/89831c27a3a193ee
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 1:45 am
From: [EMAIL PROTECTED] (mike) 

regards:


where to find the *.jar files which SOAP needs?

activation.jar
bsf.jar
jaxp.jar
js.jar
mail.jar
servlet.jar
soap.jar


Thank you.
May god be with you.




==============================================================================
TOPIC: Reproducing du/ls in Java
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3b6930f360088c78
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 1:43 am
From: [EMAIL PROTECTED] (Oreo) 

Hi there,

I am writing an application that needs to compute the exact size of a
file. I need for this function to work in Windows and UNIX.

One of my issues is that the length() method provided by the File
class does not return the exact size for all files.

The essence of my problem is that I cannot properly compute the size
of a directory or symbolic links in UNIX properly.

File.class() returns 0 for the size of directories regardless of OS.
This appears to be correct on Windows (right-click -> properties on an
empty directory in Windows). However this seems to be incorrect
according to Linux.

When compared to the output of ls, the File.length() method will not
return the proper length of directories (whether on a FAT or reiserfs
file system) or a symbolic link in UNIX. The length of a UNIX
directory is not zero, and the size of symbolic link is the length of
the filename that it points to.

When the windows partition is mounted in Linux, the size of the
directories on the windows partition are reported as being 4096 by
file system utilities ls and du. This contrasts the value of zero
reported by the Microsoft 98 Windows Explorer.

Detailed examples of my problem can be found at the following thread:
http://forum.java.sun.com/thread.jspa?threadID=574755

How can I compute a function that will be able to compute the size of
any file under any operating system?

I would like to avoid his path:
    1. Determine if the class is being run in Windows or UNIX
    2. If running in UNIX, 
           a. If a directory of symbolic link: execute : du -sb [file]
| awk '{print $1}'
              or ls -al [file ] | awk ' { print  $5 }'
           b. Otherwise: File.length()
    3. If running Windows, simply class File.length() (?)


By taking this route I need to perform an if() statement every time
the size of any file is being computed, and also execute an expensive
command for some special cases (when the file is a directory of link).
The expensive commands will be common, and I would like to avoid
having to do that.

- Oreo




==============================================================================
TOPIC: please recommend a design pattern book in java
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/99dfc42b6357856
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 8:21 pm
From: metfan  

I searched Amazon and it came out a list, could you please recommend one, which 
one is of the best for a mid-level programmer? Thanks.

1) Design Patterns Java Workbook by Steven John Metsker
2) Applied Java Patterns by Stephen A. Stelting
3) Java Design Patterns: A Tutorial by James William Cooper
4) Patterns in Java: A Catalog of Reusable Design Patterns Illustrated with 
UML, 2nd Edition, Volume 1 by Mark Grand
5) Java Design: Objects, UML, and Process by Kirk Knoernschild
6) Object-Oriented Software Engineering: Using UML, Patterns and Java, Second 
Edition by Bernd Bruegge
7) Software Architecture Design Patterns in Java by Partha Kuchana




==============================================================================
TOPIC: Comparing two strings
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/64fe8d36ff4a5ff1
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 12:46 pm
From: "MaSTeR"  

> public class T {
>     public static void main(String args[])
>     {
> String s1 = "we are students";
> String s2 = "are";
> int startIndex = s1.indexOf(s2);
> if (startIndex > 0) {
>     System.out.println("Found substring at: " + startIndex);
> }
> else {
>     System.out.println("Found no match");
> }
>     }
> }
>

Actually
 if (startIndex != -1) {
     System.out.println("Found substring at: " + startIndex);
 }
 else {
     System.out.println("Found no match");
 }
     }
 }

Otherwise wouldn't find a match for
 String s1 = "we are students";
 String s2 = "we";






==============================================================================
TOPIC: Struts Newbie - problems with Action Forwards
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/337c322e6607f24c
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 7:08 am
From: [EMAIL PROTECTED] (Spivee) 

Thanks Martin, that was exactly the problem.  I changed the perform
method to execute and that fixed the problem completely!



Martin Froment wrote:
 The perform method is deprecated and no more available in the
ActionServlet
 controller of Struts 1.2.4 (not 1.4.2).
 
 You must override the Action execute method in your SubmitAction
class,
 otherwise the superclass' execute method is called and it's returning
a null




==============================================================================
TOPIC: Best way to do this
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8e38d69ac964c0ee
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 6:55 am
From: [EMAIL PROTECTED] (Fran Garcia) 

I send you some code:

This is the code for the creation of the class to playing the wav
file.

public SimpleAudioPlay(String fileName,int tamano)
        {
                m_tamanoBuffer=tamano;
                m_nombreFich=fileName;
                m_ficheroWav=new File(m_nombreFich);
                try {
                  m_flujoEntradaAudio =
AudioSystem.getAudioInputStream(
                      m_ficheroWav);
                }
                catch (IOException ex) {
                      System.err.println("ERROR : "+ex.getMessage());
                }
                catch (UnsupportedAudioFileException e) {
                      System.err.println("ERROR : "+e.getMessage());
                }
                try {
                  m_formatoAudio = m_flujoEntradaAudio.getFormat();
                  DataLine.Info info = new
DataLine.Info(SourceDataLine.class,m_formatoAudio);
                  m_line = (SourceDataLine) AudioSystem.getLine(info);
                }
                catch (LineUnavailableException ex1) {
                    System.err.println("ERROR : "+ex1.getMessage());
                }
                try {
                  m_line.open(m_formatoAudio);
                }
                catch (LineUnavailableException ex2) {
                       System.err.println("ERROR :
"+ex2.getMessage());
                }
                catch (Exception ex) {
                  System.err.println("ERROR : "+ex.getMessage());
                }

        }

And then I must do m_line.start() in the root class. Do you understand
me?

I hope that you can help me!


Chris Smith <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Fran Garcia <[EMAIL PROTECTED]> wrote:
> > I=3Fm developping an applet that plays a wav file and now I wanna add a
> > slider to showing the position for the wav file, but I have no idea to
> > do it. How can I communicate the read for the wav file and the slider.
> > Listener, Timer or what?
> 
> Are you using the java.applet.AudioClip interface, or 
> javax.sound.sampled.*?  If the former, you're not on solid ground trying 
> to stretch the functionality this far.  You could probably kludge 
> something together using a custom URLStreamHandler for your URL and 
> wrapping the resulting InputStream to count the progress and report 
> it... but that would be fairly ugly (also, I'm unsure if common browsers 
> grant NetPermission("specifyStreamHandler"), which would be needed).
> 
> If you're using javax.sound.sampled.* then this is easier.  Post some 
> code to play the sound, and I can help you get the progress meter going.




==============================================================================
TOPIC: adding jars to classpath on runtime without -cp option
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e98c253d97fad483
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 6:51 am
From: "Ferenc Hechler"  

Hi Rony,

thats exactly what the Class "ClassPathHacker" is doing,
Perhaps you should look at the thread 
http://forum.java.sun.com/thread.jspa?threadID=300557&start=0&tstart=0 
again.
There are two solutions mentioned.
One using reflections to access the protected method  addURL of ClassLoader
and the other changing the Thread-Context ClassLoader using 
Thread.currentThread().setContextClassLoader .

bye,

   feri


"rony" <[EMAIL PROTECTED]> schrieb im Newsbeitrag 
news:[EMAIL PROTECTED]
> "Ferenc Hechler" <[EMAIL PROTECTED]> wrote in message 
> news:<[EMAIL PROTECTED]>...
>> You can use URLClassLoader to do the class-loading.
>> Take a look at the following thread:
>> http://forum.java.sun.com/thread.jspa?threadID=300557&start=15&tstart=0
>>
>> bye, feri
>
> Hi,
>
> The problem is that I don't know the name of the class that is going
> to be used. I just know that jar where it is located. I want the VM to
> look there.
>
> Thanks,
> Rony 






==============================================================================
TOPIC: Best Practices for running J2EE applications on machine with 192 CPUs?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/670df86c61aad2c5
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 5:11 am
From: [EMAIL PROTECTED] (Cindi Jenkins) 

I have seen others comment on writing applications that run on two or
four CPU machines but wanted to know if anyone has uncovered "best
practices" for developing Java applications that support 192 CPUs?




==============================================================================
TOPIC: Advanced question about generics
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/70947db3058ccce1
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 6:12 am
From: Michal Kleczek  

Jesper Nordenberg wrote:
> Michal Kleczek <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
> PROTECTED]>...
> 
>>Jesper Nordenberg wrote:
>>
>>>"Vincent Cantin" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL 
>>>PROTECTED]>...
>>>
>>>
>>>>Hello,
>>>>
>>>>I have a class Server<C extends Connection> that accepts some connections 
>>>>are for each of them creates an instance of C.
>>>>
>>>>Problem : the implementation of the class need to have C.class in order to 
>>>>create its instance but it doesn't know it unless I ask the user of my 
>>>>class 
>>>>to give it in parameter.
>>>>
>>>>So the user of the class write something like that :
>>>>
>>>>   Server server = new Server<MyConnection>(MyConnection.class);
>>>>
>>>>but I would like him to only write something like that :
>>>>
>>>>   Server server = new Server<MyConnection>();
>>>>
>>>>Is there something in the language of Java 1.5 that can do implicitly what 
>>>>I 
>>>>want ?
>>>
>>>
>>>No, not possible because of type erasure. A flexible solution is to
>>>pass a factory object that create the instances, for example:
>>>
>>>Server server = new Server<MyConnection>(new Factory<MyConnection>() {
>>>  public MyConnection create() {
>>>    return new MyConnection();
>>>  }
>>>});
>>>
>>>public interface Factory<T> {
>>>  T create();
>>>}
>>>
>>>This has several advantages over directly calling a constructor using
>>>reflection.
>>>
>>>/Jesper Nordenberg
>>
>>Hi,
>>actually it is the same as the original solution - but more verbose.
> 
> 
> No, it's not the same. The Factory solution is more flexible because
> it allows you to use any constructor of the MyConnection class, or
> even not to create a new object at all. For example:
> 
> final MyConnection connection = getConnection();
> 
> Server server = new Server<MyConnection>(new Factory<MyConnection>() {
>   public MyConnection create() {
>     return connection;
>   }
> });
> 
> 
> Server server2 = new Server<MyConnection>(new Factory<MyConnection>()
> {
>   public MyConnection create() {
>     return new MyConnection("This is an argument!");
>   }
> });
> 
> This is something you can't do by just passing the MyConnection.class
> object.
> 
> /Jesper Nordenberg
Hi,
I agree with you it's more flexible, but has nothing to do with generics.
Michal




==============================================================================
TOPIC: java web start can run console app?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a49fe32937c92583
==============================================================================

== 1 of 1 ==
Date: Mon, Nov 29 2004 7:16 am
From: [EMAIL PROTECTED] (Matt) 

java web start can only runs swing/awt applications? but not console
applications? I put console application as java web start application,
and it doesn't work and no error at all.

Please advise. thanks!!



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

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

To post to this group, send email to [EMAIL PROTECTED] or
visit http://groups-beta.google.com/group/comp.lang.java.programmer

To unsubscribe from this group, send email to
[EMAIL PROTECTED]

To change the way you get mail from this group, visit:
http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe

To report abuse, send email explaining the problem to [EMAIL PROTECTED]

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

Reply via email to