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

Today's topics:

* UTF 16 (byte[]) <--> String? - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9199d3b6e927cb81
* java splash window - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a18982f4ea35d6ef
* how to set center alignment in JTable? - 2 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/77b50aaa835963b
* Struts: best practice working with disabled fields - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/799880f4b973219
* &#35201;&#22914;&#20309;&#29992;java&#25235;word&#27284;&#30340;property - 6 
messages, 5 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/dc6b5097ce89d2d4
* abstract constructor performance? - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/beb77902ee7c05c7
* Would like a preprocessor. - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f8d589c27ece424e
* What is a monitor ? - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/69bebcbefe17ef56
* File.lastModified *extremely* slow ? - 2 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c70759a9620dbe78
* byte manipulation in Java ? - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a6813ab049aef0b6
* Different compilers = Different byte code? - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d6730b906587dde
* file image uploaded to a webserver appears garbled after upload. - 1 messages, 1 
author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ef06b42d62b446df
* JUnit Testing with JavaServer Faces - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7eba10c6dd2185d3
* Detecting double click with MouseListener - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7acf887f3c6b02cd
* Who can resist a compilable example? - JComboBox - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a964462dca846012
  
==========================================================================
TOPIC: UTF 16 (byte[]) <--> String?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9199d3b6e927cb81
==========================================================================

== 1 of 2 ==
Date:   Tues,   Aug 31 2004 11:42 pm
From: "Ong Hong Peow" <[EMAIL PROTECTED]> 

Thanks Mike.

where do one find those available "charsetName" in getBytes(String
charsetName) ?

Thanks again ;-)

"Mike Schilling" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> "Ong Hong Peow" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Hi,
> >
> > is there a convenient way to convert unicode that's stored in byte array
> to
> > java String?
> > and vice-versa?
> >
> > e.g. for a single single unicode,
> > the higher byte would be in byte[0],
> > lower byte[1]
> > and byte[2], byte[3] = 0. null terminated
> >
> > the byte array of unicode is generated from a C program and transfered
> over
> > the network ..
> >
> > looking over the String API doesn't reveal much ... or am I overlooking
> > something?
> >
> > Thanks in advance.
> >
>
> String -> bytes:     string.getBytes("UTF-16BE")
> bytes -> String:     new String(bytes, 0, len, "UTF-16BE")
>
> You'd have to write code to find the length of the byte array (i.e. to
> search for the null terminator.)
>
>





== 2 of 2 ==
Date:   Wed,   Sep 1 2004 5:04 am
From: Thomas Fritsch <[EMAIL PROTECTED]> 

Ong Hong Peow wrote:

>...
>
>where do one find those available "charsetName" in getBytes(String
>charsetName) ?
>
>...
>  
>
See http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html
There you find the short list of standard charsets (the minimum set to 
be supported by any Java platform).
The complete list of available charsets can be got by calling   
Charset.availableCharsets()

-- 
Thomas<dot>Fritsch<squiggle>ops<dot>de





==========================================================================
TOPIC: java splash window
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a18982f4ea35d6ef
==========================================================================

== 1 of 1 ==
Date:   Wed,   Sep 1 2004 12:00 am
From: Jacob <[EMAIL PROTECTED]> 

Roy Ratcliffe wrote:

>> can anybody show me how to show a splash window before my program 
>> formally
>> starts for 10 seconds. The splash window should show only color 
>> image/logo,
>> without any window frame, title bar, etc.
>>
>> how to use Java to implement this?
> 
> 
> Dear Gino,
> 
> Maybe a little too late, but see what you think of this one
>     http://www.aqss05.dsl.pipex.com/

This is a much simpler solution, suitable for most
practical purposes:

http://geosoft.no/software/splashscreen/SplashScreen.java.html





==========================================================================
TOPIC: how to set center alignment in JTable?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/77b50aaa835963b
==========================================================================

== 1 of 2 ==
Date:   Wed,   Sep 1 2004 12:14 am
From: "Nick Pomfret" <[EMAIL PROTECTED]> 


"lucy" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi, I've used the following to set the alignment for cells in JTable...
>
> ttt.setAlignmentX(0.5);
> ttt.setAlignmentY(0.5);
>
> where ttt is a JTable object,
>
> but it did not work at all,... (the JTable display shows no change at
> all...)
>
> What's the problem?
>
>

