comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * Help please - Why does ByteBuffer return '?' as opposed to what was put? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d3036bb0e4e92e4 * Java is EVIL, it's the programming language of SATAN ! ! ! - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/195bb46ec0ebeeea * Oracle JDBC XA question - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3ded1e7f0747a226 * background process: existing jsp/servlet or new applet? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/22361eba54ae92f9 * hex in a file stream - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b24f4f48f3cd8c3 * Problems with regular expressions using JDK java.util.regex package - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/85e2934c64426894 * Character encoding between Win and *nix - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d00907704bee1888 * How can I convert a String to an Int? - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3a44aee4d751e576 * help with my first project on first job, how to read a strange file, thanks a lot!!!!!!! - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8c32ba1a17d68c9a * reference to a jar file inside another jar file - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7dab58f45ecad79c * Newbee Question about random numbers - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d5332da2a87b1a4a * How to update Gui data from application code? - 2 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e5ed9fff31421c42 * singleton pattern - 5 messages, 5 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2df0080c97ed1370 * javax.xml.transform.TransformerException - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/16ee0563542144eb * applet's call comportement - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/cc1d4563dc67060c * Regular expression problem - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/98669b754907f080 * Inner Class in EJB not found - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d3fb4eb0ebb4e93d * Apache Referencing META-INF Directory - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c8128b3e03cc879b * sorting an ArrayList by int - 3 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/127ea15b32732f1 ========================================================================== TOPIC: Help please - Why does ByteBuffer return '?' as opposed to what was put? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d3036bb0e4e92e4 ========================================================================== == 1 of 2 == Date: Mon, Oct 25 2004 7:39 am From: "xarax" <[EMAIL PROTECTED]> "Tim Ward" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Tor Iver Wilhelmsen" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > [EMAIL PROTECTED] (Ed) writes: > > > > > I have an annoying problem with ByteBuffer (BB). > > > > Rather with the understanding of how SIGNED bytes work. > > Yet another victim of the utterly bizarre decision to make bytes signed in > the first place. Or rather the bizarre decision not to include "unsigned" integer types of all sizes. == 2 of 2 == Date: Mon, Oct 25 2004 10:14 am From: "John C. Bollinger" <[EMAIL PROTECTED]> Ed wrote: > I have an annoying problem with ByteBuffer (BB). No, you have a lack of appreciation for the difference between bytes and characters, and for the accompanying niceties of character encoding. > I have the following code: > > for (int i = 0; i < 255; i++) > { > ch = (char) i; > test = new StringBuffer(); > test.append((char) i); So far, so good. > byteBuffer.put(test.toString().getBytes()); But that's bad. You are using the no-arg version of String.getBytes(), which encodes the characters of the string into an array of bytes according to the system's default character encoding scheme. You should _always_ use an explicit encoding scheme to (1) make your intention clear and (2) ensure that your application works the same way on every system. It will also get you thinking about what's happening; the details of this conversion are part of what's tripping you up. > byteBuffer.flip(); > > back = byteBuffer.get(); That bit is probably fine, although you omitted the declaration of back. > // Uncomment below to see more working ... > > /* > if (back < 0) > { > System.out.println("... adding 256 ...."); > back = back + 256; > } > */ Well, yes, I can imagine that that might work better. byteBuffer.get() returns a value of type *byte*, which is a *signed* 8-bit number. You are comparing it (below) to a *char*, which (in one relevant sense) is an *unsigned* 16-bit number. Try this: if (((char) 0x80) == ((byte) 0x80)) { System.out.println("No duh!"); } else { System.out.println("Surprise!"); } Note that, as for most numeric operations on bytes, chars, and shorts, the operands are widened to type int, with sign extension, for that comparison. > backch = (char) back; > > if (ch != backch) > { > System.out.println("ERROR - following do not match:"); > } > System.out.println("" + i + " [" + ch + "] = " + back + " [" + > backch + "]"); > byteBuffer.clear(); > } > > The code works ok up to value 127. From 129 to 159 (hex 80 to 9F) > bytebuffer always gives back the '?' char (int 63). From 160 to 255 I > get a negative number. The '?' characters are a dead giveaway of a character encoding problem. Your default character encoding is apparently a one-byte encoding that does not map characters U+0080 through U+009f (and, probably not characters greater than U+00ff, either). It is probably some variant on Latin-1 (aka ISO/IEC 8859-1, which is not quite the same as ISO-8859-1), which in fact doesn't define mappings for those characters, but which also doesn't define mappings for characters U+0000 - U+0019. > I am obviously doing something wrong. You are improperly intermixing bytes and characters. Do not use Strings, chars, StringBuffers, etc. to hold binary data. Binary data that represents characters must be decoded according to the appropriate character encoding scheme, and that scheme generally must be obtained from an external source. Always specify the encoding explicitly when producing binary representations of character data. And remember that Java bytes are signed. John Bollinger [EMAIL PROTECTED] ========================================================================== TOPIC: Java is EVIL, it's the programming language of SATAN ! ! ! http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/195bb46ec0ebeeea ========================================================================== == 1 of 3 == Date: Mon, Oct 25 2004 7:43 am From: "xarax" <[EMAIL PROTECTED]> "Dave Monroe" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > [EMAIL PROTECTED] (Karl-Hugo Weesberg) wrote in message news:<[EMAIL PROTECTED]>... > > Java is EVIL, it's the work of the devil, made to collect your > > souls and to turn you into brainless slaves of hell. > > > > If you like Java, you will lose your soul to be damned > > for eternal torment in hell.Demons and devils will feast on your soul > > for all eternity. > > > > So stop using it now to save your soul. > > > > Or the holy inquisition will come for you and burn your flesh to save > > your soul, because the devil must not collect more souls or nobody can > > prevent Armageddon. > > > > Java is evil, using it is BLASPHEMY , only heretics and > > witches like Java.And heretics and witches shall BURN ! > > > > Java = programming language written by SATAN in Hell's Kitchen in 666 minutes ! ! ! > > Thank you for a fair, balanced and well reasoned presentation. > > Isn't it time for your medications? When will these newbies ever learn? Please post your source code! How can we find the problem without the source? ;) == 2 of 3 == Date: Mon, Oct 25 2004 8:02 am From: Bryce <[EMAIL PROTECTED]> On 24 Oct 2004 16:35:12 -0700, [EMAIL PROTECTED] (Karl-Hugo Weesberg) wrote: >Java is evil, using it is BLASPHEMY , only heretics and >witches like Java.And heretics and witches shall BURN ! > >Java = programming language written by SATAN in Hell's Kitchen in 666 minutes ! ! I think you are confusing Java with XSLT. Lord knows I sometimes think XSLT is the spawn of satan!! -- now with more cowbell == 3 of 3 == Date: Mon, Oct 25 2004 9:06 am From: "John C. Bollinger" <[EMAIL PROTECTED]> Karl-Hugo Weesberg wrote: > Java is EVIL, it's the work of the devil, made to collect your > souls and to turn you into brainless slaves of hell. > > If you like Java, you will lose your soul to be damned > for eternal torment in hell.Demons and devils will feast on your soul > for all eternity. > > So stop using it now to save your soul. > > Or the holy inquisition will come for you and burn your flesh to save > your soul, because the devil must not collect more souls or nobody can > prevent Armageddon. > > Java is evil, using it is BLASPHEMY , only heretics and > witches like Java.And heretics and witches shall BURN ! > > Java = programming language written by SATAN in Hell's Kitchen in 666 minutes ! ! ! Trolling is GOOD, it's the work of Lala, the yellow Teletubbie, made to collect your soul and turn you into a brainless, but blissful, couch potato. If you like trolling you will lose your sense of good taste in children's television programming, which will be of great comfort to you these days and in days to come. Brightly colored, linguistically challenged cyborgs will cavort before your glazed eyes all the days of your life. If you troll really well you might even be granted a glimpse of "Boobah". Keep trolling in hope of eternal, senseless, buttock-numbing bliss. Or you might be forced to take your medication. Trolling is good, doing it is even better than watching "Elmo's World". Only articulate, literate, or tactful people dislike trolling, and articulate, literate, and tactful people would never watch "Brum". Trolling = Usenet activity designed by Barney on the back of a napkin in 7 seconds! ! ! ! ! ! ! JCB ========================================================================== TOPIC: Oracle JDBC XA question http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3ded1e7f0747a226 ========================================================================== == 1 of 1 == Date: Mon, Oct 25 2004 7:55 am From: [EMAIL PROTECTED] (spiderbug) > Good! Your response made me dig a little. I had mostly just consulted the XA spec, > which > was vague in that area. Looking deeper, I checked our (FirstSQL/J ORDBMS) XA code, > which > does support mixing global and local transactions in this manner, and checked the > JTA > spec. > > Section 3.4.7 "Local and Global Transactions" in my JTA spec (1.01B) encourages a > resource adapter (JDBC Driver & RDBMS) to support local transactions on a connection > after being 'disassociated' from a global transaction with end(). OTOH, the section > does > also permits an RDBMS to disallow it and throw a native exception. Thus, Oracle > seems to > be compliant with JTA in this area. > > I hope that clears up the confusion I promulgated with my earlier response. Hmm - thanks for your response...But even if the resource adapter decides to not allow mixing of transactions, it should support subsequent transactions one after the other and without committing the previous one (committing, not ending - it definitely has to be ended). xares.start(xid1) xares.end(xid1) xares.start(xid2) xares.end(xid2) ....prepare..commit....etc etc.. Anyway I checked a few other XA drivers - they all differ in their behaviour as far as mixing is concerned. So I guess that's it. But even then, Oracle's error messages leave a lot to be desired. Regards ~spiderbug~ ========================================================================== TOPIC: background process: existing jsp/servlet or new applet? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/22361eba54ae92f9 ========================================================================== == 1 of 1 == Date: Mon, Oct 25 2004 8:10 am From: Bryce <[EMAIL PROTECTED]> On 22 Oct 2004 20:07:34 -0700, [EMAIL PROTECTED] (robert) wrote: >Bryce <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... >> On 22 Oct 2004 11:25:30 -0700, [EMAIL PROTECTED] (robert) wrote: >> >> >- post to the controller servlet which spawns a thread to do the db >> > update, then sends a response back to the browser. all using the >> > existing infrastructure. adv.: the application comes back fast. >> > disadv.: one loses contact with the db update, so confirming that >> > it worked is some work. >> >> We do exactly this (using ThreadPools and worker threads). You lose >> track in that its an asynchronous transaction. A status page retrieves >> the data, to view if the transaction was successful. > >that was my inclination. i guess i'll have to fight to the death to >kill off the applet wave. not that applets are necessarily bad (another >system is applet based), but mixing one in just to get threading seems >foolish. Our requirements were that we needed to guarantee delivery and execution of the process (banking software if funny that way), but immediate feedback wasn't important. Issue was that hundreds and thousands of transactions can be taking place. So having an "in progress" page wasn't feasible. That's where the asynchronous messaging comes in. JMS would have been a good technology to use, but design decisions were made before I came on board. Originally, they had each servlet request spawning a thread... Imagine having hundreds of requests every minute or so... A thread for each request would eat resources pretty darn quick. I implemented thread pooling using a queue and a finite number of worker threads. Works great. Processing slows down during peak usage, but usually a transaction is completed within a few minutes. There are some tricks we do, s uch as logging the transaction before returning control to the user. That way, they know the transaction has been submitted, and we can guarantee that it will be run (again, JMS server would have been a perfect solution...) -- now with more cowbell ========================================================================== TOPIC: hex in a file stream http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b24f4f48f3cd8c3 ========================================================================== == 1 of 3 == Date: Mon, Oct 25 2004 8:28 am From: [EMAIL PROTECTED] (omar) hi everyone, I am trying to make a java program that creates a bitmap file through a file stream. When I view a regular bitmap file in a hex editor, I see that there are many periods and other symbols. When I look at the hex side of these periods and symbols, I see that each period is assigned a different hexadecimal value. My question is as follows: How can I make my program output these periods that have the proper hexadecimal values behind them? Is there any library that I should be using in order to output these specific periods and other symbols? Thank you very much, Omar == 2 of 3 == Date: Mon, Oct 25 2004 10:09 am From: Paul Lutus <[EMAIL PROTECTED]> omar wrote: > hi everyone, > > I am trying to make a java program that creates a bitmap file through > a file stream. When I view a regular bitmap file in a hex editor, I > see that there are many periods and other symbols. When I look at the > hex side of these periods and symbols, I see that each period is > assigned a different hexadecimal value. That is because each period is meant to represent a hex value that is not representable in the font current in use. It doesn't represent their actual value as text (since they don't have one). > My question is as follows: How > can I make my program output these periods that have the proper > hexadecimal values behind them? Defone "output". Define "behind them". > Is there any library that I should be > using in order to output these specific periods and other symbols? Define "output" again. What are you trying to do exactly? Are you, as you say above, trying to read a file stream and create a bitmap file from it? If so, post your code and ask specific questions. -- Paul Lutus http://www.arachnoid.com == 3 of 3 == Date: Mon, Oct 25 2004 10:13 am From: Oscar kind <[EMAIL PROTECTED]> omar <[EMAIL PROTECTED]> wrote: > I am trying to make a java program that creates a bitmap file through > a file stream. When I view a regular bitmap file in a hex editor, I > see that there are many periods and other symbols. When I look at the > hex side of these periods and symbols, I see that each period is > assigned a different hexadecimal value. Yes, that's how a hex viewer works: unprintable characters are displayed as a period. > My question is as follows: How > can I make my program output these periods that have the proper > hexadecimal values behind them? Is there any library that I should be > using in order to output these specific periods and other symbols? Check if the character is an ISO control character according to Character#isISOControl(char). -- 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: Problems with regular expressions using JDK java.util.regex package http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/85e2934c64426894 ========================================================================== == 1 of 3 == Date: Mon, Oct 25 2004 8:29 am From: [EMAIL PROTECTED] (Tom Maki) Hi, I have to admit I have never been good at regular expressions and I have a piece of code that I want to write using the java.util.regex package. It is quite simple -- it is for a compression filter. Once thing that is a bit different is that I want to compress all web pages that don't have the subsequence 'admin' in them (these pages all go over a LAN so compression would be counterproductive. I can't just invert the find () boolean since the client will be changing the reg. exp. over time. Anyway, here is the test case I have been using. You notice is fails on assertFalse(pattern.matcher(adminUri).find()) statement: import java.util.regex.Pattern; import junit.framework.TestCase; public class RegularExpressionTest extends TestCase { public void testRexEx() { String adminUri = "/rss/admin_product_types_start.do"; String reportUri = "/rss/price_change_report_start.do"; String regEx = "[^a][^d][^m][^i][^n]"; Pattern pattern = Pattern.compile(regEx); assertTrue(pattern.matcher(reportUri).find()); assertFalse(pattern.matcher(adminUri).find()); } } Any help would be greatly appreciated! Thanks, Tom Maki == 2 of 3 == Date: Mon, Oct 25 2004 10:05 am From: Paul Lutus <[EMAIL PROTECTED]> Tom Maki wrote: > Hi, > > I have to admit I have never been good at regular expressions and I > have a piece of code that I want to write using the java.util.regex > package. It is quite simple -- it is for a compression filter. Once > thing that is a bit different is that I want to compress all web pages > that don't have the subsequence 'admin' in them (these pages all go > over a LAN so compression would be counterproductive. I can't just > invert the find () boolean since the client will be changing the reg. > exp. over time. Anyway, here is the test case I have been using. You > notice is fails on assertFalse(pattern.matcher(adminUri).find()) > statement: How would we notice that? You are not providing a complete, compilable example. > > import java.util.regex.Pattern; > import junit.framework.TestCase; > > public class RegularExpressionTest extends TestCase { > > public void testRexEx() { > String adminUri = "/rss/admin_product_types_start.do"; > String reportUri = "/rss/price_change_report_start.do"; > > String regEx = "[^a][^d][^m][^i][^n]"; > Pattern pattern = Pattern.compile(regEx); > assertTrue(pattern.matcher(reportUri).find()); > assertFalse(pattern.matcher(adminUri).find()); > > } > } > > Any help would be greatly appreciated! Please post a complete, compilable example, and say exactly what you are doing and how it fails. -- Paul Lutus http://www.arachnoid.com == 3 of 3 == Date: Mon, Oct 25 2004 10:19 am From: Oscar kind <[EMAIL PROTECTED]> Tom Maki <[EMAIL PROTECTED]> wrote: > I have to admit I have never been good at regular expressions and I > have a piece of code that I want to write using the java.util.regex > package. It is quite simple -- it is for a compression filter. Once > thing that is a bit different is that I want to compress all web pages > that don't have the subsequence 'admin' in them (these pages all go > over a LAN so compression would be counterproductive. I can't just > invert the find () boolean since the client will be changing the reg. > exp. over time. Anyway, here is the test case I have been using. You > notice is fails on assertFalse(pattern.matcher(adminUri).find()) > statement: > > import java.util.regex.Pattern; > import junit.framework.TestCase; > > public class RegularExpressionTest extends TestCase { > > public void testRexEx() { > String adminUri = "/rss/admin_product_types_start.do"; > String reportUri = "/rss/price_change_report_start.do"; > > String regEx = "[^a][^d][^m][^i][^n]"; > Pattern pattern = Pattern.compile(regEx); > assertTrue(pattern.matcher(reportUri).find()); > assertFalse(pattern.matcher(adminUri).find()); > > } > } The assertion on the String adminUrio fails, because there is a substring in it that doesn't start with an 'a', doesn't have 'd' as second character, etc. The first 5 characters match. Why not try to match "admin" (or "[Aa][Dd][Mm][Ii][Nn]" for case-insensitivity)? If it doesn't match, compress. You can even use the boolean inversion operator (!) for this... Sorry for the sarcasm, but the first thing I was told about regular expressions was to make sure what to match; especially as complicated regular expressions are often WORN (written: once, read: never). Or at least they are as I write them... -- 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: Character encoding between Win and *nix http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d00907704bee1888 ========================================================================== == 1 of 1 == Date: Mon, Oct 25 2004 8:43 am From: "John C. Bollinger" <[EMAIL PROTECTED]> [EMAIL PROTECTED] wrote: > I'll try to be a little bit more specific, while answering some of the > questions that came in replies: > > I do not have control over the client, as a matter of fact I don't even > know for sure if it is a Windows client. > > The connections my server accepts include non-http requests, so I > cannot use URLConnection (or can I?) > > As a matter of fact, the data I'm processing is in the HTTP body (in > case I do receive a HTTP request). In this body I can also find > information about the encoding. As a matter of fact, the encoding > specified here is the only way for me of knowing with which kind of > characters I'm dealing... Should however this information be > unavailable (since also that is possible), then I can consider the data > encoded as UTF-8.. Well that doesn't sound so hard. You locate the encoding specification in the message, if present, and use it to construct an InputStreamReader around the input byte stream. If no encoding specification is available then you do the same assuming UTF-8 as a default. Read the content via the InputStreamReader, either directly or indirectly, and you've got it. If you remember the encoding used to read the request data then you can apply the same encoding to the outbound response data. Do note, however, that this depends on the client either providing a correct character encoding specification or using the same encoding that the server assumes for a default (UTF-8). If the client, for instance, encodes the data with ISO-8859-1 but doesn't specify an encoding (perhaps because ISO-8859-1 is the default for HTTP) then your program will not behave as desired. If this is not satisfactory then you need to change the server design. John Bollinger [EMAIL PROTECTED] ========================================================================== TOPIC: How can I convert a String to an Int? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3a44aee4d751e576 ========================================================================== == 1 of 3 == Date: Mon, Oct 25 2004 8:52 am From: John Smith <[EMAIL PROTECTED]> Hi Java-Coder! I'am coding in Java for about an half year, but I still don't know how I convert a String to a Int. Can you help me? Thanks a lot! == 2 of 3 == Date: Mon, Oct 25 2004 9:19 am From: Jacob <[EMAIL PROTECTED]> John Smith wrote: > I'am coding in Java for about an half year, but I still don't know how I > convert a String to a Int. > Can you help me? try { int value = Integer.parseInt (string); } catch (Exception exception) { // It wasn't a number after all } == 3 of 3 == Date: Mon, Oct 25 2004 10:24 am From: Aquila <[EMAIL PROTECTED]> John Smith wrote: > Hi Java-Coder! > > I'am coding in Java for about an half year, but I still don't know how I > convert a String to a Int. > Can you help me? > > Thanks a lot! String myString = "42"; Integer myInt = newInteger(myString); ========================================================================== TOPIC: help with my first project on first job, how to read a strange file, thanks a lot!!!!!!! http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8c32ba1a17d68c9a ========================================================================== == 1 of 1 == Date: Mon, Oct 25 2004 8:59 am From: Paul Lutus <[EMAIL PROTECTED]> matt wrote: > here is a sample of the file. / ... snip unformatted text sample > this is IIS log file. i am not sure how to make hexdump. but the white > space is space bar. 1. If you want to become successful in computer programming, you need to adopt more strict thinking and reporting standards. For example, when you write sentences, pretend that your prose will be compiled by an "English" compiler, one that, just like a Java compiler, requires you to put in all the words you believe to be unimportant. 2. To solve this specific problem, even to describe the problem, you have to tighten up your thinking and writing. 3. Tell us exactly what you plan to do with the file, and exactly what is in it. The above pasted text leaves out some crucial information, because it is unformatted text. On carefully reading your posts, I must ask how much experience you have writing Java programs. Have you considered reading the file's lines and trimming whitespace from the lines before further processing? If you did this, the original problem you state wold most likely be solved (assuming your description is correct). Yo may be able to simply read input lines, trim whitespace using String.trim(), and emit the same lines, like this: java MyProgramName < inputfile | destination_application 5. Where is your code? I ask because we do not ordinarily write code to solve problems posted by programmers who do not post their own code, and we also do not do this, on principle, for students who do not post code. -- Paul Lutus http://www.arachnoid.com ========================================================================== TOPIC: reference to a jar file inside another jar file http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7dab58f45ecad79c ========================================================================== == 1 of 3 == Date: Mon, Oct 25 2004 9:20 am From: "JML" <[EMAIL PROTECTED]> Hi, I need create a manifest file for a jar, but I need set the classpath in the manifest file to reference a jar file inside the current jar file. My idea is getting a single jar file which contains all the needed jar files. == 2 of 3 == Date: Mon, Oct 25 2004 10:26 am From: Thomas Fritsch <[EMAIL PROTECTED]> JML wrote: > Hi, I need create a manifest file for a jar, but I need set the classpath in > the manifest file to reference a jar file inside the current jar file. My > idea is getting a single jar file which contains all the needed jar files. > Read <http://java.sun.com/j2se/1.4.2/docs/api/java/net/JarURLConnection.html> to get some clues about URLs for files inside a jar file. Having read this, I've got the vague idea, that an URL like jar:file:outerfile.jar!innerfile.jar contained in the manifest's classpath might do the trick. -- "Thomas:Fritsch$ops:de".replace(':','.').replace('$','@') == 3 of 3 == Date: Mon, Oct 25 2004 10:21 am From: Oscar kind <[EMAIL PROTECTED]> JML <[EMAIL PROTECTED]> wrote: > Hi, I need create a manifest file for a jar, but I need set the classpath in > the manifest file to reference a jar file inside the current jar file. My > idea is getting a single jar file which contains all the needed jar files. This is not possible IIRC: you'll have to copy the .jar files in the same directory as the current .jar file, or package their contents in the current .jar file. -- 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: Newbee Question about random numbers http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d5332da2a87b1a4a ========================================================================== == 1 of 1 == Date: Mon, Oct 25 2004 9:31 am From: Alex Hunsley <[EMAIL PROTECTED]> marcus wrote: > tor-- it is a kind of thing in this ng to not give homework answers, buddy > Can you please not top-post Marcus? ta alex ========================================================================== TOPIC: How to update Gui data from application code? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e5ed9fff31421c42 ========================================================================== == 1 of 2 == Date: Mon, Oct 25 2004 9:36 am From: Alex Hunsley <[EMAIL PROTECTED]> Dacleaver wrote: > So does this controller system consist strictly of using the Obeserver > pattern or is that just one type of implementation. Also, are you aware of > any example code that you could recommend to help understand it in a > practicle way. Yes, the observer (aka publisher/subscriber or listener) pattern is good. I'd avoid just implementing the Observer java interface though; make your own listener interfaces. More details here in an old thread: http://makeashorterlink.com/?P47822C99 Btw, can you not top-post please? It makes threads harder to follow. alex == 2 of 2 == Date: Mon, Oct 25 2004 9:39 am From: Alex Hunsley <[EMAIL PROTECTED]> Jacob wrote: > Dacleaver wrote: > >> So what is the proper way then to update your swing components from >> your application code? Or should you just overright a JPanels >> paintComponent() method to have it check for the data it needs from >> the application and then update it every single time a paint request >> is sent? > > > Seems like you've got the model vs. GUI separation right, which > is good. This is the "M" and "V" part of the MVC pattern. > > Don't touch the paintComponent() method (for this puropse at least). > Normally what you will do is to implement some (private) refresh() > method on your GUI classes which picks the relevant part of the > model and populates the GUI (setText(...), setSelectedItem(...) etc.). ... and which you should write such that it does the populating in the GUI thread (see SwingUtilities.invokeLater()). I wish sun had made it easier to do things the right way with regards to the event despatch/GUI thread... alex ========================================================================== TOPIC: singleton pattern http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2df0080c97ed1370 ========================================================================== == 1 of 5 == Date: Mon, Oct 25 2004 9:40 am From: "joe" <[EMAIL PROTECTED]> Typical i write my singletons like this: protected static MyClass singleton; protected MyClass() { } public static MyClass getInstance() { if( singleton == null ) { singleton = new MyClass(); } return singleton; } However on more than once occasion I've come across this: protected static MyClass singleton = new MyClass(); protected MyClass() {} public static MyClass getInstance() { return singleton; } Now for some reason the seconds way bothers me. I am not sure why ? Is there something to this ? Or I am just being stupid ? joe == 2 of 5 == Date: Mon, Oct 25 2004 9:52 am From: Lasse Reichstein Nielsen <[EMAIL PROTECTED]> "joe" <[EMAIL PROTECTED]> writes: > Typical i write my singletons like this: [lazy initialized singleton] > However on more than once occasion I've come across this: [singleton initialzed when class is loaded] > Now for some reason the seconds way bothers me. I am not sure why ? Is > there something to this ? Or I am just being stupid ? The difference between the two methods is that the latter creates the instance object when the class is loaded, and the former creates it the first time it is requested. The former has a small overhead each time the instance is requested, because it tests whether it is null. The latter is potentially wastefull if the instance is never requested. So, if you know that you *will* request the instance (and what other reason is there for loading a singleton class? :) then the latter is *probably* fine. You can even make the instance field "final" :) I also have an irrational preference for the lazily intialized singleton, but I can't think of any singleton class I have ever used, where I didn't request the singleton. /L -- Lasse Reichstein Nielsen - [EMAIL PROTECTED] DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html> 'Faith without judgement merely degrades the spirit divine.' == 3 of 5 == Date: Mon, Oct 25 2004 10:12 am From: Eric Sosman <[EMAIL PROTECTED]> joe wrote: > Typical i write my singletons like this: > > protected static MyClass singleton; > protected MyClass() { } > public static MyClass getInstance() { > if( singleton == null ) { > singleton = new MyClass(); > } > return singleton; > } > > However on more than once occasion I've come across this: > protected static MyClass singleton = new MyClass(); > protected MyClass() {} > public static MyClass getInstance() { > return singleton; > } > > Now for some reason the seconds way bothers me. I am not sure why ? Is > there something to this ? Or I am just being stupid ? First, I think you want `private' rather than `protected'. With the latter, it seems to me someone could do: class NoSingletonIsAnIsland extends MyClass { public static MyClass makeAnotherOne() { return new MyClass(); } } ... and proceed to make a million instances of your "singleton" class. As to your fundamental question, both approaches have their place. If constructing the MyClass instance is expensive and there's a reasonable chance you won't ever need one, your "lazy initialization" style makes sense. However, you'll need more bullet-proofing to make it thread-safe; imagine what would happen if thread T1 was busy in the MyClass constructor (it's assumed to be expensive, so the constructor will take a while) and T2 came along, found `singleton' still null, and started constructing another one ... The second pattern avoids the synchronization issues at the cost of *always* making a MyClass instance, which would be a shame if it were expensive and it turned out you didn't need one after all. There's a discussion of both these patterns and of some further variants in "Effective Java" by Bloch. -- [EMAIL PROTECTED] == 4 of 5 == Date: Mon, Oct 25 2004 10:11 am From: Babu Kalakrishnan <[EMAIL PROTECTED]> joe wrote: > Typical i write my singletons like this: > > protected static MyClass singleton; > protected MyClass() { } > public static MyClass getInstance() { > if( singleton == null ) { > singleton = new MyClass(); > } > return singleton; > } > > > However on more than once occasion I've come across this: > protected static MyClass singleton = new MyClass(); > protected MyClass() {} > public static MyClass getInstance() { > return singleton; > } > > Now for some reason the seconds way bothers me. I am not sure why ? Is > there something to this ? Or I am just being stupid ? > > The first way is not threadsafe - you might end up with more than one instance of the "Singleton" unless your accessor is synchronized. While the second example seems to create an instance even if the class in question is not used, it isn't normally so. Most JVMs don't load the class till some code makes a reference to it, and the instance will be created only during classloading. (And in almost all cases that I have encountered, the first access to a Singleton class is the getInstance() call) BK == 5 of 5 == Date: Mon, Oct 25 2004 10:22 am From: Gordon Beaton <[EMAIL PROTECTED]> On Mon, 25 Oct 2004 18:52:39 +0200, Lasse Reichstein Nielsen wrote: > [lazy initialized singleton] > The former has a small overhead each time the instance is requested, > because it tests whether it is null. It also has a race condition that can only be solved by explicit synchronization, missing from the example. > [singleton initialzed when class is loaded] > The latter is potentially wastefull if the instance is never > requested. Since the instance won't be created until the class itself is loaded (which won't happen until it is needed at runtime), where is the potential for waste? The Java classloading mechanism already provides lazy initialization. There is no need to implement it yourself in this case. /gordon -- [ do not email me copies of your followups ] g o r d o n + n e w s @ b a l d e r 1 3 . s e ========================================================================== TOPIC: javax.xml.transform.TransformerException http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/16ee0563542144eb ========================================================================== == 1 of 1 == Date: Mon, Oct 25 2004 10:02 am From: [EMAIL PROTECTED] (veny) Hi guys & girls, I am working on an application which will take all the required configuration from MAIN xml file and update those in the nearly 8 xml files. In the process, I was successfull implementing on the windows platform but when I want to do the same application on UNIX I am having problem with the paths. Though I am imposing the absoulte path for the newly created xml files using transformer object, I am ending up with "javax.xml.transform.TransformerException:java.io.FileNotFoundException: usr/local/Edre/adminserver/AdminServerConfig.xml (A file or directory in the path name does not exist.)" As you can see the path doesn't start with "/usr/local/..." but starts with "usr/local/...". I have no clue why this exception is thrown eventhough I am creating a file with absolute path. see the snippet of the code below, Source source = new DOMSource(doc); File file = new File(filename); File file1 = file.getAbsoluteFile(); Result result = new StreamResult(file1); Transformer xformer = TransformerFactory.newInstance ().newTransformer(); xformer.transform(source, result); }catch (TransformerConfigurationException e) { System.out.println("TransformerConfigurationException : " + e); }catch (TransformerException e) { System.out.println("TransformerException : " + e); } Can anyone let me know where I am doing wrong. Anyhelp in this matter would be greatly appreciated and thanks in advance. veny ========================================================================== TOPIC: applet's call comportement http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/cc1d4563dc67060c ========================================================================== == 1 of 1 == Date: Mon, Oct 25 2004 10:05 am From: "Emmanuel Freund" <[EMAIL PROTECTED]> Hi, I'm currently developping a web browser in java and I'd like to have the windows openned by some applets to be displayed in my own workspace and not the OS's one. If anybody have an idea, some clue, whatever, it would be of great help. -- Emmanuel ========================================================================== TOPIC: Regular expression problem http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/98669b754907f080 ========================================================================== == 1 of 1 == Date: Mon, Oct 25 2004 10:21 am From: "John C. Bollinger" <[EMAIL PROTECTED]> [EMAIL PROTECTED] wrote: > How I see it, is that you're specifying in your adjusted RE that it > should match an expression between <title> and </title> that contains: > Chinese characters; > the character '-' ; > the characters '<' and '>'. > > Try using <title>[^<]*</title>. Right, as far as I can tell, the part about matching Chinese characters is irrelevant -- Java doesn't treat them any differently from any other character. That revised RE should do much better, but it's not quite there yet. Given that this looks a lot like a homework, I'll just leave it there. John Bollinger [EMAIL PROTECTED] ========================================================================== TOPIC: Inner Class in EJB not found http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d3fb4eb0ebb4e93d ========================================================================== == 1 of 2 == Date: Mon, Oct 25 2004 10:26 am From: "John C. Bollinger" <[EMAIL PROTECTED]> Bruno Grieder wrote: > That is what happens with too comfortable IDEs! Indeed it is. > Time to go back to vim ;-) JCB's rule of programming number 6: If you don't know how to do it with ViM, you don't know how to do it. :-) John Bollinger [EMAIL PROTECTED] == 2 of 2 == Date: Mon, Oct 25 2004 10:43 am From: Bruno Grieder <[EMAIL PROTECTED]> John C. Bollinger wrote: > Bruno Grieder wrote: > >> That is what happens with too comfortable IDEs! > > > Indeed it is. > >> Time to go back to vim ;-) > > > JCB's rule of programming number 6: If you don't know how to do it with > ViM, you don't know how to do it. :-) That is so true (and I know it), but lazyness, lazyness.... mother of all sins (that is for our "Java is evil" friend) :-) > > > John Bollinger > [EMAIL PROTECTED] ========================================================================== TOPIC: Apache Referencing META-INF Directory http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c8128b3e03cc879b ========================================================================== == 1 of 1 == Date: Mon, Oct 25 2004 10:37 am From: [EMAIL PROTECTED] (Gary V) I am using apache 2.0 and when I attempt to load a Java jar file, from within an html page, it writes the following error message to the log file: File does not exist: /usr/local/apache2/htdocs/java/META-INF The Apache DocumentRoot directory is /usr/local/apache2/htdocs. I included a Meta file when creating the .jar file but then what causes Apache to access this directory? Gary V ========================================================================== TOPIC: sorting an ArrayList by int http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/127ea15b32732f1 ========================================================================== == 1 of 3 == Date: Mon, Oct 25 2004 10:49 am From: "zcraven" <[EMAIL PROTECTED]> I need to sort a football league by the number of points each club has. The clubs are objects stored in an ArrayList called 'league'. Each club has a field for the number of points they have. Can someone suggest the best way to sort this arraylist and output it to screen? Most examples on the web suggest I type: collections.sort(league) but i get the error that it expects an Array but has found an ArrayList. PLEASE HELP! :-) == 2 of 3 == Date: Mon, Oct 25 2004 10:59 am From: Joona I Palaste <[EMAIL PROTECTED]> zcraven <[EMAIL PROTECTED]> scribbled the following on comp.lang.java.programmer: > I need to sort a football league by the number of points each club has. The > clubs are objects stored in an ArrayList called 'league'. Each club has a > field for the number of points they have. > Can someone suggest the best way to sort this arraylist and output it to > screen? > Most examples on the web suggest I type: > collections.sort(league) > but i get the error that it expects an Array but has found an ArrayList. > PLEASE HELP! :-) There is a Collections.sort(List) method. Simply feed your ArrayList to it with Collections.sort(league). You have to make sure your club objects implement the Comparable interface though - otherwise you may end up with ClassCastExceptions, or a list that is not properly sorted. -- /-- Joona Palaste ([EMAIL PROTECTED]) ------------- Finland --------\ \-------------------------------------------------------- rules! --------/ "'I' is the most beautiful word in the world." - John Nordberg == 3 of 3 == Date: Mon, Oct 25 2004 11:11 am From: "zcraven" <[EMAIL PROTECTED]> when I type this line in class 'Club' I get the error 'club is not abstract and does not override abstract method compareTo': public class Club implements Comparable I have been stuck on this for 4 hours! Zac "Joona I Palaste" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > zcraven <[EMAIL PROTECTED]> scribbled the following > on comp.lang.java.programmer: > > I need to sort a football league by the number of points each club has. The > > clubs are objects stored in an ArrayList called 'league'. Each club has a > > field for the number of points they have. > > > Can someone suggest the best way to sort this arraylist and output it to > > screen? > > > Most examples on the web suggest I type: > > > collections.sort(league) > > > but i get the error that it expects an Array but has found an ArrayList. > > > PLEASE HELP! :-) > > There is a Collections.sort(List) method. Simply feed your ArrayList to > it with Collections.sort(league). You have to make sure your club > objects implement the Comparable interface though - otherwise you may > end up with ClassCastExceptions, or a list that is not properly sorted. > > -- > /-- Joona Palaste ([EMAIL PROTECTED]) ------------- Finland --------\ > \-------------------------------------------------------- rules! --------/ > "'I' is the most beautiful word in the world." > - John Nordberg ======================================================================= 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
