| Doing one last thing to a WeakReference |
|
 |
Index ‹ java-programmer
|
- Previous
- 2
- Newbie:Please suggest ebook or any reading material for creating rich clients interfaces in javaWhile googling I found a very interesting presentation on creating
amazing GUI's in java on this link -
http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-3548&yr=2007&track=2
. I was very much impressed and really want to read and learn more on
developing such interfaces. So please suggest some reading material
for this.
I know core java and basics of swing.
Still learning java..:)
- 3
- [OT] SourceForge AddReleaseTaskOfftopic: A question about HTTPS / Java:
I'm writing an Ant task to automate the SourceForge 'Add release' procedure.
For this I'm using Jakarta Commons Net and HttpClient.
The task can be used in an Ant build file as follows:
<taskdef name="sfaddrelease"
classname="org.xins.util.ant.sourceforge.AddReleaseTask"
classpath="xins-common.jar:commons-net.jar:commons-httpclient.jar"
/>
<sfaddrelease
user="znerd"
password="${password}"
file="build/xins-${version}.tar.gz"
group="71598"
package="71219"
release="${version}"
/>
The login is done using HTTPS. The Commons HttpClient library supports this.
But apparently, the server is not trusted, because I get a
javax.net.ssl.SSLHandshakeException. The message is:
"java.security.cert.CertificateException: Could not find trusted
certificate"
Apparently, I need to get the certificate of sourceforge.net and store it in
a keystore. Perhaps I should use 'keytool -import' for this, in some way.
Questions:
* How do I get the certificate of sourceforge.net?
* How do I store it in a file so that Java will accept it?
Ernst
_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"
- 4
- JTree with dynamically adjusted row height during editing.I have extended JTable so that the installed editor for a cell checks
at each keystroke whether it must adjust the row height in order to fit
the content in the cell. This is easy to do with a document listener
which just starts a thread on each insertion to check for a height
change, and then calls setRowHeight on the appropriate row.
However, it does not seem to be so simple to do the same thing with a
JTree. setRowHeight cannot be called on a specific row, and with
rowHeight set to 0, the tree cells are only resized when the tree
manager itself queries the height. There does not appear to be a way
to get the editor to do this directly.
Does anyone know how to get this effect? It allows for something much
like a regular text outliner using JTree and I would think lots of
people would have wanted to do this in the past, but I havent found
evidence that it has been done.
- 5
- AES-RijndaelI am doing an entry in the Java glossary on AES aka
Rijndael symmetric cipher.
I wonder if anyone knows of opensource Java implementations.
see http://mindprod.com/jgloss/aes.html
for what I have discovered so far.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
- 5
- 9
- A specific external package import from javacWhich file(s) are required?
Where should these file(s) go?
What's the javac syntax to compile Test16 into ...\class\?
Given this directory structure:
C:\java\java\jTidy\Test16.java
C:\java\org\w3c\
C:\java\class\
Given that Test16.java has this import:
import org.w3c.tidy.Tidy;
SSCE @ <http://thufir.lecktronix.net/java/Test16.java>
Here's what I've gleaned from the 'net:
C:\java> javac -d . org\w3c\* C:\java\java\*
Clearly not correct, but that's my best effort at this point :(
thank you,
Thufir Hawat
- 10
- Synth L&F as jarHello,
i am trying to build a L&F basedf on Synth but now i have problems
using the L&F in another project. I pack the L&F into jar add it to a
projects classpath but it is not possible to access the images
contained in the jar. I know that resources from a jar should be
accessed by:
MyResourceBase.class.getResource("path/relative/to/the/MyResourceBase.png")
the problem is that its not me who accesses the images but synth. AND
when i look into synths code the images should be loaded by:
new ImageIcon(url, null).getImage()
with url is the return of:
private URL getResource(String path) {
return _resourceBase.getResource(path);
}
That looks correct to me but it does not work. Has anyone build his
synth L&F and got it to work from a jar? If that does not work, what is
a custom L&F good for if it can not be deployed as a jar?
I am very thankfull for all hints
Harri E.
- 12
- using importI'm trying to import the Welomb class in the java divelog tutorial into
another application. But when I type import divelog.* it refuses
the absolute path for Welcome is
d:\Documents\Java\Divelog\src\divelog
the application I'm trying to import it from is at
d:\Documents\Java\Frames\src\frames
I've also tried creating a library (MyLibrary) and pointing to the
divelog.jar file and setting the classpath to point at divelog.jar. I've
then added the library to my project but when I try and create a Welcome
class it says it cant find the class. So neither using a library or
importing work.
I'm using sun java studio enterprise8 (free) does anyone know how to import
the divelog package into my app using an import statement.
I've tried the following with no success
import divelog.*
import Documents.Java.Divelog.src.divelog.*
in both cases I get package diesnt exist
any suggestion welcome!!
- 13
- M-I 5-Persecution . my resp onse to the harass ment-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-= my response to the. harassment -=
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
My first reaction in 1990/91 was to assume that. if I broke contact then
they would not be able to follow and would lose interest.. So I did the
things that have been suggested by other people; I sold my. television,
stopped listening to the radio and tried. to withdraw away from the sources
of abuse as much as possible. I reasoned that. they must have more important
things. to deal with and that normal people would simply leave me alone if
it. were made difficult for them to continue their harassment.
I reckoned without the sheer vindictiveness of the abusers. They. did not
let up. but instead "got to" people around me, mainly people at work, to do
their dirty work for them. I went to see my GP, who refused to. believe what
he was being told, and. refused to direct me on to anyone who could be of
practical assistance. It was not until three. years had passed that the GP
admitted the matter was. outside his competence and suggested going to the
police.
In the summer of 1994 we called in. counter-surveillance experts from a
private detective agency to sweep our house and telephone for. bugging
devices. They conducted. a thorough search and found nothing; but as noted
above, since the existence of surveillance was being. forced in my face by
the harassers, you would expect. them to have taken the possibility of a
counter-surveillance sweep into account when. planning the type of devices
to. be employed.
In Easter 1995 I made a complaint to. my local Police station in London, but
the police have not expressed any intention to do anything about. the
continuing harassment ("we're not saying it's. happening and we're not
saying it isn't. happening" were the words used). I think the officer I
spoke to at Easter wasn't aware of it happening, although other members. of
the police force obviously do. know.
From April 1995 until the present time the. matter has been discussed in a
lot of detail on the Usenet (Internet) "uk.misc" newsgroup.. That discussion
has. given birth to the article which you are now reading. My hopes in
posting to Usenet were that. wider publicizing would discourage the security
services from continuing their harassment, and "draw. people out" into
concurring with the truth of what was being said. Neither of. those have
followed, but the discussion has served a purpose in allowing. this
structured. report to be created.
8322
- 13
- McNealy should have watched "Godfather 3" -- "Never hate your enemies, it clouds your judgement.""The worst thing about this deal is that Sun brought it upon itself
through a campaign of ridicule and hate promulgated personally by CEO
Scott McNealy. This is McNealy's failure and nobody else's. The quotes
last week from McNealy were laughable, the about face nothing short of
shameful. How are Sun's big customers going to believe what the company
says in the future in the face of such a change? How can they base huge
technical investments on the word of Sun?"
Answer: They can't. They never could.
http://www.pbs.org/cringely/pulpit/pulpit20040408.html
- 13
- Piped stream help.Hi Everyone,
I have two servlets that both need access to a data file. I would like to
have a 'driver' program that takes care of writing / reading objects to the
data file and i would like the driver program to be able to communicate
objects to each servlet. Can i do this w/ pipedinput / output streams? I do
not understand how i can reference a piped output stream in one object from
another!
TIA, Andrew.
- 16
- JNI: call C-main program from JavaI have a C-program which calls Java functions through JNI.
The C-part runs okay, and I want to debug the Java code.
For that reason, I want to start the Java debugger and then start the
C-main program through JNI. After that I hope I can set
breakpoints within the Java part and start debugging.
In the documents I saw that "System.LoadLibrary()" can load
only DLL's and shared object, but no main-program.
Thanks for any help,
Josef
- 16
- AffineTransform.getScaleInstance questionHi,
I am using the AffineTransform.getScaleInstance to transform an image
by showing it growing. i.e. something like the following:
while(scale <= 1) {
repaint();
scale += 0.05;
try {
Thread.sleep(25);
}
catch(InterruptedException e) {
e.printStackTrace();
}
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setComposite(AlphaComposite.SrcAtop);
g2.transform(AffineTransform.getScaleInstance(scale, scale));
g2.fill(clipShape);
g2.dispose();
}
the problem is that the image grows large from the top lefthand corner
towards the bottom right hand corner.
What I want is the image to grow from the bottom left hand corner to
the top right hand corner.
I have tried messing with the Scale instance, but I cant seem to figure
it out.
anyone know how to do this? thanks!
- 16
- JSP, forward, include, dispatch rules ?Can I get a clear summary of the rules involved with these ?
forward, include, RequestDispatcher rd
<jsp:include page="servlet/MyServlet" flush="false" />
rd.forward(req, res);
<jsp:forward page="NextPart.jsp" />
response.sendRedirect("NewPage.html");
What I have seen, is that this Error occurs:
'IllegalStateException: Cannot forward after response has been
committed'
When a JSP/Servlet writes to the page using a PrintWriter and then
tries to do a forward.
Maybe the following also cause problems:
response.setContentType(...)
response.setHeader(...)
TIA for your help, suggestions; Please Advise.
- 16
- Improving hashCode() to match equals()In my NamedBitField class I define equals() to mean that 2
NamedBitFields are equal if all 3 of their fields are equal.
Any suggestions for improving my hashCode() definition? I
can improve its performance by caching the computed hashCode
in a transient field, sure, but can I improve the _way_ it's
computed?
class NamedBitField {
String name; // name of bit field
int startIndex; // where it starts
int length; // how many bits it occupies
pubic boolean equals(Object obj) {
if (this == obj)
return true;
if ( obj == null || this.getClass() != obj.getClass() )
return false;
NamedBitField other = (NamedBitField) obj;
return
this.name.equals(other.name) &&
this.startIndex == other.startIndex &&
this.length == other.length;
}
public int hashCode() {
// to make this symmetric with equals() I'd prefer to
// involve all 3 fields (name, startIndex and length)
// in the computation of the hash. But how?
//
// Here I'm simply reusing String.hashCode(), but the
// hashed String at least incorporates the other
// fields
return ((name + startIndex) + length).hashCode();
}
}
Marco
----------------------------------------------------
Please remove digits from e-mail address (tr/0-9//d)
|
| Author |
Message |
Paul J. Lucas

|
Posted: 2008-6-26 13:11:00 |
Top |
java-programmer, Doing one last thing to a WeakReference
Lew wrote:
> Paul J. Lucas wrote:
>> Lew wrote:
>>>
>>> This is not a flaw in Java.
>>
>> Yes it is.
>
> No, it isn't.
Real compelling argument there. Java programmers need to stop being in denial
and admit that Java has flaws just like every other language.
- Paul
|
| |
|
| |
 |
Paul J. Lucas

|
Posted: 2008-6-26 13:11:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
Lew wrote:
> Paul J. Lucas wrote:
>> Lew wrote:
>>>
>>> This is not a flaw in Java.
>>
>> Yes it is.
>
> No, it isn't.
Real compelling argument there. Java programmers need to stop being in denial
and admit that Java has flaws just like every other language.
- Paul
|
| |
|
| |
 |
Paul J. Lucas

|
Posted: 2008-6-26 13:13:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
Lew wrote:
> Paul J. Lucas wrote:
>> Mark Space wrote:
>>
>>> Try-catch-finally. The "finally" portion is always run.
>>
>> No it's not:
>>
>> try {
>> // ...
>> if ( catastrophe )
>> System.exit( -1 );
>> }
>> finally {
>> // not executed if catastrophe == true
>> }
>
> Eschew System.exit(), especially in try blocks.
That doesn't invalidate my point. And it should be used when appropriate.
That's why Java has shutdownHooks.
- Paul
|
| |
|
| |
 |
Lew

|
Posted: 2008-6-26 20:47:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
Paul J. Lucas wrote:
> Lew wrote:
>> Paul J. Lucas wrote:
>>> Lew wrote:
>>>>
>>>> This is not a flaw in Java.
>>>
>>> Yes it is.
>>
>> No, it isn't.
>
> Real compelling argument there. Java programmers need to stop being in
> denial and admit that Java has flaws just like every other language.
It does not follow from the existence of flaws in the language, which no one
denies, btw, that the lack of a guaranteed dispose() for every object is such
a flaw.
For you it's a flaw because apparently you don't want to write this particular
corner case yourself. You want the language to bear the burden of your
specific need. You call this a flaw in the language itself. I call it lazy
greed.
--
Lew
|
| |
|
| |
 |
Tom Anderson

|
Posted: 2008-6-26 22:23:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
On Wed, 25 Jun 2008, Paul J. Lucas wrote:
> Lew wrote:
>
>> You make it sound like Java's fault. No language nor its library will
>> have all your use cases coded for you; at some point you will have to
>> write your own solution.
>>
>> This is not a flaw in Java.
>
> Yes it is. In Java, you have very limited ways you can interact with
> the garbage collector. If one of the ways, say WeakReferences as is the
> case here, doesn't do what you want, you're just plain out of luck.
>
> In C++, however, I could easily code my own reference-counted class and
> destructors and get exactly the behavior I want (thanks to, among other
> things, stack allocation of objects that permit the "resource acquisition is
> initialization" technique).
Okay: any time you can use RAII in C++, you can use an explicit close,
perhaps ensured by a try-finally, in java. Yes, in Java, you have to write
the close explicitly. Boo hoo.
> It's a perfectly reasonable (and common) thing to want to:
>
> a) guarantee an object is destroyed as soon as it's no longer used (and not
> "some later time").
>
> b) do one last thing to an object before it's destroyed.
>
> Java simply doesn't let you do those.
Yes, it does. It just doesn't give you a way to do it automatically. I
agree that this is a shame - i believe C# has a 'with' construct that lets
you do RAII, and i think that's a good feature. But it's hardly a
showstopper.
tom
--
Hesgadin. It was in two parts - both of them silent. I remember this map
came with a letter accusing me of stealing eggs. I had never understood
the relationship of the map to the accusation. I still don't, but I'm
grateful for the map.
|
| |
|
| |
 |