The solution is to use a CellRenderer.

Create a class that extends DefaultTableCellRenderer and implement the
getTableCellRendererComponent method, something like:

    public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected,
                                                   boolean hasFocus, int
row, int column) {
        JLabel renderedLabel = (JLabel) super.getTableCellRendererComponent(
                table, value, isSelected, hasFocus, row, column);
        renderedLabel.setHorizontalAlignment(SwingConstants.RIGHT);
        return renderedLabel;
    }


The DefaultTableCellRenderer is actually just a JLabel which JTable uses to
render each cell (a flywieght).  You can then manipulate this JLabel as you
feel (set the alignment, text, colors, icon etc).

Then you need to apply this renderer to your JTable.  You can do this by
overriding the JTable.getCellRenderer method:

public class MyJTable extends JTable {
    private TableCellRenderer renderer;

    public MyJTable(CellRenderer renderer) {
        this.renderer = renderer;
    }

    public TableCellRenderer getCellRenderer(int row, int column) {
        return renderer;
    }
}

-- 

** http://www.tabletoolkit.com **
Aggregate a JTable to an arbitrary level to create your own pivot tables





== 2 of 2 ==
Date:   Wed,   Sep 1 2004 1:17 am
From: "Nick Pomfret" <[EMAIL PROTECTED]> 


"lucy" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi, I've used the following to set the alignment for cells in JTable...
>
> ttt.setAlignmentX(0.5);
> ttt.setAlignmentY(0.5);
>
> where ttt is a JTable object,
>
> but it did not work at all,... (the JTable display shows no change at
> all...)
>
> What's the problem?
>
>

Apologies if my post comes though twice, my PC died as I was sending the
last one.

The solution is to use a CellRenderer.  By extending
DefaultTableCellRenderer and implementing the getTableCellRendererComponent
you can format cells in a JTable as you wish.

The DefaultTableCellRenderer is a JLabel that a JTable uses to render each
of its cells.  The following will render a cell as you need:

public class MyRenderer extends DefaultTableCellRenderer {

    ...

    public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected,
                                                   boolean hasFocus, int
row, int column) {
        super.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);
        setHorizontalAlignment(SwingConstants.CENTER);
        return this;
    }
}

Now you need to add this into your JTable.  Simplest way is to override the
JTable.getCellRenderer method:

public class MyJTable extends JTable {
    private MyCellRenderer renderer;

    public MyJTable(MyCellRenderer renderer) {
        this.renderer = renderer;
    }

    public TableCellRenderer getCellRenderer(int row, int column) {
        return renderer;
    }
}

-- 

** http://www.tabletoolkit.com **
Aggregate a JTable to an arbitrary level to create your own pivot tables






==========================================================================
TOPIC: Struts: best practice working with disabled fields
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/799880f4b973219
==========================================================================

== 1 of 1 ==
Date:   Wed,   Sep 1 2004 12:32 am
From: Tobias Schierge <[EMAIL PROTECTED]> 

Hi,

> I have a web application where some fields on a jsp page are disabled for some
> users.

for not loosing these properties add a second hidden field with the same 
value to the form.


Regards,

Tobias




==========================================================================
TOPIC: &#35201;&#22914;&#20309;&#29992;java&#25235;word&#27284;&#30340;property
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/dc6b5097ce89d2d4
==========================================================================

== 1 of 6 ==
Date:   Wed,   Sep 1 2004 12:28 am
From: "Peter Kirk" <peter> 


"Alan Moore" <[EMAIL PROTECTED]> skrev i en meddelelse
news:[EMAIL PROTECTED]
> On Tue, 31 Aug 2004 15:37:11 GMT, Andrew Thompson
> <[EMAIL PROTECTED]> wrote:
>
> >Welcome to Earth.
> >
> >Many languages are spoken by it's inhabitants,
> >..the above is not one of them.
>
> Some of *its* inhabitants speak them better than others...

And some *write* worser than they *speak*.




== 2 of 6 ==
Date:   Wed,   Sep 1 2004 1:53 am
From: Shanmuhanathan T <[EMAIL PROTECTED]> 

