comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * Performance of null tests? - 4 messages, 4 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e1febd5672a2f269 * simplifying use of properties - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c8ec2d768fef49b3 * Newbie question about EJB-CMP: is it worth it when using multiple containers? - 5 messages, 4 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7783b0dd00f912fb * convert RSA keys - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/136546fb9c297e9a * Apache Axis and JDK1.5 - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/274cfa6bf37ead9b * regex replace \\ by \ - 3 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9f662bcf0fda45f7 * "Could not find main-class" - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/631c41f6c0ad1a67 * Print and print overview and current page - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8f9e247fc4ba1c27 * How can I change the location of the Web Start cache? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4aabb51e96392879 * java.net.SocketException: Insufficient buffer space - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7c9c56b240ed60b1 * Building an Exception Layer - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a8359d1a0e5422fb * Stupid null pointer exception - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/aeeebd0bb6f11be3 * Calendar.roll on december,31 !!!! - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ea6aea82ed17ba7a * newbie exceptions question - 3 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/80a2d1cab77381a * newbie compile question - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8de296cba22d3831 ========================================================================== TOPIC: Performance of null tests? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e1febd5672a2f269 ========================================================================== == 1 of 4 == Date: Thurs, Nov 4 2004 6:10 am From: Michael Borgwardt <[EMAIL PROTECTED]> Adam wrote: > I've just been having a discussion with a colleague and would be > interested to hear people's opinions on which of the below code > snippets would have the highest performance overhead. Answer: forget about premature optimization, write clean, understandable code. Using exceptions for control flow is BAD style. == 2 of 4 == Date: Thurs, Nov 4 2004 6:16 am From: Jacob <[EMAIL PROTECTED]> Adam wrote: > (A) > > if(badger == null) { > <do bad stuff> > } else { > <do good stuff> > } > > (B) > > try { > <do good stuff> > } catch (NullPointerException npe) { > <do bad stuff> > } Hopefully this is an academic discussion only? No matter what result you get from you performance study, NEVER EVER write your code as in (B). == 3 of 4 == Date: Thurs, Nov 4 2004 6:20 am From: "VisionSet" <[EMAIL PROTECTED]> "VisionSet" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > "Adam" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > I've just been having a discussion with a colleague and would be > > interested to hear people's opinions on which of the below code > > snippets would have the highest performance overhead. > > > > Assume that <do good stuff> would throw a NullPointerException if > > badger was null. > > > > (A) > > > > if(badger == null) { > > <do bad stuff> > > } else { > > <do good stuff> > > } > > > > (B) > > > > try { > > <do good stuff> > > } catch (NullPointerException npe) { > > <do bad stuff> > > } > > > > > > If badger is truly exceptionally null then (B) will be best because there is > no conditional to test and there will rarely be any overhead of throwing the > exception. > On the other hand if badger is often null then (A) would be better since > testing for null is very low overhead. Whilst throwing an exception is high > overhead. > Of course taking the wider perspective with performance aside, you should write code in such a way as to never need to catch RuntimeExceptions (eg NPE) at all. Checks such as (A) should be made to check for null where necessary and if at all possible disallow nulls as a precondition to a method by documenting and explicitly throwing NPE early. -- Mike W == 4 of 4 == Date: Thurs, Nov 4 2004 7:15 am From: Chris Smith <[EMAIL PROTECTED]> Jacob wrote: > Hopefully this is an academic discussion only? > > No matter what result you get from you performance > study, NEVER EVER write your code as in (B). Agreed that there is no reasonable circumstance where you'd cause a NullPointerException to be thrown and then catch it again in the same method. However, the general concept of choosing to allow NullPointerException to occur is a good one when the null input is not expected. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ========================================================================== TOPIC: simplifying use of properties http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c8ec2d768fef49b3 ========================================================================== == 1 of 1 == Date: Thurs, Nov 4 2004 6:16 am From: "John C. Bollinger" <[EMAIL PROTECTED]> kartik wrote: > Currently, use of (JavaBeans) properties requires manual calls to > getter & setter methods. "Manual" is an odd choice of words there. > Wouldn't it be better to extend the language > so that an expression "object.foo" (without a '()'), in the absence of > a field named foo, is treated as equivalent to a call to a > getter/setter method (depending on whether the property is being read > or written). Why would it be better? What do you expect to gain by this? I don't even see the problem you hope to solve. > I feel it would be better to do this *not* by a compile-time > transformation but by changing the spec of the getfield & putfield > instructions to invoke a getter/setter method when there is no > matching field. Then, classes can replace fields with properties (or > vice-versa) without hurting binary compatibility (for clients who > access the fields/properties using the "object.foo" syntax). If your basic idea were adopted then the compatibility features of your suggested implementation would be attractive, but their implementation would be a bit messy. More importantly, however, implementing this in the JVM would introduce a (Java convention) <-> (bytecode semantics) relationship that would be wholly inappropriate. Furthermore, although there would be compatibility advantages going forward, the suggested JVM change is _not_ fully binary compatible with existing classes because it does not reproduce the error behavior currently specified by the language and VM specs (and implemented by the current compiler / VM combination). The JVM, although designed to support Java, can and does support other languages. It's native language, bytecode, is a high-level OO language entirely of its own. In consideration of those facts I'd argue that it is entirely inappropriate to implement a change to Java language semantics by means of a change to bytecode semantics. John Bollinger [EMAIL PROTECTED] ========================================================================== TOPIC: Newbie question about EJB-CMP: is it worth it when using multiple containers? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7783b0dd00f912fb ========================================================================== == 1 of 5 == Date: Thurs, Nov 4 2004 6:16 am From: "Eugene Ostroukhov" <[EMAIL PROTECTED]> If you really need EJBs use BMP + some OR mapping like hibernate for persistance code. But than again - are you sure you need those EJBs anyway? "Andrea Desole" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm playing around with container managed persistence, and I noticed > that there is no standard that defines the mapping between beans and > databases. In fact, this is what the EJB specification says: > > "The Deployer, using the Container Provider s tools, determines how the > persistent fields and relationships defined by the abstract persistence > schema are mapped to a database or other persistent store, and generates > the necessary additional classes and interfaces that enable the > container to manage the persistent fields and relationships of the > entity bean instances at runtime." > > If it's true then I will have problems if I have an application that > supports multiple EJB containers, which is my case. So, my question is: > isn't it better to write just some normal SQL once and use bean managed > persistence, instead of writing and maintaining n different files (one > for each container) for the same mapping? How complex should my SQL be > to make CMP really valuable in this case? > Thanks > > Andrea == 2 of 5 == Date: Thurs, Nov 4 2004 7:09 am From: Andrea Desole <[EMAIL PROTECTED]> Actually, hibernate is not a bad idea. I was not thinking about using it with EJBs. I'll look at it. I haven't been working for a long time on this application, but I think yes, EJBs are needed, since there are more applications talking to each other, sometimes on different machines. Having to use a communication framework in a Java environment I don't think EJBs are a bad choice. Thanks for the tip Andrea Eugene Ostroukhov wrote: > If you really need EJBs use BMP + some OR mapping like hibernate for > persistance code. But than again - are you sure you need those EJBs anyway? > > "Andrea Desole" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>I'm playing around with container managed persistence, and I noticed >>that there is no standard that defines the mapping between beans and >>databases. In fact, this is what the EJB specification says: >> >>"The Deployer, using the Container Provider s tools, determines how the >>persistent fields and relationships defined by the abstract persistence >>schema are mapped to a database or other persistent store, and generates >>the necessary additional classes and interfaces that enable the >>container to manage the persistent fields and relationships of the >>entity bean instances at runtime." >> >>If it's true then I will have problems if I have an application that >>supports multiple EJB containers, which is my case. So, my question is: >>isn't it better to write just some normal SQL once and use bean managed >>persistence, instead of writing and maintaining n different files (one >>for each container) for the same mapping? How complex should my SQL be >>to make CMP really valuable in this case? >>Thanks >> >>Andrea > > > == 3 of 5 == Date: Thurs, Nov 4 2004 7:23 am From: Chris Smith <[EMAIL PROTECTED]> Andrea Desole wrote: > I'm playing around with container managed persistence, and I noticed > that there is no standard that defines the mapping between beans and > databases. In fact, this is what the EJB specification says: [...] > If it's true then I will have problems if I have an application that > supports multiple EJB containers, which is my case. You should be aware that the EHB specification was not written to allow randomly swapping the EJB container. The claim is that it was, but the reality is that various companies have a financial interest in encouraging you to buy into their platform as opposed to another, so a lot of the EJB spec is left up to the implementation or limited to the point that you're sometimes forced to rely on vendor extensions. EJB is a lot like SQL in this respect; it's possible to write portable code, but only if you don't have particularly advanced needs. So if you need to depend on the database schema from outside basic use of your CMP EJBs, then you've run into such a limitation. You can use BMP EJBs, perhaps with Hibernate as someone else suggested, or you can research each of your possible containers and determine how they do the persistence mapping, and then try to adapt all of them to one schema. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation == 4 of 5 == Date: Thurs, Nov 4 2004 7:44 am From: Andrea Desole <[EMAIL PROTECTED]> > You should be aware that the EHB specification was not written to allow > randomly swapping the EJB container. The claim is that it was, but the > reality is that various companies have a financial interest in > encouraging you to buy into their platform as opposed to another, so a > lot of the EJB spec is left up to the implementation or limited to the > point that you're sometimes forced to rely on vendor extensions. EJB is > a lot like SQL in this respect; it's possible to write portable code, > but only if you don't have particularly advanced needs. mmmmm, this is not really the concept of "write once run anywhere" I had in mind :-) > > So if you need to depend on the database schema from outside basic use > of your CMP EJBs, then you've run into such a limitation. You can use > BMP EJBs, perhaps with Hibernate as someone else suggested, or you can > research each of your possible containers and determine how they do the > persistence mapping, and then try to adapt all of them to one schema. > I have to say that, after a further discussion, I now know that a reason to use EJBs is also that EJBs allow a better control in the case that an object changes, because a notification is sent, so that all the other instances, on other machines (in case, for example, of a cluster) can be updated. I'm not sure Hibernate can do that, and I'm not sure it's possible to find a good framework that can (maybe JDO?) Maybe the best option is really to use plain BMP and SQL. == 5 of 5 == Date: Thurs, Nov 4 2004 8:06 am From: Sudsy <[EMAIL PROTECTED]> Andrea Desole wrote: <snip> > If it's true then I will have problems if I have an application that > supports multiple EJB containers, which is my case. So, my question is: > isn't it better to write just some normal SQL once and use bean managed > persistence, instead of writing and maintaining n different files (one > for each container) for the same mapping? How complex should my SQL be > to make CMP really valuable in this case? CMP EJBs are just another abstraction layer atop proprietary RDBMS interfaces. You write your queries in EJB QL rather than SQL and the mapping to the underlying data source is typically performed at deployment time. If you're performing complex transactions across multiple data sources then the J2EE features really come into play. CMR and the "order by" clause (missing from the first version) handle much of the complexity you would have to manage explicitly with BMP. IMHO it depends on the complexity of your app. There are certainly alternatives; DAOFactory immediately comes to mind. Once you get to a point where you're explicitly managing transactions and relation- ships, you might have reached the juncture where CMPs can simplify your life (not to mention your coding ;-). -- Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development. ========================================================================== TOPIC: convert RSA keys http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/136546fb9c297e9a ========================================================================== == 1 of 2 == Date: Thurs, Nov 4 2004 6:20 am From: Sudsy <[EMAIL PROTECTED]> CP wrote: <snip> > //PROBLEM! how to convert the above key into publicKey object? > rsaCipher.init(Cipher.ENCRYPT_MODE, pub); Public key and modulus in BigInteger form -> RSAPublicKeySpec -> KeyFactory -> PublicKey. Anything more and I'll have to charge you. I won't apologize for that either. Crypto is one of the most difficult and time-consuming areas of Java I've yet encountered. There's a huge amount of background knowledge you have to acquire before the myriad of classes begin to make sense. -- Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development. == 2 of 2 == Date: Thurs, Nov 4 2004 7:00 am From: Chris Smith <[EMAIL PROTECTED]> CP wrote: > I've created a pair of keys in c and use in java RSA encryption. > > //public and private key which created in C > byte[] pubKey = { [...] }; > // initiate a cipher > Cipher rsaCipher = Cipher.getInstance("RSA", "BC");// Initialize the cipher > for encryption > > //PROBLEM! how to convert the above key into publicKey object? > rsaCipher.init(Cipher.ENCRYPT_MODE, pub); Okay, gotcha. You will need a KeySpec for your key. You can create a RSAPublicKeySpec with the public constructor, which takes a modulus and exponent. Alternatively, if you have your key in an X.509 encoded form, then use X509EncodedKeySpec instead. The latter is probably the easiest code by far, since you don't need to convert anything; so if you can get whatever key representation you need, then I'd shoot for X.509. Once you have the KeySpec, just do: pub = KeyFactory.getInstance("RSA").generatePublic(keySpec); > // Initialize the same cipher for decryption > //PROBLEM! how to convert the above key into privateKey object? > rsaCipher.init(Cipher.DECRYPT_MODE, priv); Same answer as above, but just use RSAPrivateKeySpec instead of RSAPublicKeySpec if you go with modulus and exponent, use PKCS8EncodedKeySpec instead of X509EncodedKeySpec if you encode your keys, and use generatePrivate instead of generatePublic. I've only done this with DSA, but I see no reason it won't work with RSA. Here is some code for both sides and using encoded keys and DSA: public static PublicKey getDSAPublicKey(String resource) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException { ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream in = LicenseUtil.class.getClassLoader() .getResourceAsStream(resource); if (in == null) throw new IllegalArgumentException( "Key resource not found"); try { byte[] buffer = new byte[32768]; int len; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } } finally { in.close(); } X509EncodedKeySpec keySpec = new X509EncodedKeySpec( out.toByteArray()); return KeyFactory.getInstance("DSA").generatePublic(keySpec); } public static PrivateKey getDSAPrivateKey(String resource) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException { ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream in = LicenseManager.class.getClassLoader() .getResourceAsStream(resource); try { byte[] buffer = new byte[32768]; int len; while ((len = in.read(buffer)) != -1) { out.write(buffer, 0, len); } } finally { in.close(); } PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec( out.toByteArray()); PrivateKey key = KeyFactory.getInstance("DSA") .generatePrivate(keySpec); return key; } -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ========================================================================== TOPIC: Apache Axis and JDK1.5 http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/274cfa6bf37ead9b ========================================================================== == 1 of 1 == Date: Thurs, Nov 4 2004 6:22 am From: Jacob <[EMAIL PROTECTED]> I have downloaded axis1.2rc and try to compile with the 1.5 compiler and it fails because Axis (still) uses "enum" as a package name. ("enum" is a reserved word in Java 1.5; Its introduction has been known for a very long time). Can I conclude that Apache Axis is a dead project? What are alternative libraries for Soap access? Thanks! ========================================================================== TOPIC: regex replace \\ by \ http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9f662bcf0fda45f7 ========================================================================== == 1 of 3 == Date: Thurs, Nov 4 2004 6:22 am From: "John C. Bollinger" <[EMAIL PROTECTED]> Alan Moore wrote: > The backslash character is special in both the regex and the > replacement string, so it has to be double escaped in both places. Oops, right you are. I overlooked the fact that the replacement string, although not a regex, is nevertheless not treated as an opaque replacement. John Bollinger [EMAIL PROTECTED] == 2 of 3 == Date: Thurs, Nov 4 2004 6:34 am From: "John C. Bollinger" <[EMAIL PROTECTED]> Stephan Ehlert wrote: > thanks for your fast replies. But unfortunately none of your solutions > solves my problem. I have written a second example. We understand your problem. You are mistaken about not having a solution. Your test is buggy. > The String > "someText\\nsomeText2" > has to be replaced by "someText\nsomeText2" , so that someText2 is > written to a new line when I write the whole String into a file. > Note that the replacement shouldn't work with \n only, but with other > expressions like \t, too. > > Thanks, Stephan > > The code: > class XYZ { > > public static void main(final String[] args) { > > String s = "someText\\nsomeText2"; The above string literal represents a String containing only *one* backslash, represented in the source code as "\\". Did you actually look at the output of the println() below? > System.out.println(s); [...] > // s = s.replaceAll("\\\\\\\\", "\\\\"); // no match That doesn't match because your test string does not meet your criteria. Here is a modified code that demonstrates the above solution working perfectly, as far as I understand your requirements: public class ReplTest { public static void main(final String[] args) { String s = "someText\\\\nsomeText2"; System.out.println(s); s = s.replaceAll("\\\\\\\\", "\\\\"); System.out.println(s); } } And here is a transcript of one run of that program: D:\temp\testdir>java -cp . ReplTest someText\\nsomeText2 someText\nsomeText2 As I wrote before, backslashes are tricky. John Bollinger [EMAIL PROTECTED] == 3 of 3 == Date: Thurs, Nov 4 2004 6:31 am From: Morten Alver <[EMAIL PROTECTED]> > thanks for your fast replies. But unfortunately none of your solutions > solves my problem. I have written a second example. The String > "someText\\nsomeText2" > has to be replaced by "someText\nsomeText2" , so that someText2 is > written to a new line when I write the whole String into a file. > Note that the replacement shouldn't work with \n only, but with other > expressions like \t, too. Here you are: s.replaceAll("\\\\n", "\n"); This worked when I tested it. The problem is that "\n" is a single character, so the "n" must be treated together with the "\". -- Morten ========================================================================== TOPIC: "Could not find main-class" http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/631c41f6c0ad1a67 ========================================================================== == 1 of 1 == Date: Thurs, Nov 4 2004 6:42 am From: Tarlika Elisabeth Schmitz <[EMAIL PROTECTED]> Andrew Thompson wrote: >>Plus there is nothing more annoying than finding someone with the same >>problem in the archive but no solution. > > > How about... "Thanks anyway - solved it." ;-) > Exactly ;-) -- Regards/Gruß, Tarlika ========================================================================== TOPIC: Print and print overview and current page http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8f9e247fc4ba1c27 ========================================================================== == 1 of 1 == Date: Thurs, Nov 4 2004 6:48 am From: [EMAIL PROTECTED] (Bernard Segonnes) Hi, I will have several pages to print. I need to have an overview of 1 page at the time (in a JPanel), and the possibility to use the same JPanel to display another page. This JPanel will be able to print all pages. 1)Is it possible to use the same method (drawPage() ) to print 1 page (called from print() and from paint() ) ? 2) How can I know the page number I have to display in paint() ? 3) How do I know how to create a new page ? 4) How can I count the number of pages before printing (in the oveview on the screen) ? book = new Book(); printAndOverview = new PrintAndOverview(); book.append(printAndOverview,myPageFormat); job.setPageable(book); .... private class PrintAndOverview extends JPanel implements Printable { public PrintAndOverview() { super(); setVisible(true); } public int print(Graphics g, PageFormat format, int pageIndex) { super.print( g); drawPage((Graphics2D) g); return Printable.PAGE_EXISTS; } public void paintComponent(Graphics g) { super.paintComponent(g); drawPage((Graphics2D) g); } private void drawPage(Graphics2D g2){ g2.drawString("page number XXX",10,10); .... a lot of stuff }// drawPage() } Thanks for your help ========================================================================== TOPIC: How can I change the location of the Web Start cache? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4aabb51e96392879 ========================================================================== == 1 of 1 == Date: Thurs, Nov 4 2004 6:56 am From: Tarlika Elisabeth Schmitz <[EMAIL PROTECTED]> Hello, In case you're reading this, Andrew, I've got a new challenge for you: (I heard on the grape-vine that you're a bit of a WebStart specialist ;-) ) Most of the WebStart docs I have found seem to refer to older versions and therefore some of the tips I've seen don't work. I am running 1.4.2 The webstart cache is normally installed per user, not per system. On Linux, the cache is located somewhere in $HOME/.java, and on Windoze somewhere in the application folder. I want to use WebStart for an Intranet application, more or less as a convenience: rather than having to install every new release on X machine, I'll just pop it on the local server. 1) I want to pre-install the cache and provide an icon to the application (desktop integration). I guess, I'll just have to do this by hand for the first installation. Or does anyone have a better idea? 2) I would like to choose a different location for the cache (per system rather than per user). Somewhere I saw the tip to change the following property: javaws.cfg.cache.dir=c:/Programme/JavaSoft/JWSCache I think there used to be a javaws.cfg file but there isn't any longer. Where are all these settings stored now? -- Regards/Gruß, Tarlika Elisabeth Schmitz ========================================================================== TOPIC: java.net.SocketException: Insufficient buffer space http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7c9c56b240ed60b1 ========================================================================== == 1 of 1 == Date: Thurs, Nov 4 2004 7:10 am From: "John C. Bollinger" <[EMAIL PROTECTED]> Jeff wrote: > The exception was thrown by the BufferedInputStream read. The > ServerSocket.accept() completed and we are reading from the input stream > when the problem occurs. It is conceivable that it is the network stack's packet queue that is filling up. The network stack may be signaling that or some other error condition on the socket that is not directly related to the current read attempt. It is also conceivable that the native network stack does not signal a failure to allocate the send and receive buffers until the first attempt to read from the socket, or that the Java Socket implementation does not pass on the error until a read attempt it made. > We made the BufferedInputStream one meg to reduce the number of reads and > off-load message reassembly. Our proprietary messages can be up to one meg. > Rather than do multiple reads, then reassemble the packet, we let > BufferedInputStream assemble the packet. Faster and less to debug. But it doesn't work that way. The BufferedInputStream will never be able to read more from the socket at one go than the capacity of the socket's receive buffer. The BufferedInputStream will not request additional bytes from the socket until it needs to satisfy a request for more bytes than are waiting unread in its own internal buffer. Thus, as Esmond said, it is of negligible value to give the BufferedInputStream a buffer larger than the socket's receive buffer. That doesn't mean you can't perform an efficient read without copying. This is a perfect case for performing your own buffering instead of using a BufferedInputStream. Here's an example that actually does what you thought your BufferedInputStream was doing for you. final static int BUF_SIZ = 1024000; [...] InputStream bytesIn = mySocket.getInputStream(); byte[] buffer = new byte[BUF_SIZ]; int total = 0; for (int numRead = bytesIn.read(buffer, total, BUF_SIZ - totalRead); numRead > 0; numRead = bytesIn.read(buffer, total, BUF_SIZ - totalRead)) { total += numRead; } After buffering the whole message you can hand it off as the byte array + number of bytes, or wrap it up in a suitably configured ByteArrayInputStream to package those into a single object. Do note that if messages tend to be smaller than the maximum then you are wasting memory. Unless you can determine the message size before allocating the buffer, you have an unavoidable space / speed tradeoff going on here. > Once the tcp receive buffer fills, it should not accept more packets. That > should be communicated to the sender by reducing the size of the receive > window in the tcp header. This is an ancient, reliable mechanism. Which is apparently not working. > I think the problem lies in how the JVM accesses the tcp receive buffer. I > hoped to find more information on the interaction of the JVM with the tcp > stack. > > To the most recent post, we are running on SuSE linux. We use JRockit. I can't speak specifically to JRockit, but it is highly unlikely to be messing about with the TCP implementation. If it accesses the network stack by anything other than the standard system API then I would complain to the vendor. It is conceivable that the VM or the ServerSocket implementation is setting TCP options that you did not explicitly ask for, but before I spent much effort in that direction I would try to reduce the probability that the problem is at system level. It shouldn't be too hard to write a bit bucket TCP service in C against which you could run your probe to see whether the network stack behaves similarly. John Bollinger [EMAIL PROTECTED] ========================================================================== TOPIC: Building an Exception Layer http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a8359d1a0e5422fb ========================================================================== == 1 of 1 == Date: Thurs, Nov 4 2004 7:34 am From: Chris Smith <[EMAIL PROTECTED]> Rizwan wrote: > ok so all four exceptions has to be inherited from BaseException. thanks > One more comment: assuming that these exceptions will generally be handled from outside your library, BaseException is a really poor name. Why not name it after the API or framework? That way, it's immediately obvious where the exception comes from when you're reading client code. For example, JavaMail throws MessagingException, and the java.io package throws IOException as a base class for their respective exceptions. You are thinking as a library implementor instead of a library user, and threatening to create a mess for your users. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ========================================================================== TOPIC: Stupid null pointer exception http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/aeeebd0bb6f11be3 ========================================================================== == 1 of 1 == Date: Thurs, Nov 4 2004 7:46 am From: Alex Hunsley <[EMAIL PROTECTED]> Tony Morris wrote: >>Good! > > > She knows. I know. ========================================================================== TOPIC: Calendar.roll on december,31 !!!! http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ea6aea82ed17ba7a ========================================================================== == 1 of 1 == Date: Thurs, Nov 4 2004 7:58 am From: Alex Hunsley <[EMAIL PROTECTED]> Thomas Weidenfeller wrote: > Gianni wrote: > >> I have to add one day to the "today". >> >> In fact on 2004-dec-31 I have 2004-jan-1 >> >> I use : >> Calendar calendar = Calendar.getInstance(Locale.GERMANY); >> calendar.roll(6, 1); >> >> but obviously does not work on dec,31... > > > It works according to the specification. What about spending a minute or > two and reading the API documentation? > >> any idea how to fix it??? > > > By using the method which is supposed to do what you want to do. > > BTW: I think it is rather uncool to use the number literal 6 instead of > the predefined constant to address the field. It's definitely error prone. The constants allow you to not worry about whether monday or sunday is the first day, and if the first day is 0 or 1, etc. la, la.... ========================================================================== TOPIC: newbie exceptions question http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/80a2d1cab77381a ========================================================================== == 1 of 3 == Date: Thurs, Nov 4 2004 7:58 am From: Nandan <[EMAIL PROTECTED]> java -classpath WizTest_fat.jar bm.Tests.TestDiv tests/divtest4.xml Exception in thread "main" java.lang.NoClassDefFoundError: bm/Tests/TestDiv > It might be worthwhile to catch this exception in the program and > offer a more informative error message. am I correct in thinking the following? That will not work. There is no way to catch that exception, as I understand it. It isn't even a 'real' exception, as none of our code has been executed at that point. It is really an error message from the java interpreter to say it couldn't find the file. I may be wrong on this though, I will check. == 2 of 3 == Date: Thurs, Nov 4 2004 8:02 am From: Andrea Desole <[EMAIL PROTECTED]> Nandan wrote: > java -classpath WizTest_fat.jar bm.Tests.TestDiv tests/divtest4.xml > Exception in thread "main" java.lang.NoClassDefFoundError: bm/Tests/TestDiv > > > >>It might be worthwhile to catch this exception in the program and >>offer a more informative error message. > > > am I correct in thinking the following? > > That will not work. There is no way to catch that exception, as I understand > it. It isn't even a 'real' exception, as none of our code has been executed > at that point. It is really an error message from the java interpreter to > say it couldn't find the file. I may be wrong on this though, I will check. > > Well, considering that the class hasn't been found I don't see how its code can be executed. No, probably it wouldn't work Andrea == 3 of 3 == Date: Thurs, Nov 4 2004 8:07 am From: Nandan <[EMAIL PROTECTED]> Andrea Desole wrote: >> That will not work. There is no way to catch that exception, as I >> understand it. It isn't even a 'real' exception, as none of our code has <snip> >> > Well, considering that the class hasn't been found I don't see how its > code can be executed. > No, probably it wouldn't work > > Andrea So rather than call it an exception, is it more correct to say it's an interpreter error message? Thanks, Nandan ========================================================================== TOPIC: newbie compile question http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8de296cba22d3831 ========================================================================== == 1 of 1 == Date: Thurs, Nov 4 2004 8:01 am From: Nandan <[EMAIL PROTECTED]> I have a set of .java files in a directory hierarchy (organized according to their respective packages) under src. How can I use the java command line compiler to compile all the relevant files? I know of the javac -d bin *.java trick that populates a bin directory in a package-appropriate way. after that I can simply run jar cf bin with some extra options. Is there some way to make the java compiler recursively compile all the .java files belonging to the src dir's package hierarchy? Thanks a lot, N ======================================================================= 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