Tom Anderson

|
Posted: 2008-6-26 22:26:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
On Wed, 25 Jun 2008, Daniele Futtorovic wrote:
> On 2008-06-25 22:23 +0100, Paul J. Lucas allegedly wrote:
>> Tom Anderson wrote:
>>> I was thinking you'd do reference counting explicitly, using the 'destroy'
>>> or whatever method in the session objects to do a decrement on the
>>> relevant HotelHandle.
>>
>> That's just it: for my use case, I *can't* do it explicitly because I
>> have no way of knowing if my resource is either currently in use or
>> will be used again in the not-too-distant future (because some
>> code/object somewhere still has a hard reference to it).
>>
>> For the record, the use-case is as follows. I have some class
>> (ImageInfo) that reads image files (possibly very large image files).
>> As part of the class's implementation, it opens a RandomAccessFile on
>> the image and reads "chunks" of the file into memory. (The "chunks"
>> themselves are held by SoftReferences -- a SoftChunkyByteBuffer -- and
>> this part works fine.)
>>
>> The class has many methods, each of which accesses different parts of
>> the image, e.g., get the image's metadata (getMetadata()), the image's
>> color profile (getColorProfile()), the image's thumbnail
>> (getThumbnail()), and the image itself (getImage()). All said methods
>> must ultimately read data from the "chunks."
>>
>> For a given image file F, a new ImageInfo(F) is created. Once created,
>> the rest of the code will use the various methods of ImageInfo in an
>> arbitrary order. The first method called (regardless of which method it
>> is) creates the SoftChunkyByteBuffer and, after creation, it (and the
>> RandomAccessFile it uses) sticks around.
>>
>> After the first method is called, I can't just close the
>> RandomAccessFile because it might be the case that another method is
>> about to be called for the same image F via the same ImageInfo object.
>> In fact, I can *never* explicitly close the RandomAccessFile because of
>> this.
>
> Open the file on-demand then. Keep your chunky buffers as
> WeakReferences, so that they stick around a tad bit stronger, and close
> the file after, say, a short timeout. By experimenting around, you ought
> to find a reasonable trade-off balance for how soon to close. I mean,
> there isn't a particularly huge overhead associated with opening a RAF,
> is there? One FD. You may even be able to do without the buffering of
> significant amounts of data (as opposed to metadata) altogether.
>
> [Apologies if I missed some important parts of the thread -- I haven't
> read it all]
You didn't miss anything in Paul's case that would stop this working.
Closing and reopening files is a good solution here, and one i would have
suggested if you hadn't got there first.
In my earlier discussion with Mark, i described an isomorphic situation,
but added a requirement that meant closing and reopening couldn't be used.
In that case, you do need to add refcounting.
tom
--
Hesgadin. It was in two parts - both of them silent. I remember this map
came with a letter accusing me of stealing eggs. I had never understood
the relationship of the map to the accusation. I still don't, but I'm
grateful for the map.
|
| |
|
| |
 |