on 8/31/2004 8:42 PM Alvin Wrote:

> Hi 
> 
> &#25105;&#26377;&#20491;&#21839;&#38988;&#35531;&#25945;&#21508;&#20301;&#20808;&#36914;
> 
> &#23567;&#24351;&#24819;&#29992;java&#21435;&#25235;word&#30340;property,&#35201;&#29992;&#29978;&#40636;&#26041;&#24335;?
> 
> &#36889;&#20491;property&#26159;&#22312;&#27284;&#26696;&#32317;&#31649;&#20013;&#25353;&#21491;&#37749;&#24460;,&#40670;&#36984;&#33258;&#35330;&#24460;&#36664;&#20837;&#30340;.
> 
> &#26377;&#40670;&#24613;,&#35531;&#22823;&#23478;&#24171;&#24537;

After some cutting pasting and babelfishing, this is the verbatim
translation(according to babelfish) of what the op wants to know:
"
How has to use java to grasp word files property I to have a question to 
consult fellow advanced little brothers to want to use java to grasp 
word property, what way has to use? This property is in the file main 
pipe after the right key, the spot elects since to subscribe inputs A 
little anxious, asks everybody to help
"
This might not make much sense, since it was translated by systran.
But looks like the OP wants to know how to access word (possibly MS)
documents in java.

-- 
Shanmu.



== 3 of 6 ==
Date:   Wed,   Sep 1 2004 2:06 am
From: Morten Alver <[EMAIL PROTECTED]> 


> This might not make much sense, since it was translated by systran.
> But looks like the OP wants to know how to access word (possibly MS)
> documents in java.

I think there's a solution (don't know how far this project has come, 
though):

http://jakarta.apache.org/poi/


--
Morten



== 4 of 6 ==
Date:   Wed,   Sep 1 2004 2:33 am
From: Michiel Konstapel <[EMAIL PROTECTED]> 

On 1 Sep 2004 09:28:20 +0200, Peter Kirk <peter> wrote:

>
> "Alan Moore" <[EMAIL PROTECTED]> skrev i en meddelelse
> news:[EMAIL PROTECTED]
>> On Tue, 31 Aug 2004 15:37:11 GMT, Andrew Thompson
>> <[EMAIL PROTECTED]> wrote:
>>
>> >Welcome to Earth.
>> >
>> >Many languages are spoken by it's inhabitants,
>> >..the above is not one of them.
>>
>> Some of *its* inhabitants speak them better than others...
>
> And some *write* worser than they *speak*.

Worser? :-p
GD&R,
Michiel



== 5 of 6 ==
Date:   Wed,   Sep 1 2004 3:39 am
From: "Peter Kirk" <peter> 

> > And some *write* worser than they *speak*.
> 
> Worser? :-p

Yeah? Worse, worser, worst. Simple grammatic rules.



== 6 of 6 ==
Date:   Wed,   Sep 1 2004 4:20 am
From: "Chris Uppal" <[EMAIL PROTECTED]> 

Peter Kirk wrote:

> Yeah? Worse, worser, worst. Simple grammatic rules.

Worse, worser, worstest.

    -- chris






==========================================================================
TOPIC: abstract constructor performance?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/beb77902ee7c05c7
==========================================================================

== 1 of 1 ==
Date:   Wed,   Sep 1 2004 1:21 am
From: Mad Hamish <[EMAIL PROTECTED]> 

On Mon, 9 Aug 2004 17:35:40 +0100, "Chris Uppal"
<[EMAIL PROTECTED]> wrote:

>[Michael, this isn't aimed at you personally; it's just a general point about
>an attitude that we often express on this NG, and elsewhere, and which I think
>we are overdoing.]
>
>I don't agree with this.  The OP was asking /whether/ an optimisation was worth
>considering, and I think that's a sensible question (to which, as it happens,
>the answer is no).
>
>The advice "don't optimise" is in general good, but the picture is really more
>complicated than it suggests.  Experienced programmers get a sense of what kind
>of optimisations are (in any given situation) quite likely to be necessary, or
>quite likely to be useless.

Having read Abrash's black book on graphics I'm not so sure of that.