Tom Anderson

|
Posted: 2008-6-26 22:44:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
On Wed, 25 Jun 2008, Paul J. Lucas wrote:
> Tom Anderson wrote:
>> On Wed, 25 Jun 2008, Paul J. Lucas wrote:
>>
>>> Tom Anderson wrote:
>>>
>>>> Yes. Reference counting is a good solution to this problem, probably the
>>>> best one.
>>>
>>> Too bad Java doesn't provide it. It would be nice if CountedReference
>>> existed and the increment/decrement of the counter were handled
>>> automatically by the VM. It would be nicer still if you could specify a
>>> method to be called once the count reaches 0 and just before the referrent
>>> is reclaimed.
>>
>> Er ...
>>
>> How would this be any better than proper garbage collection?
>
> Because I'd want the VM to *guarantee* that the dispose() method would
> be called *as* *soon* *as* the count reaches 0. This is in contrast to
> WeakReferences that may never have their referrents be reclaimed.
Right. But if the objects that are holding your CountedReferences are
themselves managed by the GC, then they'll only decrement their counts
when they get collected, so you're still dependent on the GC to make your
refcounted objects die.
Of course, you could manage your reference-holding objects by refcounting.
But here, obviously, you have an infinite regress: for this to work, you
have to use refcounting all the way back to the root set, ie replace GC
with refcounting altogether. And even then, you're stuffed if you hit
cyclic garbage: you can only free that when the cycle detector runs, which
happens periodically, like GC. Unless you're going to cycle-detect every
time you decrement a pointer, which is going to have some performance
penalties, to put it mildly. On top of the fact that large-scale
refcounting is incredibly slow anyway, because of all the writes to
memory.
Now, having said that, the fragrant David Bacon has come up with an edgy
modern style of refcounting which does actually deliver pretty good
performance:
http://www.research.ibm.com/people/d/dfb/recycler-publications.html
It deals with cyclic garbage, runs only 5-10% slower than a proper GC,
and has really good realtime properties. However, one of the tradeoffs it
makes to achieve this is deferring decrements, which means it doesn't
quite have the properties you want.
>> I was thinking you'd do reference counting explicitly, using the
>> 'destroy' or whatever method in the session objects to do a decrement
>> on the relevant HotelHandle.
>
> That's just it: for my use case, I *can't* do it explicitly because I
> have no way of knowing if my resource is either currently in use or will
> be used again in the not-too-distant future (because some code/object
> somewhere still has a hard reference to it).
>
> For the record, the use-case is as follows. I have some class
> (ImageInfo) that reads image files (possibly very large image files).
> As part of the class's implementation, it opens a RandomAccessFile on
> the image and reads "chunks" of the file into memory. (The "chunks"
> themselves are held by SoftReferences -- a SoftChunkyByteBuffer -- and
> this part works fine.)
>
> The class has many methods, each of which accesses different parts of
> the image, e.g., get the image's metadata (getMetadata()), the image's
> color profile (getColorProfile()), the image's thumbnail
> (getThumbnail()), and the image itself (getImage()). All said methods
> must ultimately read data from the "chunks."
>
> For a given image file F, a new ImageInfo(F) is created. Once created,
> the rest of the code will use the various methods of ImageInfo in an
> arbitrary order. The first method called (regardless of which method it
> is) creates the SoftChunkyByteBuffer and, after creation, it (and the
> RandomAccessFile it uses) sticks around.
>
> After the first method is called, I can't just close the
> RandomAccessFile because it might be the case that another method is
> about to be called for the same image F via the same ImageInfo object.
> In fact, I can *never* explicitly close the RandomAccessFile because of
> this.
This is indeed a painful situation. But my point stands: since you're
dependent on GC of the reference-holding objects to the decrement the
count, you'd still lose with refcounting.
In C++, you could do this, because you implicitly or explicitly destroy
objects as soon as you're done with them - but there's nothing stopping
you doing this in java! Create an ImageInfoHandle class, through which you
use your ImageInfo. Give it a release() method. Call it whenever a
destructor would be called in C++ - when a locally-held instance goes out
of scope (using try-finally), or when you know you're done with a shared
instance (where you'd use delete in C++).
Or, do what Daniele suggested, and hide the details of the RAF being
opened and closed altogether.
tom
--
Hesgadin. It was in two parts - both of them silent. I remember this map
came with a letter accusing me of stealing eggs. I had never understood
the relationship of the map to the accusation. I still don't, but I'm
grateful for the map.
|
| |
|
| |
 |
John B. Matthews

|
Posted: 2008-6-26 23:23:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
In article <email***@***.com>,
email***@***.com (Stefan Ram) wrote:
> "Paul J. Lucas" <email***@***.com> writes:
> >It's a perfectly reasonable (and common) thing to want to:
> >a) guarantee an object is destroyed as soon as it's no longer used (and not
> >"some later time").
> >b) do one last thing to an object before it's destroyed.
>
> C++ has destructors.
>
> Are there any other (object-oriented) programming
> languages with destructors?
In Ada, objects derived from the abstract type
Ada.Finalization.Controlled have a Finalize method that is invoked
before the object's storage is reclaimed. This is sometimes used with
System.Storage_Pools to implement custom garbage collection.
<http://www.adaic.org/whyada/intro3.html>
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews
|
| |
|
| |
 |