>  A sense of /when/ to test an optimisation to see
>if it should be used.  There is no point in building a complex system, making
>it work, performance testing it, and /then/ discovering that it needs a
>complete re-write to satisfy performance requirements; any more than there is
>in spending a week optimising a routine that will hardly every be called.

If you're in a situation where your entire system needs to be
rewritten then I'd put that down to algorithm selection and probably
poor general design selections rather than a failure to optimise. 

>Certainly beginners (and experienced programmers too) tend to focus too much on
>performance, and it will always be worth discouraging that tendency.  But -- 
>and I think this is too often ignored -- NOT to the extent of stopping them
>thinking about costs, and developing a sense of what is cheap and what is
>expensive.
>
>There have been quite a lot of posters here over the last year or two who have
>used techniques with horrifying costs in space or time, apparently without
>realising what they are doing.  That could just be inexperience (of course),
>but I wonder to what extent is because we (I do it too, I'm afraid) keep
>hammering on the point that optimisation is "evil", and whether that has
>discouraged them from acquiring a simple (but not simplistic) picture of what
>is really going on, and what that costs.

I think there's a difference between deciding on a reasonable
algorithm and optimising the implementation of the algorithm.

Thoought on the selection of an algorithm is a good plan, optimising
the implementation of the algorithm isn't.




==========================================================================
TOPIC: Would like a preprocessor.
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f8d589c27ece424e
==========================================================================

== 1 of 1 ==
Date:   Wed,   Sep 1 2004 2:27 am
From: "Chris Uppal" <[EMAIL PROTECTED]> 

Grant Wagner wrote:

> Labelled break:
>  [...]

> Unlabelled break:
>  [...]

> Avoid break entirely:
>  [...]
(This is buggy, BTW -- but it doesn't affect your point, or mine)

And lastly:

> boolean isIntersectionPresent(int[] arr1, int[] arr2) {
>     for (int i = 0; i < arr1.length; i++) {
>         for (int j = 0; j < arr2.length; j++) {
>             if (arr1[i] == arr2[j]) {
>                 return true;
>             }
>         }
>     }
>     return false;
> }

This is the /only/ one of the four that I would consider natural.  The others
are -- to varying degrees -- obfuscated.

Granted that there are cases where other considerations would mean that one of
the others was to be preferred, but such cases are in the small minority.

    -- chris







==========================================================================
TOPIC: What is a monitor ?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/69bebcbefe17ef56
==========================================================================

== 1 of 1 ==
Date:   Wed,   Sep 1 2004 2:33 am
From: "Chris Uppal" <[EMAIL PROTECTED]> 

Razvan wrote:

> Somebody asked me today what is a monitor. I said that it is some
> piece of code that manages the locking mechanism and that it should
> not be concerned about it because the monitor mechanism is implemented
> in Java by default.

<grin>


> Can somebody give a more academic/corect definition ?

According to a book I happened to have handy, the name "monitor" was invented
by Tony Hoare, and was popularised in his paper "Monitors: an operating system
structuring concept" which was published in the CACM in 1974 (it's in the ACM's
online library, but you need a subscription to read it).

Apparently the concept was then used in the Pascal family of languages.

Having wondered what "monitor" really meant myself (not being a Pascal
programmer), I went off and read the paper.  Here's a summary.

A "monitor" is a programming language element used for expressing the control
of concurrency.  In modern terms it is best viewed as a flavour of class with
some added elements and properties that make it well-adapted to expressing
concurrency.

A monitor is a collection of:

    some data items (variables)
    some procedures (methods)
    some "conditions", which can be true or false.

The procedures have exclusive access to the variables and conditions (which
makes a monitor very like a modern OO object).  Additionally, the
compiler/system ensures that no two procedures can be active at once (very much
like "synchronized" methods in Java).  Lastly any procedure can "wait" for a
condition to become true, or it can "notify" any other processes that the state
of a condition had changed.

As you'll see, it's all very familiar.  It's interesting to compare it to the
state of the art at that time.  I don't think anyone (except Alan Kay, and his
associates, of course) really knew what OO was then (I don't think the term was
in anything like general use, if it had even been invented).  And although
Simula had already introduced the "class" concept (Hoare mentions it in the
paper) I don't think an understanding of /objects/ (as distinct from ADTs, say)
had yet emerged.  One concurrency concept that it was intended to subsume was
the "critical section", where passages of code scattered around the program
would be marked such that none of them were allowed to execute concurrently.
Compared with that (and with semaphores, etc) monitors have a much more
structured (and modern!) feel to them.  BTW, Hoare ascribes the invention to
Per Hinch-Bransen.

The paper then goes on to illustrate (and prove) how monitors can be used to
solve various concurrency problems (like bounded queues, emulating semaphores,
etc), and to discuss issues like which of the waiting processes should be
scheduled next when a condition was notified.  Something of a classic, that
paper...

HTH

    -- chris






==========================================================================
TOPIC: File.lastModified *extremely* slow ?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c70759a9620dbe78
==========================================================================

== 1 of 2 ==
Date:   Wed,   Sep 1 2004 2:30 am
From: "Chris Uppal" <[EMAIL PROTECTED]> 

Robert Mischke wrote:

> > It does sound reasonable when you look at it from a Windows programmer's
> > perspective.  Unfortunately it looks like pointless complication from a
> > UNIX programmer's perspective, since there is no underlying API that it
> > maps onto, and it would seem that Sun's Java programmers think like
> > UNIXers ;-)
>
> But it could still provide an efficient underlying implementation on
> Unix, even if there's no API support from the OS.

My point is that, from the POV of a UNIXer, it would be a bizarrely complex API
that provided no advantage in either expressiveness or performance.  Hence
they'd not add it.  The /only/ reason to introduce an API like this is to
support systems where there is an actual performance advantage; otherwise it's
just adding complexity with no return.


> From what Mark wrote, the guys at Sun are actually planning to improve
> on this in Java 1.5, so at least there is hope :)

Yes, but I suspect it'll be 1.6 rather than 1.5.  I hope I'm wrong...


> > > The problem is that this kind of performance is kind of a show-stopper
> > > for my application.
> >
> > Is it really a show stopper ?  [...]
>
> Well, it is... because [...]

Fair enough.

BTW, the hope that an improvement will "soon" be available for Windows makes
the case against JNI even weaker.  You will not only not have to support that
solution on multiple platforms, but you'll also not be committing yourself to
maintaining the Windows JNI code for ever.

    -- chris






== 2 of 2 ==
Date:   Wed,   Sep 1 2004 2:34 am
From: "Chris Uppal" <[EMAIL PROTECTED]> 

John C. Bollinger wrote:
> > http://www.javaworld.com/javaworld/javaqa/2003-12/01-qa-1212-intern.html
>
> That's an interesting article; thanks for pointing it out.  The
> article's premise is slightly flawed, but the code (the first example,
> at least) works.