Paul J. Lucas

|
Posted: 2008-6-27 0:03:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
Lew wrote:
> Paul J. Lucas wrote:
>> Real compelling argument there. Java programmers need to stop being
>> in denial and admit that Java has flaws just like every other language.
> For you [guaranteed dispose()] a flaw because apparently you don't want to write
> this particular corner case yourself.
Guaranteeing object destruction is hardly a corner case. Part of the big point
of Java is the garbage collector to free the programmer from the burden of
managing memory. Unfortunately it's very myopic in that it's *only* about
object reclamation and doesn't lift a finger to help you manage other resources
(like files, sockets, etc.).
- Paul
|
| |
|
| |
 |
Paul J. Lucas

|
Posted: 2008-6-27 0:25:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
Tom Anderson wrote:
> On Wed, 25 Jun 2008, Paul J. Lucas wrote:
>
>> Because I'd want the VM to *guarantee* that the dispose() method would
>> be called *as* *soon* *as* the count reaches 0. This is in contrast
>> to WeakReferences that may never have their referrents be reclaimed.
>
> Right. But if the objects that are holding your CountedReferences are
> themselves managed by the GC, then they'll only decrement their counts
> when they get collected, so you're still dependent on the GC to make
> your refcounted objects die.
In my ideal implementation, a counted reference would not be an object like a
WeakReference, i.e., a separate object. Imagine a new syntax like:
MyObject# ref = SomeObject.getMyObject();
where the # marks "ref" as a counted reference; or, if you don't like that, then
a new keyword:
counted MyObject ref = SomeObject.getMyObject();
Or, if you don't like that either, mark the method to return only counted
references so the caller can't forget:
class SomeObject {
public counted MyObject getMyObject() { /* ... */ }
}
MyObject ref = SomeObject.getMyObject();
Then the whole problem of having a hard reference to a CountedReference (as a
distinct object) goes away. As soon as ref goes out of scope, its counter gets
decremented.
As far as having a counted reference *inside* another object (to which one has a
hard reference), well, as with everything else, you have to know what you're
doing. But at least this scheme affords you the ability whereas current Java
doesn't.
> In C++, you could do this, because you implicitly or explicitly destroy
> objects as soon as you're done with them - but there's nothing stopping
> you doing this in java! Create an ImageInfoHandle class, through which
> you use your ImageInfo. Give it a release() method. Call it whenever a
> destructor would be called in C++ - when a locally-held instance goes
> out of scope (using try-finally), or when you know you're done with a
> shared instance (where you'd use delete in C++).
Yes, sure; but, as a library designer, I want the burden of doing all this to be
mine and not the users of the library who will often forget.
I find it ironic that Java, which has garbage collection to free the programmer
from the burden of memory management, instead burdens the programmer with having
to remember to use try/finally.
- Paul
|
| |
|
| |
 |
Paul J. Lucas

|
Posted: 2008-6-27 0:30:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
On Jun 25, 2:03爌m, Daniele Futtorovic <email***@***.com>
wrote:
> Open the file on-demand then. Keep your chunky buffers as
> WeakReferences, so that they stick around a tad bit stronger, and close
> the file after, say, a short timeout.
Unfortunately that can't be guaranteed to work. When one wants to
move or delete a file under Windows, the file can *not* be open.
Having a time-out is a race-condition and bug waiting to happen.
- Paul
|
| |
|
| |
 |
Tom Anderson

|
Posted: 2008-6-27 0:43:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
On Thu, 26 Jun 2008, Paul J. Lucas wrote:
> Tom Anderson wrote:
>> On Wed, 25 Jun 2008, Paul J. Lucas wrote:
>>
>>> Because I'd want the VM to *guarantee* that the dispose() method would be
>>> called *as* *soon* *as* the count reaches 0. This is in contrast to
>>> WeakReferences that may never have their referrents be reclaimed.
>>
>> Right. But if the objects that are holding your CountedReferences are
>> themselves managed by the GC, then they'll only decrement their counts when
>> they get collected, so you're still dependent on the GC to make your
>> refcounted objects die.
>
> In my ideal implementation, a counted reference would not be an object like a
> WeakReference, i.e., a separate object. Imagine a new syntax like:
>
> MyObject# ref = SomeObject.getMyObject();
>
> where the # marks "ref" as a counted reference; or, if you don't like that,
> then a new keyword:
>
> counted MyObject ref = SomeObject.getMyObject();
>
> Or, if you don't like that either, mark the method to return only counted
> references so the caller can't forget:
>
> class SomeObject {
> public counted MyObject getMyObject() { /* ... */ }
> }
>
> MyObject ref = SomeObject.getMyObject();
>
> Then the whole problem of having a hard reference to a CountedReference
> (as a distinct object) goes away. As soon as ref goes out of scope, its
> counter gets decremented.
Okay.
> As far as having a counted reference *inside* another object (to which
> one has a hard reference), well, as with everything else, you have to
> know what you're doing. But at least this scheme affords you the
> ability whereas current Java doesn't.
Hang on, would you ban the use of counted references as instance fields?
Or just let this happen and live with having delayed decrements in those
cases?
>> In C++, you could do this, because you implicitly or explicitly destroy
>> objects as soon as you're done with them - but there's nothing stopping you
>> doing this in java! Create an ImageInfoHandle class, through which you use
>> your ImageInfo. Give it a release() method. Call it whenever a destructor
>> would be called in C++ - when a locally-held instance goes out of scope
>> (using try-finally), or when you know you're done with a shared instance
>> (where you'd use delete in C++).
>
> Yes, sure; but, as a library designer, I want the burden of doing all
> this to be mine and not the users of the library who will often forget.
That's fair enough. I was trying to make the point that this kind of
refcounting *can* be done in java, but of course you're quite right to say
that it's a pain.
I think the best accomodation that could be made without a major and
potentially awkward addition to the language and runtime system would be a
C#-style 'using' construct:
using (ImageInfo info = getImageInfo(fileName)) {
int w = info.getWidth() ;
// etc
}
Which would mean something like:
ImageInfo info ;
try {
info = getImageInfo(fileName) ;
int w = info.getWidth() ;
// etc
}
finally {
info.close() ;
}
This is an addition to the language, but a minor one, and one that's
syntactic sugar, so the compiler can deal with it without needing the
runtime system to change. Like the new for loops. Also like the new for
loops, it would depend on the used object implementing some interface,
like Closeable, Releasable, Usable, whatever.
You might even want to use finalize() as the method called, or make
finalization call close() if an object is Closeable. Not sure about that.
It may not be quite as neat as in C++ (and i never thought i'd say that!),
but all it involves doing is adding a keyword, a pair of parens, and a
pair of braces to your code.
It would mean that the lifetimes of usable objects have to nest - you
can't do:
acquire foo
acquire bar
release foo
release bar
At least, not using this construct alone. You could nest them and
explicitly close foo when you were done.
> I find it ironic that Java, which has garbage collection to free the
> programmer from the burden of memory management, instead burdens the
> programmer with having to remember to use try/finally.
Fair point!
tom
--
Hesgadin. It was in two parts - both of them silent. I remember this map
came with a letter accusing me of stealing eggs. I had never understood
the relationship of the map to the accusation. I still don't, but I'm
grateful for the map.
|
| |
|
| |
 |
Joshua Cranmer

|
Posted: 2008-6-27 0:55:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
Paul J. Lucas wrote:
> Guaranteeing object destruction is hardly a corner case. Part of the
> big point of Java is the garbage collector to free the programmer from
> the burden of managing memory. Unfortunately it's very myopic in that
> it's *only* about object reclamation and doesn't lift a finger to help
> you manage other resources (like files, sockets, etc.).
Memory tends to be a special case. Every object uses memory, and writing
a good memory manager is very taxing on the programmer.
Other resources are different. Relatively few objects need access to a
file, stream, or socket, for example. In addition, these resources tend
to have more uniform life spans. If you want to write your own global
resource manager, go ahead.
By the way, there is an RFE to add a using construct to make the
try-finally syntax. With any luck, it will come in Java 7.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
|
| |
|
| |
 |
ram

|
Posted: 2008-6-27 1:30:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
Tom Anderson <email***@***.com> writes:
>
>I think the best accomodation that could be made without a major and
>potentially awkward addition to the language and runtime system would be a
>C#-style 'using' construct:
>using (ImageInfo info = getImageInfo(fileName)) {
> int w = info.getWidth() ;
> // etc
>}
In [1], it is described how to write a class
籉ileInputStreamOpenCloseAndNull?so that
for( final java.io.FileInputStream fileInputStream:
new FileInputStreamOpenCloseAndNull( "input.txt" ))
use( fileInputStream );
will close 籪ileInputStream?after the use.
This is not much longer than the way it is written
without such a feature, that is:
final java.io.FileInputStream fileInputStream =
new FileInputStreamOpenCloseAndNull( "input.txt" );
use( fileInputStream );
When opening the stream was not possible, it also will not be
closed, and it is possible to set up things to either not call
籾se?in this case at all or call it with 籲ull?
Also, when multiple resources are needed, the for statements
can be written in sequence to get the proper behavior.
For more details, See:
[1]
http://www.purl.org/stefan_ram/pub/dual-band_if
|
| |
|
| |
 |
Lew

|
Posted: 2008-6-27 1:30:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
Lew wrote:
> > For you [guaranteed dispose()] a flaw because apparently you don't want to write
> > this particular corner case yourself.
"Paul J. Lucas" wrote:
> Guaranteeing object destruction is hardly a corner case. 燩art of the big point
That isn't a refutation of what I said, it's a refutation of some
point I did not make. The "corner case" to which I referred is not
object destruction per se, but the unique requirement you have that it
occur at a particular time and release additional resources. That is
a corner case, Mr. Straw-Man Arguer.
> of Java is the garbage collector to free the programmer from the burden of
> managing memory. 燯nfortunately it's very myopic in that it's *only* about
> object reclamation and doesn't lift a finger to help you manage other resources
> (like files, sockets, etc.).
That may be unfortunate, but it's not a flaw in the language, it's
just something you don't get automatically with every object. You
don't get it with every object because not every object needs it.
Only the objects involved in your corner case need that capability.
To burden every object with relatively rarely-needed features would be
the flaw, so you have it exactly backwards.
Lew
|
| |
|
| |
 |
Mike Schilling

|
Posted: 2008-6-27 2:12:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
"Paul J. Lucas" <email***@***.com> wrote in message
news:pzF8k.6674$email***@***.com...
> Lew wrote:
>> Paul J. Lucas wrote:
>>> Mark Space wrote:
>>>
>>>> Try-catch-finally. The "finally" portion is always run.
>>>
>>> No it's not:
>>>
>>> try {
>>> // ...
>>> if ( catastrophe )
>>> System.exit( -1 );
>>> }
>>> finally {
>>> // not executed if catastrophe == true
>>> }
>>
How is this different from C++ (excuse any syntax errors: it's been a while)
{
Object a = new Object();
exit(-1); // a's destructor won't run now
}
>> Eschew System.exit(), especially in try blocks.
>
> That doesn't invalidate my point. And it should be used when appropriate.
> That's why Java has shutdownHooks.
There are two sorts of resources that might need cleaning up.
1. Those which disappear on process exit. The shutdownHooks are not
necessary..
2. Those which don't disappear on process exit. The shutdownHooks are
insufficient, since the JVM may not exit cleanly.
|
| |
|
| |
 |
Joshua Cranmer

|
Posted: 2008-6-27 2:36:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
Mike Schilling wrote:
> How is this different from C++ (excuse any syntax errors: it's been a while)
>
> {
> Object a = new Object();
> exit(-1); // a's destructor won't run now
> }
The code should be:
{
Object a;
exit(-1);
}
And no, it isn't any different (at least, in g++-4.3 it isn't).
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
|
| |
|
| |
 |
Tom Anderson

|
Posted: 2008-6-27 3:38:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
On Thu, 26 Jun 2008, Stefan Ram wrote:
> Tom Anderson <email***@***.com> writes:
>
>> I think the best accomodation that could be made without a major and
>> potentially awkward addition to the language and runtime system would be a
>> C#-style 'using' construct:
>> using (ImageInfo info = getImageInfo(fileName)) {
>> int w = info.getWidth() ;
>> // etc
>> }
>
> In [1], it is described how to write a class
> 籉ileInputStreamOpenCloseAndNull?so that
> [1]
>
> http://www.purl.org/stefan_ram/pub/dual-band_if
That's clever. Gross, but clever!
tom
--
They didn't have any answers - they just wanted weed and entitlement.
|
| |
|
| |
 |
Daniele Futtorovic

|
Posted: 2008-6-27 3:56:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
On 2008-06-26 18:30 +0100, Paul J. Lucas allegedly wrote:
> On Jun 25, 2:03 pm, Daniele Futtorovic <email***@***.com>
> wrote:
>
>> Open the file on-demand then. Keep your chunky buffers as
>> WeakReferences, so that they stick around a tad bit stronger, and close
>> the file after, say, a short timeout.
>
> Unfortunately that can't be guaranteed to work. When one wants to
> move or delete a file under Windows, the file can *not* be open.
Yeah, that's how it goes. Work on a temporary copy if you're concerned
about that. By the way, how come you're so much concerned about deleting
a file when your program is actually working on it? Isn't that like...
all right if it can't be deleted?
Also, are you sure you open the file in read-only mode?
> Having a time-out is a race-condition and bug waiting to happen.
Not if you do it properly.
But you may also forget about the timeout, load the file/image metadata
once, and remaining data on-demand.
--
DF.
to reply privately, change the top-level domain
in the FROM address from "invalid" to "net"
|
| |
|
| |
 |
Daniel Pitts

|
Posted: 2008-6-27 4:02:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
Paul J. Lucas wrote:
> Lew wrote:
>> Paul J. Lucas wrote:
>>> Real compelling argument there. Java programmers need to stop being
>>> in denial and admit that Java has flaws just like every other language.
>
>> For you [guaranteed dispose()] a flaw because apparently you don't
>> want to write
>> this particular corner case yourself.
>
> Guaranteeing object destruction is hardly a corner case. Part of the
> big point of Java is the garbage collector to free the programmer from
> the burden of managing memory. Unfortunately it's very myopic in that
> it's *only* about object reclamation and doesn't lift a finger to help
> you manage other resources (like files, sockets, etc.).
>
> - Paul
Which is exactly what the try{}finally{} is to help you manage. Seems
like more than a finger to me.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
|
| |
|
| |
 |
Lasse Reichstein Nielsen

|
Posted: 2008-6-27 6:58:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
"Paul J. Lucas" <email***@***.com> writes:
> Tom Anderson wrote:
>> On Wed, 25 Jun 2008, Paul J. Lucas wrote:
>>
>>> Because I'd want the VM to *guarantee* that the dispose() method
>>> would be called *as* *soon* *as* the count reaches 0. This is in
>>> contrast to WeakReferences that may never have their referrents be
>>> reclaimed.
>> Right. But if the objects that are holding your CountedReferences
>> are themselves managed by the GC, then they'll only decrement their
>> counts when they get collected, so you're still dependent on the GC
>> to make your refcounted objects die.
>
> In my ideal implementation, a counted reference would not be an object
> like a WeakReference, i.e., a separate object. Imagine a new syntax
> like:
>
> MyObject# ref = SomeObject.getMyObject();
>
> where the # marks "ref" as a counted reference; or, if you don't like
> that, then a new keyword:
>
> counted MyObject ref = SomeObject.getMyObject();
Is the variable reference-counted or is the object?
> Or, if you don't like that either, mark the method to return only
> counted references so the caller can't forget:
>
> class SomeObject {
> public counted MyObject getMyObject() { /* ... */ }
If the method returns the same reference twice, how is it counted?
If it returns a reference to an existing object with other references
out there, how will it be counted?
I can only make reference counting make sense if it tracks an object
from its creation to its final reference is dead.
/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
|
| |
|
| |
 |
Paul J. Lucas

|
Posted: 2008-6-27 7:03:00 |
Top |
java-programmer >> Doing one last thing to a WeakReference
Tom Anderson wrote:
> On Thu, 26 Jun 2008, Paul J. Lucas wrote:
>
>> As far as having a counted reference *inside* another object (to which
>> one has a hard reference), well, as with everything else, you have to
>> know what you're doing. But at least this scheme affords you the
>> ability whereas current Java doesn't.
>
> Hang on, would you ban the use of counted references as instance fields?
> Or just let this happen and live with having delayed decrements in those
> cases?
I wouldn't ban anything, just put a big, fat warning to developers. I don't
believe in designing language to save programmers from themselves. I'd rather
err on the side of flexibility.
Sure, C++ allows you to shoot yourself in the foot (and blow away your whole
leg); but then it's *my* fault. I'd rather have that situation than my current
one with Java where I *can't* do what I want easily.
- Paul
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Struts JDO EJB Hibernate JFC - NUTS !The industry is in pure and utter chaos.
So many choices. How does one know which one is the popular one?
Is it Struts? Is it JFC? Is EJB unpopular (bloat)?
Personally, I find that xdoclet makes writing EJB's a total breeze,
dealing with the database that is. Are people using JDO now, or have
people been looking to see what JDO is all about but can't find any
solid examples so that people can't get rolling with it?
For the webgui, I wish more solutions would take the XMLC (enhydra) or
Tapestry approach. JSP / JSF / Struts all fail to separate design
from content.
Which framework handles form processing best? When I tried Struts I
lost days and days dealing with the uninformative errors it spits out.
Which one is better? What do people like these days? Or is everyone
else also in disarray, and keeps browsing site after site after blog
after blog and can't seem to get the scoop anymore?
- 2
- [Active Tags] Have the RefleX !hi,
People that are intersting in native XML programming can download the
RefleX engine freely here :
http://reflex.gforge.inria.fr
RefleX is available under the french license CeCILL, which is almost the
same as the well-known GNU GPL.
RefleX is a Java tool that allows people that have no particular
knowledge of Java to write smart programs entirely in XML ; however, the
most brave fellows could also design their own tags and plug them to the
engine ! Have a look at the "How-To" section to achieve this.
The concepts of native XML programming used in RefleX have been designed
separately, so that other implementations on other platforms/languages
can be considered.
Why programming in XML ?
At INRIA, we have experienced RefleX on a *real* operational project,
and it appears that :
-the code is very easy to produce
-the amount of code produced is very tiny
Despite the intrinsic verbosity of XML, the expressiveness of XPath
(which is used intensively in Active Tags) and the ability to declare
complex processes exposed as simple tags makes Active Tags programs very
efficient.
Active Tags has been designed like a programming language : it offers
several libraries (called modules) for different purpose : system
interactions, I/O, SQL, Web, etc and allow users to define simply their
own libraries, but Active Tags differs from other programming languages
in many ways... read more on the Active Tags website or on the RefleX
web site !
http://reflex.gforge.inria.fr
http://disc.inria.fr/perso/philippe.poulard/xml/active-tags/
You'll find on the RefleX web site some tutorials that are showing the
traditional "hello world" example, how to publish an entire XML
repository to HTML, how to map SQL to XML, how to design an MVC
architecture, and how to play with datatypes and PSVI ; most of them are
available in batch mode as well as in a Web application ready to run.
Don't say anymore that Santa Claus doesn't exists !
Enjoy !
--
Cordialement,
///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
- 3
- Correct use of ReadableByteChannelFor a piece of code intented to be rather
generic, I thought it would be a good idea
that it reads its input from a
ReadableByteChannel. The main reason to
choose it over an InputStream was that the
channel can be obtained for an InputStream as
well as for a RandomAccessFile.
Now the question:
How do you correctly perform a blocking read
from a ReadableByteChannel given that it does
not necessarily block?
I came up with
ReadableByteChannel source;
ByteBuffer inBuf;
...
int result;
while( 0==(result=source.read(inBuf)) ) Thread.yield();
In case the channel is blocking, the yield()
will never be called. If the channel is
non-blocking, the yield() may be called. But
on a machine without much load, I am afraid
it will generate load because no other thread
is interested in the processor.
Any ideas how this can be done better?
Harald.
- 4
- ObjectWebCon'06 - Call For Proposals CALL FOR PROPOSALS OBJECTWEBCON06 ObjectWeb Annual Conference 5th EDITION Paris France Januar 31st Februar 2nd 2006 http: ObjectWebCon06 object eb org SUBMISSION DEADLINE: No ember 21th 2005 ObjectWebCon06 the ne t ObjectWeb annual conference ill take place in Paris la D fense France from Januar 31st to Februar 2nd 2006 As ObjectWeb is mo ing in Anal st reports from a pure technical pla er in open source infrastructure soft are to a consortium of market pla ers its annual conferences strengthens as unique opportunit for professionals to disco er learn and e change on middle are and open source soft are technolog and Ecos stems As an e perienced professional of the domain ou are in ited to submit proposals in one or more of the follo ing sessions: Parallel sessions Best use case a ards Podium talks Please freel distribute this call to interested colleagues and friends We thank ou for making our submission online before No ember 21th and are looking for ard to reading our proposals Best regards Object ebCon06 Program Committee mailto:OWCon06 contact@object eb org Note: More information can be found on the eb at http: ObjectWebCon06 object eb org or belo in plain te t form ============================================================================ The ObjectWebCon06 program committee is seeking to recei ing proposals for the follo ing sessions: 1 Parallel sessions 45 minutes ================================== Sessions ill co er the three follo ing topics: T1 Using Open Source Middle are for : 3 presentations in each topic enterprise Ja a APS J2EE Webportal B2B BI SOA application integration ESB Clustering GRID autonomic management pro isioning large scale s stems Ad hoc net orked s stems telco mobilit RFID embedded T2 In the business of Open Source Middle are 6 presentations Business models legal aspects OSS Strateg public policies real orld cases go ernmental uses T3 Focus on ObjectWeb projects 10 presentations O er ie introduction primers guided tours getting started ith ObjectWeb projects Guideline to submit in Parallel sessions The title of the presentation A brief outline or abstract of the presentation not to e ceed 400 ords For each speaker the speaker name title compan professional street and email addresses phone and fa numbers Addresses phone and fa numbers are for organi ation purposes onl and ill not be distributed to third parties ithout prior agreement A short biograph of the proposed speaker s sho ing rele ant e perience and qualification to speak on the proposed subject matter not to e ceed 300 ords Submissions should be made online at http: ObjectWebCon06 object eb org iki bin ie Main CFP and should be ritten in English presentations are to be gi en in English Important dates for Parallel sessions: Abstract due: No ember 21th 2005 Notification: starting December 5th 2005 2 Best Use Cases A ards ======================== The ObjectWebCon06 Best Use Cases contest is a challenge for hich ou ma file one or se eral submissions about real orld use cases of ObjectWeb components and platforms Winners ill be nominated b ObjectWeb members through on line ote December 1st 15th A ards ill be offered in the follo ing categories: A1: Entreprise Ja a: production use of ObjectWeb enterprise Ja a components and platforms A2: ISV Integration: commercial offering or de elopment embedding some ObjectWeb components A3: Jur s Special Pri e: an use of ObjectWeb components and platforms Guideline to run for Use Cases A ards: A brief outline or abstract not to e ceed 150 ords ObjectWeb components that ha e been used a comment about this success h has it been a success according to ou? In option ou ma add: a complete description of the Use Case screenshots Submission should be made online at http: ObjectWebCon06 object eb org iki bin ie Main A ardsForm Important dates for Use Case A ards: Abstract due: No ember 21st 2005 Online ote: December 1 12 Notification: Starting December 15th 3 Podium talks =============== Podium talks intends to gi e all participants an opportunit to present ork the do relating to open source middle are Podium speaker ill ha e the floor for 10 minutes and ma use up to 5 slides Podium talks ill complement technical sessions on the follo ing topics: enterprise grid J2EE APS SOA ESB Telco Guideline for podium speakers: Podium talks are scheduled on a first come first ser ed basis Send an email to OWCon06 contact@object eb org in order to reser e a slot On behalf of the ObjectWebCon 06 Organi ation Committee Xa ier MOGHRABI ObjectWeb Consortium http: object eb org
- 5
- Bug#166370: Join our marketing teamWe are Looking for partners worldwide. The position is home-based. Our Company Head Office is located in UK with branches all over the world. We are looking for talented, honest, reliable representatives from different regions. The ideal candidate will be an intelligent person, someone who can work autonomously with a high degree of enthusiasm. Our Company offers a very competitive salary to the successful candidate, along with an unrivalled career progression opportunity.
If you would like to work with our active, dynamic team, we invite you to apply for employment. Preference will be given to applicants with knowledge of multiple languages.
Please send the following information to email***@***.com.
1. Full name
2 Address of residence
3 Contact Phone numbers
4 Languages spoken
5 Whether you are interested in part time job or full time employment.
Thank you. We look forward to working with you.
If you received this message in error, please send a blank email to: email***@***.com.
--
To UNSUBSCRIBE, email to email***@***.com
with a subject of "unsubscribe". Trouble? Contact email***@***.com
- 6
- paintComponent into a BuffereImage?It seems like I should be able to override the paintComponent method of
a class and have it do its paint into a BufferedImage something like
this:
public void paintComponent(Graphics g) {
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2D = image.createGraphics();
super.paintComponent( g2D );
.. etc ...
But all I get is a null pointer exception on super.paintComponent( g2D
); even though g2D is definitely NOT null. The exception actually comes
deep in the bowels of Java at:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.awt.Rectangle.intersects(Unknown Source)
at javax.swing.text.BoxView.paint(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI$RootView.paint(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.paintSafely(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.paint(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at TextPanel.paintComponent(TestClass.java:139) <--- the
super.paintComonent()
Any ideas on how to make this work?
Thanks,
--gary
- 7
- 8
- Java proxy server for IEHi,
I hope someone can help me (I am an inexperienced Java programmer).
What I'm trying to do is write a Java Application that acts as a proxy
server for Internet Explorer. The goal of the little Java application
is to be able to log HTTP requests and responses between IE and a web
server.
I've pasted my application as it exists so far. It only handles HTTP
GETs right now, which is fine for my purposes at the moment. It works
for simple HTML pages. The problem is that I can't get it to
read/write graphic information correctly, such as when a web page
requests a gif (the graphic appears messed up in IE). I have 2
questions for all the Java experts out there:
(1) How can I handle binary content so it's properly rendered in the
browser.
(2) Using writeBytes from the DataOuputStream class seems to write one
byte at time, even though I'm passing in a string. I'd like a method
that writes in batches to the socket endpoint. Is that possible?
Thanks for any and all help!
import java.io.*;
import java.net.*;
class SimpleProxy {
public static void main(String[] args) {
ServerSocket ss = null;
Socket s = null; // client socket connection with client (browser)
DataOutputStream os = null; //client (browser) output;
DataInputStream is = null; //client (browser) input
String sInput;
int iPosURLEnd;
String sURL;
Socket sServ = null; //client socket connection with server (web
server)
DataOutputStream osServ = null; //server (web server) output;
DataInputStream isServ = null; //client (web server) input
int iPosHostStart;
String sHost;
System.out.println ("Starting app...\r\n");
try {
ss = new ServerSocket(45678);
}
catch (Exception e) {
System.out.println ("Error establishing ServerSocket
connection.\r\n");
System.out.println ("Error: " + e.getMessage());
}
for (; ;) {
try {
s = ss.accept();
System.out.println("Connection established.\r\n");
os = new DataOutputStream(s.getOutputStream());
is = new DataInputStream(s.getInputStream());
}
catch (Exception e) {
System.out.println ("Error establishing connection.\r\n");
System.out.println ("Error: " + e.getMessage());
}
System.out.println("--------- Read REQUEST from client
--------\r\n");
for (; ;) {
try {
sInput = is.readLine();
if (sInput == null)
break;
System.out.println("Client: " + sInput);
if (sInput.startsWith("GET",0)) {
iPosURLEnd = sInput.indexOf(" ",4); // 4 = Len("GET ")
sURL = sInput.substring(4, iPosURLEnd);
iPosHostStart = sURL.indexOf("://") + 3; // 3 = Len("://")
sHost = sURL.substring(iPosHostStart,
sURL.indexOf("/",iPosHostStart+1));
try {
sServ = new Socket(sHost, 80); //assume port 80
osServ = new
DataOutputStream(sServ.getOutputStream());
isServ = new DataInputStream(sServ.getInputStream());
}
catch (Exception e) {
System.out.println ("Error establishing connection with
server.\r\n");
System.out.println ("Error: " + e.getMessage());
}
}
osServ.writeBytes(new String(sInput + "\r\n"));
if (sInput.compareTo("") == 0)
break;
}
catch (Exception e) {
System.out.println ("Error reading information from
client.\r\n");
System.out.println ("Error: " + e.getMessage());
}
}
System.out.println("--------- Write RESPONSE from server
--------\r\n");
for (; ;) {
try {
sInput = isServ.readLine();
if (sInput == null)
break;
System.out.println("Server: " + sInput);
os.writeBytes(new String(sInput + "\r\n"));
}
catch (Exception e) {
System.out.println ("Error reading information from
server.\r\n");
System.out.println ("Error: " + e.getMessage());
}
}
try {
isServ.close();
osServ.close();
sServ.close();
is.close();
os.close();
s.close();
}
catch (IOException e) {
System.out.println ("Error closing sockets.\r\n");
System.out.println ("Error: " + e.getMessage());
}
}
}
}
- 9
- Confused with the ArrayListHello,
ArrayList main = new ArrayList();
ArrayList copy = new ArrayList();
copy.add("Test1");
copy.add("Test2");
main.add(copy);
copy = new ArrayList();
copy.add("Test3");
copy.add("Test4");
main.add(copy);
for(int i=0;i<main.size();i++)
{
ArrayList temp = (ArrayList)main.get(i);
for(int j=0;j<temp.size();j++)
{
System.out.println(temp.get(j));
}
}
for(int i=1;i<main.size();i++)
{
ArrayList temp = (ArrayList)main.get(i);
temp.set(0,"Test5");
temp.set(1,"Test6");
}
for(int i=0;i<main.size();i++)
{
ArrayList temp = (ArrayList)main.get(i);
for(int j=0;j<temp.size();j++)
{
System.out.println(temp.get(j));
}
}
}
- 10
- Howto read newline characterHi,
I'm new to java and I'm writing a simple text editor using swt examples
from eclipse. The only problem I see is that my editor wont display the
text file correctly. It will display the whole text file in one line.
Here is the code I use to open file. I don't know where to start.
public class OpenFile extends SelectionAdapter {
public void widgetSelected(SelectionEvent event) {
FileDialog fileOpen = new FileDialog(shell, SWT.OPEN);
fileOpen.setText("Open");
String[] filterExt = { "*.txt", "*.ini", "*.*" };
fileOpen.setFilterExtensions(filterExt);
String selected = fileOpen.open();
if (selected == null) {
return;
}
FileReader file = null;
try {
file = new FileReader(selected);
} catch (FileNotFoundException e) {
MessageBox messageBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
messageBox.setMessage("Could not open file.");
messageBox.setText("Error");
messageBox.open();
return;
}
BufferedReader fileInput = new BufferedReader(file);
String textString = null;
StringBuffer sb = new StringBuffer();
try {
do {
if (textString != null) {
sb.append(textString);
}
} while ((textString = fileInput.readLine()) != null);
} catch (IOException e1) {
MessageBox messageBox = new MessageBox(shell, SWT.ICON_ERROR |
SWT.OK);
messageBox.setMessage("Could not write to file.");
messageBox.setText("Error");
messageBox.open();
return;
}
text.setText(sb.toString());
}
}
Thanks in advance,
C
- 11
- 12
- 13
- JDialog dispose and application window poppingHello!
I have an application where I show a JDialog (sort of as a status
indicator). During this time, I launch an application like Excel
(which comes up successfully). Once that other application is
launched, I take down my dialog by calling dlg.dispose(). Note that
the user did NOT interact with that dialog.
After the dialog disappears, my application pops itself to be
frontmost. I cannot figure out how to make my application stop this
behavior. I want the second application (Excel in this case), to
remain in front.
I have been searching all over and cannot find any solution to this
problem. I do know its tied up with the dispose() because not invoking
it leaves things the way I want (except that my modal dialog is still
up).
Any pointers would be appreciated.
Allan
- 14
- memory profiler recommendationJavameisters,
I have written an application for J2SE using the Netbeans IDE. I would
like to test it for memory leaks before releasing it, and would like a
recommendation as to what to use. I tried OptimizeIt some time ago,
and it seemed to do what I want, but I was just wondering if there are
better (or less expensive) alternatives.
Thanks much,
Matthew Fleming
email***@***.com
(please remove X before using this address)
- 15
- Saving a BufferedImage as a JPEGI am saving a BufferedImage as a JPEG file under Windows XP.
I am using the JAI JPEGImageEncoder class.
The JPEG is saved as CMYK but I need RGB.
I cannot figure out how to get RGB. Any help?
|
|
|