> I will therefore have to retrench, and say that when
> you intern() a String you *may* ensure that a copy is retained for the
> remainder of the VM's lifetime.  Whether or not that is is in fact
> ensured depends on the String implementation [not on the VM
> implementation, as the JW article's author mistakenly implied].

It certainly doesn't /depend/ on the JVMs implementation.  I think the author's
reasoning was (or rather, should have been ;-) that in the specific JVM he was
testing, String interning /is/ done by the JVM -- in the discussion afterwards
he talks of the interned String data being kept outside the heap.
Incidentally, I can't see the sense of that implementation decision: either the
implementation is simple-minded and does not reclaim interned Strings, in which
case it makes sense to keep the data in a special non-GCable area outside the
heap; or it does reclaim them, in which case the sensible approach is to use a
weak collection (or perhaps just the JVM's underpinnings for weak collection)
and it would be pointless to store them anywhere except the heap -- which is,
after all, designed for that kind of thing.

Changing the subject slightly.  It's not completely clear to me that it is
legal for the JVM to recycle interned Strings in this way -- at least not it if
has observable consequences (other than not-running-out-of-memory ;-) and
System.identityHash() is certainly observable.  The contract of intern() is
perhaps not strong enough to rule this optimisation out for "normal" strings
(and in any case, I'm not sure that the JavaDocs are normative).  However the
contract in the JLS2 for the String literals does not (IMO) leave any scope for
/any/ observable recycling of the corresponding objects -- the language is
unambiguous and repeated.  What's more the interning of Sting literals is
discussed (briefly) in the context of class loading, so it would not be easy to
argue that the JLS writers had just "forgotten" this issue.

The obvious (and preferable, IMO) fix would be to weaken the language of the
JLS in its next edition.  Alternatively, the implementation could "pin"
interned Strings when their identityHash() is evaluated, and make them
non-recyclable at that time (say by adding a strong ref to the String to some
internal list).

As it stands (and despite the article's assertion) I don't see any reason to be
confident that:

class Oddity
{
    static final int aHash = System.identityHash("Hello");
    static bool check() { return aHash == System.identityHash("Hello"); }
}

cannot false from Oddity.check().

    -- chris








==========================================================================
TOPIC: byte manipulation in Java ?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a6813ab049aef0b6
==========================================================================

== 1 of 2 ==
Date:   Wed,   Sep 1 2004 3:04 am
From: [EMAIL PROTECTED] (Ph. Barthelemy) 

Hi,

I am looking a byte manipulation library in Java ( with functions such
as get the MSB, the LSB, decode/encode a Binary-coded decimal, etc...
for the various Java data types ).

I did not find anything included in J2se 1.4.
Is there a well-known library to do this ? or should rewrite my own
from scratch (  not very difficult, not very satisfying either to
reinvent the wheel... )

TIA,
--Philippe



== 2 of 2 ==
Date:   Wed,   Sep 1 2004 5:41 am
From: [EMAIL PROTECTED] 


Ph. Barthelemy wrote:
> Hi,
>
> I am looking a byte manipulation library in Java ( with functions
such
> as get the MSB, the LSB, decode/encode a Binary-coded decimal, etc...
> for the various Java data types ).
>
> I did not find anything included in J2se 1.4.
> Is there a well-known library to do this ? or should rewrite my own
> from scratch (  not very difficult, not very satisfying either to
> reinvent the wheel... )
>
> TIA,
> --Philippe

Java uses network byte ordering.  MSB and LSB are defined according to
that.





==========================================================================
TOPIC: Different compilers = Different byte code?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d6730b906587dde
==========================================================================

== 1 of 2 ==
Date:   Wed,   Sep 1 2004 4:10 am
From: "Chris Uppal" <[EMAIL PROTECTED]> 

Andrew Thompson wrote:

> > The extra bytes /have/ to make it compress to a larger size
> > (under any reasonable assumptions).
>
> What if they contain information for (what
> was it you called it) 'pre-training' of the
> compression algorithm?

Normally a (LZ-style) compressor starts in a "blank" state, and it only starts
to achieve compression once it has seen enough input data to recognise
exploitable repetitions.  So it can't provide any compression until at least
the second time it sees, say, the string "java/lang/Object".  The idea of
pre-training is that if you warm up the compressor by giving it some typical
text to process before the real data, then it will hit the ground running as
far as its real work is concerned.  The problem is that the training data has
to be known to both the compressor and decompressor in advance; if not then
you'll have to transmit that data /as well/ and there'll be a nett increase in
the size of the transmission.  The exception to that is if you are sending
several (independently) compressed files which have "similar" contents.  In
that case, it might be worthwhile to send the training data /once/, followed by
the compressed (with identical training) data for the N real files.

E.g. a modified JAR file format might allow a "TRAINING.DAT" file somewhere at
the start of the JAR (just after the manifest, say) which would be used to
pre-train all the [de]compressors used for the contained .class files.  Of
course, that would not then be a valid ZIP format file, since it would be using
non-standard compression.   (And, as I pointed out in the post you are
referring to, it doesn't seem to be a worthwhile technique for .class files -- 
the gains are too small to justify the effort.)

Anyway, the point of this is that it wouldn't help to add data to each of the
classfiles.  Of course, you /could/ split up the training data and share it out
amongst several of them, but that seems a little, um, perverse ;-)


> Mickey Segal swears the MS .cab files are
> smaller than the equivalent .zip's, I thought
> (maybe) they were doing some clever things
> for compression.  As people point out though,
> zip format is not that wasteful over some of
> the best algorithms, so how could MS pull it
> off in a .cab file?

I know /very/ little about how CAB files work.  The only description I've seen
suggests that MS are using a compression scheme (LZX) that is algorithmically
similar to the one used in ZIP files, but which has a significantly tighter
(and /much/ more intricate) way of encoding the repetitions that it has
discovered.  I get the impression too that the encoding can be tuned
(statically) to include something analogous to training (CAB format is not
intended to be general-purpose, so MS can use knowledge of what the typical CAB
file will contain, and can choose the details of the encoding appropriately).
But, to be honest, I don't really understand the description, so I could easily
be wrong...

The bottom line seems to be that CAB just has a "better" compressor than ZIP
(at least for some sorts of files).  Which is not unexpected -- it was designed
about a decade later, and can assume larger memories and faster machines, so it
/ought/ to be better even without any extra cleverness.


> Pre-training using information stored in those
> extraneous bytes might be a way to explain it..
> + (and this is an important point) if the
> standard 'jar' format is used on the *same*
> class files, whith the relatively uncompressible
> extraneous bytes that do not do anything useful
> for the Sun VM's.. those together might add up
> to the difference..

So Sun designed their format so that M$ could compress it better than they
themselves could ?  Unlikely, I fear ;-)


> OK.. I think I've finished musing on obsolete
> VM's.. time to get back to writing applet's
> that will work in all 1.1+ VM's...

An unusual and challenging vocation you have chosen, Mr Thompson.  You might
find digging ditches more pleasant...

    -- chris





== 2 of 2 ==
Date:   Wed,   Sep 1 2004 5:16 am
From: Andrew Thompson <[EMAIL PROTECTED]> 

On Wed, 1 Sep 2004 12:10:44 +0100, Chris Uppal wrote:

> The bottom line seems to be that CAB just has a "better" compressor than ZIP
> (at least for some sorts of files).  Which is not unexpected -- it was designed
> about a decade later, and can assume larger memories and faster machines, so it
> /ought/ to be better even without any extra cleverness.

I'll take that as the 'reasonable explanation'
that I alway lacked.  Thanks.

>> OK.. I think I've finished musing on obsolete
>> VM's.. time to get back to writing applet's
>> that will work in all 1.1+ VM's...
..
> An unusual and challenging vocation you have chosen, Mr Thompson.  You might
> find digging ditches more pleasant...

Oh (chuckles) I'm just working on a suite 
of tools that will ensure that a minimum
Java version is installed for Java applets
and that showDocument() can be made to either
work reliably, or fail and make a lot of noise,
..then there are also some tweaks to adjust
page 'focus'.

Then it is straight back into the 1.4+ 
applets, screensavers, server side magic..   :-)

-- 
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology




==========================================================================
TOPIC: file image uploaded to a webserver appears garbled after upload.
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ef06b42d62b446df
==========================================================================

== 1 of 1 ==
Date:   Wed,   Sep 1 2004 3:59 am
From: "William Brogden" <[EMAIL PROTECTED]> 

On Tue, 31 Aug 2004 14:26:29 -0700, Nishi Bhonsle  
<[EMAIL PROTECTED]> wrote:

>
> Hi:
>
> The images uploaded in a directory on a web server from a client  
> browser, end up garbled. i.e. if the image is uploaded via the UI to  
> some dir say C:\images, after the upload, if i view the image in the  
> destination directory, it looks garbled.
> I verified that the initial image in the source location was not garbled.
> I checked the file size and the permissions on the image at the  
> destination, and it seems to be the same as the one in the source  
> location.
> I also noticed that the garbling does not happen for gif images of size  
> 1K or 2K or 3K but for .jpg images of size > 10 K etc
> (I have not found bigger .gif files to test this.)
>
> A part of the java code that handles upload creates an object of class  
> MultipartFormHandler (which parses an incoming file upload post).
>
> This class parses the incoming post and returns MultipartStreamItems for  
> each form item.
> If setCharacterEncoding() is called (with anything other than null),  
> then strings returned from this class will be character-set decoded.  
> Otherwise, strings returned from this class are not character-set  
> decoded. In this way, MultipartFormHandler precisely matches the  
> behavior of ServletRequest.
>
>
> MultipartFormHandler handler = new MultipartFormHandler(request);
> handler.setCharacterEncoding("UTF-8");
>
>  if (imageFile != null)
>        {
>               FileReader reader = new FileReader(file);
>               FileWriter writer = new FileWriter(imageFile);

****** Bingo - A FileReader tries to turn a byte stream into characters
   A FileWriter does a character conversion on writing.

   You should be using plain InputStream etc. for manipulating bytes.




>               int c;
>                 while ((c=reader.read()) >= 0)
>                 {
>                   writer.write(c);
>                 }
>                reader.close();
>                writer.close();
>                }
>
> What can cause the garble?
>
> Thanks, Nishi.
>



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/




==========================================================================
TOPIC: JUnit Testing with JavaServer Faces
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7eba10c6dd2185d3
==========================================================================

== 1 of 1 ==
Date:   Wed,   Sep 1 2004 5:12 am
From: [EMAIL PROTECTED] (Roger) 

Hi

Does anyone know of anything like the StrutsTestCase extension for
JUnit testing Struts but for JSF?

Regards
Roger




==========================================================================
TOPIC: Detecting double click with MouseListener
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7acf887f3c6b02cd
==========================================================================

== 1 of 1 ==
Date:   Wed,   Sep 1 2004 5:52 am
From: Jacob <[EMAIL PROTECTED]> 

Jacob wrote:


> I can detect a docuble click using the MouseListener
> interface and inspect the event.getClickCount().
> 
> However, at that point in time, the event has already
> been classified as a single click (as the clickCount
> is 1 the first time around).
> 
> My intention is to start action A on a single click
> and action B on a double click. With a standard setup
> I will get action A on a single click but action A + B
> on a double click!
> 
> Seems like a delay is necessary in order to fully
> classify the event. Is there a standard way to acheive
> this?


I'll try to fix this myself; In doing so I need access
to the system click interval. How?

Thanks!





==========================================================================
TOPIC: Who can resist a compilable example? - JComboBox
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a964462dca846012
==========================================================================

== 1 of 1 ==
Date:   Wed,   Sep 1 2004 5:45 am
From: "VisionSet" <[EMAIL PROTECTED]> 

Sorry to blatently sensationalise my post, for once I'm in a hurry.

Here is a short compilable example that illustrates my problem.

To sumarise, I require the combobox to change its preferredsize as the
source for BasicComboBoxUI indicates it should when fireContentsChanged() is
called.
If the preferredsize changes then hopefully the JCB has half a chance of
responding visually.
I do not want to use DefaultComboBoxModel, my requirement is not simple row
addition like the example, the whole model may change at each update.
If anyone has any idea how to modify the below to fill this requirement,
please let me in on the secret!

import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class ComboTest extends JFrame {

 JComboBox combo = new JComboBox();
 ComboModel model = new ComboModel();

 public ComboTest() {

  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  combo.setModel(model);

  JPanel panel = new JPanel(new BorderLayout());

  Box box = Box.createHorizontalBox();
  combo.setMaximumSize(combo.getPreferredSize());
  combo.setMinimumSize(combo.getPreferredSize());
  box.add(combo);

  panel.add(box, BorderLayout.NORTH);

  JButton button = new JButton("Refresh");

  button.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    model.changeModel();
    System.out.println(combo.getPreferredSize());
   }
  });

  panel.add(button, BorderLayout.EAST);

  setContentPane(panel);

  setBounds(50,50,400,100);

  setVisible(true);
 }

 public static void main(String[] args) {
  new ComboTest();
 }

 class ComboModel
  extends AbstractListModel implements ComboBoxModel {

  List list = new ArrayList();
  String last = "X";
  Object selected;// = last;

  public Object getSelectedItem() {
   return selected;
  }

  public void setSelectedItem(Object item) {
   if((selected != null && ! selected.equals(item)) ||
     (selected == null && item != null)) {
    selected = item;
    fireContentsChanged(this, -1, -1);
   }
  }

  public int getSize() {
   return list.size();
  }

  public Object getElementAt(int index) {
   return list.get(index);
  }

  void changeModel() {
   list.add(last);
   last = last + "X";
   fireContentsChanged(this, 0, list.size());
  }
 }
}


-- 
Mike W





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

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/prefs

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 



------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/BCfwlB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/kumpulan/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to