<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4396093936384561136</id><updated>2024-10-24T23:17:43.468-07:00</updated><category term="/"/><title type='text'>No milk in my coffee</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default?start-index=26&amp;max-results=25'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>38</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-6313592647285315128</id><published>2014-08-30T11:53:00.000-07:00</published><updated>2014-08-30T11:53:00.175-07:00</updated><title type='text'>SimpleFlatMapper a lightweight and fast alternative to hibernate or ibatis</title><content type='html'>https://github.com/arnaudroger/SimpleFlatMapper/

it&#39;s performance focus and just work on top of jdbc without masking it.</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/6313592647285315128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/6313592647285315128' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/6313592647285315128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/6313592647285315128'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2014/08/simpleflatmapper-lightweight-and-fast.html' title='SimpleFlatMapper a lightweight and fast alternative to hibernate or ibatis'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-1165703751791419501</id><published>2012-04-02T01:38:00.000-07:00</published><updated>2012-04-02T01:38:08.818-07:00</updated><title type='text'>OSGI Impact on performace</title><content type='html'>It seems like the OSGI container - in my case Felix - is having a performance impact on code that uses the class loader to access resources or load classes. Unfortunately all the DOM/XPath Api seems to love these kind of access. &lt;br /&gt;
&lt;br /&gt;
The XPath implementation provided in standard is already not a very good performer under high concurrency environment because of that, the class loader access is synchronized.&lt;br /&gt;
&lt;br /&gt;
Don&#39;t know which one too blame... one thing for sure having a OSGI env as a target system is not pain free...</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/1165703751791419501/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/1165703751791419501' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/1165703751791419501'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/1165703751791419501'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2012/04/osgi-impact-on-performace.html' title='OSGI Impact on performace'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-2654919006453207424</id><published>2012-02-29T08:25:00.002-08:00</published><updated>2012-02-29T08:25:55.215-08:00</updated><title type='text'>How to have a ManyToOne mastered by a OneToMany with JPA annotation</title><content type='html'>http://docs.jboss.org/ejb3/app-server/HibernateAnnotations/reference/en/html_single/index.html#entity-mapping-association-collections&lt;br /&gt;
&lt;br /&gt;
To map a bidirectional one to many, with the one-to-many side as the owning side, you have to remove the mappedBy element and set the many to one @JoinColumn as insertable and updatable to false. This solution is obviously not optimized from the number of needed statements.&lt;br /&gt;
&lt;br /&gt;
@Entity&lt;br /&gt;
public class Troop {&lt;br /&gt;
    @OneToMany&lt;br /&gt;
    @JoinColumn(name=&quot;troop_fk&quot;) //we need to duplicate the physical information&lt;br /&gt;
    public Set&lt;Soldier&gt; getSoldiers() {&lt;br /&gt;
    ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
@Entity&lt;br /&gt;
public class Soldier {&lt;br /&gt;
    @ManyToOne&lt;br /&gt;
    @JoinColumn(name=&quot;troop_fk&quot;, insertable=false, updatable=false)&lt;br /&gt;
    public Troop getTroop() {&lt;br /&gt;
    ...&lt;br /&gt;
}</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/2654919006453207424/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/2654919006453207424' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/2654919006453207424'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/2654919006453207424'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2012/02/how-to-have-manytoone-mastered-by.html' title='How to have a ManyToOne mastered by a OneToMany with JPA annotation'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-119533176294612796</id><published>2011-08-05T02:20:00.000-07:00</published><updated>2011-08-05T02:26:23.526-07:00</updated><title type='text'>How were we successful before OSGI?</title><content type='html'>According to some people discourse it would be a fair question, seems that modularity is impossible before OSGI. Wonder what we have been doing for the last 10 years...&lt;br /&gt;&lt;br /&gt;Mind you, it was impossible to be successful without EJBs. So after sorting our threading issues with a well thought stack, now we have experts sorting our class loader and so far they are doing the same great job...</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/119533176294612796/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/119533176294612796' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/119533176294612796'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/119533176294612796'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2011/08/how-were-we-successful-before-osgi.html' title='How were we successful before OSGI?'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-1520058363003967330</id><published>2011-08-02T08:14:00.000-07:00</published><updated>2011-08-02T08:17:53.076-07:00</updated><title type='text'>Spring ws Saaj vs Axiom</title><content type='html'>Saaj create a lot of contention when manipulating the message - it seems to reload the an file from the class loader every time -, Axiom is much faster under stress.&lt;br /&gt;&lt;br /&gt;to change the message factory create a new one in the application context under the name messageFactory&lt;br /&gt;&lt;br /&gt;&lt;pre&gt; &lt;br /&gt;&lt;br /&gt;&amp;lt;bean name=&quot;messageFactory&quot; class=&quot;org.springframework.ws.soap.axiom.AxiomSoapMessageFactory&quot;&gt;&lt;br /&gt;&amp;lt;/bean&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/1520058363003967330/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/1520058363003967330' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/1520058363003967330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/1520058363003967330'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2011/08/spring-ws-saaj-vs-axiom.html' title='Spring ws Saaj vs Axiom'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-3982363275851358243</id><published>2009-02-26T04:37:00.001-08:00</published><updated>2009-02-26T04:40:05.854-08:00</updated><title type='text'>Introducing Unit Testing in Legacy code base</title><content type='html'>In big companies, developing a green field project is a rare privilege&lt;br /&gt;... most of the time you will have to develop on a existing code base of&lt;br /&gt;versatile quality - Not due to the skill of the developer more likely to&lt;br /&gt;the history of the project, lack of code review and poor quality focus,&lt;br /&gt;short term vs. long term risk -.&lt;br /&gt;&lt;br /&gt;Anyway if you are not lucky you are facing a big spaghetti monster&lt;br /&gt;calling other pasta entities in ways ranging from CORBA, RV, rmi, EJB,&lt;br /&gt;ftp messaging ... Chances is that the code can&#39;t even run on your dev&lt;br /&gt;machine, making development laborious and non productive.&lt;br /&gt;&lt;br /&gt;There are 2 ways to deal with this problem&lt;br /&gt;&lt;br /&gt; 1 Status quo, self explanatory&lt;br /&gt; 2 Introducing unit test, mocking the internal and external monsters&lt;br /&gt;&lt;br /&gt;1 : simple solution, not very rewarding but if the cost of solution 2&lt;br /&gt;overcome the benefit that&#39;s the way to go&lt;br /&gt;2 : long term benefit in development and quality. But costly&lt;br /&gt;&lt;br /&gt;Though with a bit of method there are way to make 2 less costly, all you&lt;br /&gt;will need is :&lt;br /&gt;&lt;br /&gt; - A good refactoring dev environment, eclipse or idea&lt;br /&gt; - Junit, XmlUnit&lt;br /&gt; - XStream an xml serializer/desiralizer&lt;br /&gt; - an UAT/Dev environment that runs.&lt;br /&gt;&lt;br /&gt;1 - identify the part the function you need to test&lt;br /&gt;&lt;br /&gt;you won&#39;t be able to test all the code, it is important to test a small&lt;br /&gt;chain of the code lest that the mocking will be too complex.&lt;br /&gt;&lt;br /&gt;It&#39;s likely that you can identify the function that is the entry and&lt;br /&gt;exit point&lt;br /&gt;&lt;br /&gt;  Object f1(Object... args)&lt;br /&gt;&lt;br /&gt;It is that function that we will try to unit test.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2 - record samples&lt;br /&gt;&lt;br /&gt;your system is probably generating high complex object, based on high&lt;br /&gt;complex entry. Trying to reproduce the graph manually is laborious and&lt;br /&gt;sure to be incomplete. That&#39;s what we need to used XStream to record the&lt;br /&gt;args and the output of the function in a uat environment, getting that&lt;br /&gt;way real life object.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;// the new method that will delegate to the old&lt;br /&gt;// and dump in and out&lt;br /&gt;Object f1(Object... args)  {&lt;br /&gt;  dumpIn(args);&lt;br /&gt;&lt;br /&gt;  Object o  = _f1(args);&lt;br /&gt;&lt;br /&gt;  dumpOut(o);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// was the real&lt;br /&gt;Object _f1(Object args) {&lt;br /&gt;       ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3 - integrate your sample in your unit test&lt;br /&gt;&lt;br /&gt;Now that you have sample with your input parameters and your expected&lt;br /&gt;result you can start writing your unit test.&lt;br /&gt;&lt;br /&gt;4 - mock the external call&lt;br /&gt;&lt;br /&gt;It is likely that once you integrate the sample in the unit test, the&lt;br /&gt;code will need to code external or internal component. you will need to&lt;br /&gt;refactor that code in specific method that you will overwrite for your&lt;br /&gt;test.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;class F {&lt;br /&gt;       Object _f1(Object... args) {&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;               // used to be inline&lt;br /&gt;               Object extInf = getExtInfo();&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;       Object getExtInfo() {&lt;br /&gt;        ....&lt;br /&gt;       }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class FTest extends F {&lt;br /&gt;&lt;br /&gt;       Object getExtInfo() {&lt;br /&gt;        return new MockObject();&lt;br /&gt;       }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If the object is to complex to Mock you can use the XStream to dump a&lt;br /&gt;sample in uat environment.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5 - run the test !&lt;br /&gt;&lt;br /&gt;6 - how to improve the solution&lt;br /&gt;&lt;br /&gt;It is possible to create the list of test automatically by scanning the&lt;br /&gt;samples directory e.g.. Making it easier to add sample and extend the&lt;br /&gt;coverage of the test and behaviour.&lt;br /&gt;&lt;br /&gt;This is an iterative process, it is not possible to make everything&lt;br /&gt;testable in one go, take your time and surely step by step the quality&lt;br /&gt;of your code will improve.</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/3982363275851358243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/3982363275851358243' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/3982363275851358243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/3982363275851358243'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2009/02/introducing-unit-testing-in-legacy-code.html' title='Introducing Unit Testing in Legacy code base'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-7191123513410010427</id><published>2008-07-25T05:38:00.000-07:00</published><updated>2008-07-25T05:39:16.763-07:00</updated><title type='text'>Dr. Horrible&#39;s Sing-Along Lyrics</title><content type='html'>&lt;a href=&quot;http://en.wikiquote.org/wiki/Dr._Horrible&#39;s_Sing-Along_Blog&quot;&gt;Here&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/7191123513410010427/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/7191123513410010427' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/7191123513410010427'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/7191123513410010427'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2008/07/dr-horribles-sing-along-lyrics.html' title='Dr. Horrible&#39;s Sing-Along Lyrics'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-2472990819758465934</id><published>2008-07-25T01:34:00.001-07:00</published><updated>2008-07-25T01:47:42.119-07:00</updated><title type='text'>The Java Spirit</title><content type='html'>- Composition is better than inheritance&lt;br /&gt;- Constructor are for initialization only&lt;br /&gt;- destructor/finalizer are for debugging only&lt;br /&gt;- Free resource explicitly&lt;br /&gt;- Declare the interface not the type ie List myList; not ArrayList myList&lt;br /&gt;- Optimize on metrics of a real system&lt;br /&gt;- Use a proper development environment&lt;br /&gt;- Don&#39;t believe the hype about closure, anonymous inner class cover 90% of the cases&lt;br /&gt;- Properties are private or protected.&lt;br /&gt;- Immutable is your friend.&lt;br /&gt;- Don&#39;t pool object, we are in the 21st century&lt;br /&gt;- Elegant code is code that is meaningful&lt;br /&gt;- the most useful api are : Collections, common-lang, java.text&lt;br /&gt;&lt;br /&gt;... To be continued</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/2472990819758465934/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/2472990819758465934' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/2472990819758465934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/2472990819758465934'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2008/07/java-spirit.html' title='The Java Spirit'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-1317630858573894436</id><published>2008-06-11T07:04:00.000-07:00</published><updated>2008-06-11T07:08:45.399-07:00</updated><title type='text'>Too many open file descriptors, leak detection</title><content type='html'>In Java it is good practice to manually free the resources such as Streams, Connection. This is the consequence of the non deterministic property of the Garbage Collector. You object that is not reference might wait minutes before being process - or might even never -, so you can rely and the destructor - the finalize method - to do that - the finalizer make the collection of the object really costly-.&lt;br /&gt;&lt;br /&gt;So if you open a Stream you should ideally do that :&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;InputStream is = null&lt;br /&gt;try {&lt;br /&gt;  is = new FileInputStream(...);&lt;br /&gt;  &lt;br /&gt;  ...&lt;br /&gt;&lt;br /&gt;} finally {&lt;br /&gt;  if (is != null) {&lt;br /&gt;    try { is.close(); ) catch(Exception e) { // IGNORE }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That&#39;s a lot of boiler plate code, and it&#39;s probably a good idea to use a Template pattern for that - look af Spring JDBCTemplate for example -.&lt;br /&gt;&lt;br /&gt;What happen if you don&#39;t do that? That depends on how many file you are gonna open.  It&#39;s really likely that the object is gonna get GC and FileInputStream as a finalizer where it closed itself.&lt;br /&gt;&lt;br /&gt;But if your application uses file intensively you might end up with &quot;Too many open file descriptors&quot; errors. If you&#39;re lucky you have few entry points where stream are open, so you can easily fix it. Otherwise you will need a way to take the part of the code that are erronous. &lt;br /&gt;&lt;br /&gt;What I propose under is to use &lt;a href=&quot;http://www.csg.is.titech.ac.jp/~chiba/javassist/&quot;&gt;Javassist&lt;/a&gt; to instrument the FileInputStrean and FileOutputStream class.&lt;br /&gt;&lt;br /&gt;First we need a class that we would inject into the FileXStream to capture the states and detect the leaks.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;package io;&lt;br /&gt;&lt;br /&gt;public class LeakDetector {&lt;br /&gt; &lt;br /&gt; private boolean closed;&lt;br /&gt; private Exception trace;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; public LeakDetector() {&lt;br /&gt;  trace = new Exception();&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public void close() {&lt;br /&gt;  this.closed = true;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; protected void finalize() {&lt;br /&gt;  if (! closed) {&lt;br /&gt;   printAlert();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private void printAlert() {&lt;br /&gt;  if (System.err != null) {&lt;br /&gt;   System.err.println(&quot;LeakDetector detected a leak from the object open at the following trace :&quot;);&lt;br /&gt;   trace.printStackTrace();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then we need a class that instruments the FileXStreams&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;package io;&lt;br /&gt;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.util.concurrent.Callable;&lt;br /&gt;&lt;br /&gt;import javassist.CannotCompileException;&lt;br /&gt;import javassist.ClassPool;&lt;br /&gt;import javassist.CtClass;&lt;br /&gt;import javassist.CtConstructor;&lt;br /&gt;import javassist.CtField;&lt;br /&gt;import javassist.CtMethod;&lt;br /&gt;import javassist.NotFoundException;&lt;br /&gt;&lt;br /&gt;public class Instrumenter implements Callable&amp;lt;Object&amp;gt; {&lt;br /&gt;&lt;br /&gt; private String[] clazzes;&lt;br /&gt; &lt;br /&gt; public Instrumenter(String[] args) {&lt;br /&gt;  this.clazzes = args;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) throws Exception {&lt;br /&gt;  &lt;br /&gt;  if (args == null || args.length == 0) {&lt;br /&gt;   args = new String[] { &quot;java.io.FileInputStream&quot;, &lt;br /&gt;     &quot;java.io.FileOutputStream&quot; };&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  new Instrumenter(args).call();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Object call() throws NotFoundException, CannotCompileException, IOException {&lt;br /&gt;  ClassPool pool = ClassPool.getDefault();&lt;br /&gt;  for(String clazz : clazzes) {&lt;br /&gt;   instrument(clazz, pool);&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  return null;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; private void instrument(String clazz, ClassPool pool) throws NotFoundException, CannotCompileException, IOException {&lt;br /&gt;  CtClass ctClass = pool.get(clazz);&lt;br /&gt;  &lt;br /&gt;  ctClass.addField(CtField.make(&quot;private io.LeakDetector __io_ld;&quot;, ctClass));&lt;br /&gt;  &lt;br /&gt;  for(CtConstructor cConst : ctClass.getConstructors()) {&lt;br /&gt;   cConst.insertBefore(&quot;__io_ld = new io.LeakDetector();&quot;);&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  for(CtMethod cMethod : ctClass.getMethods()) {&lt;br /&gt;   if (cMethod.getName().equals(&quot;close&quot;)) {&lt;br /&gt;    cMethod.insertBefore(&quot;__io_ld.close();&quot;);&lt;br /&gt;   } else if (cMethod.getName().equals(&quot;finalize&quot;)) {&lt;br /&gt;    cMethod.insertBefore(&quot;__io_ld._finalize();&quot;);&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  ctClass.writeFile(&quot;bin/java&quot;);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This class write the new FileInputStream in the bin/java directory. We need do assemble the LeakDetector and the new FileInputStream, FileOutputStream under the same jar. all you need to next is to run your application with the &quot;-Xbootclasspath/p:leakdetector.jar&quot; on the command line.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Note: Applications that use this technique for the purpose of overriding a system class in rt.jar should not be deployed as doing so would contravene the Java 2 Runtime Environment binary code license.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you run the following code, with the bootclasspath set : &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import java.io.FileInputStream;&lt;br /&gt;import java.io.FileOutputStream;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class DodgyIOClass {&lt;br /&gt;&lt;br /&gt; public static void main(String[] args) throws Exception {&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;  new FileOutputStream(&quot;c:/test.txt&quot;);&lt;br /&gt;  &lt;br /&gt;  new FileInputStream(&quot;c:/test.txt&quot;);&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;  Thread.sleep(3000);&lt;br /&gt;  System.gc();&lt;br /&gt;  Thread.sleep(3000);&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;It should prints :&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;LeakDetector detected a leak from the object open at the following trace :&lt;br /&gt;java.lang.Exception&lt;br /&gt; at io.LeakDetector.&amp;lt;init&amp;gt;(LeakDetector.java:11)&lt;br /&gt; at java.io.FileOutputStream.&amp;lt;init&amp;gt;(FileOutputStream.java)&lt;br /&gt; at java.io.FileOutputStream.&amp;lt;init&amp;gt;(FileOutputStream.java:70)&lt;br /&gt; at DodgyIOClass.main(DodgyIOClass.java:10)&lt;br /&gt;LeakDetector detected a leak from the object open at the following trace :&lt;br /&gt;java.lang.Exception&lt;br /&gt; at io.LeakDetector.&amp;lt;init&amp;gt;(LeakDetector.java:11)&lt;br /&gt; at java.io.FileInputStream.&amp;lt;init&amp;gt;(FileInputStream.java)&lt;br /&gt; at java.io.FileInputStream.&amp;lt;init&amp;gt;(FileInputStream.java:66)&lt;br /&gt; at DodgyIOClass.main(DodgyIOClass.java:12)&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/1317630858573894436/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/1317630858573894436' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/1317630858573894436'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/1317630858573894436'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2008/06/too-many-open-file-descriptors-leak.html' title='Too many open file descriptors, leak detection'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-8167586886096063904</id><published>2008-04-02T08:10:00.000-07:00</published><updated>2008-04-02T08:12:39.834-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="/"/><title type='text'>JSR 203 NIO 2 in Java 7</title><content type='html'>&lt;a href=&quot;http://blogs.sun.com/rajendrag/entry/jsr_203_new_file_system&quot; &gt;So it seems&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;That would be probably one of the most awaited fix, a well design file system api.&lt;br /&gt;&lt;br /&gt;no more &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;if (!file.delete())  {&lt;br /&gt; // delete did not work but I don&#39;t know why &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/8167586886096063904/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/8167586886096063904' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/8167586886096063904'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/8167586886096063904'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2008/04/jsr-203-nio-2-in-java-7.html' title='JSR 203 NIO 2 in Java 7'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-1029933802223540440</id><published>2008-03-28T09:22:00.000-07:00</published><updated>2008-03-28T09:23:46.913-07:00</updated><title type='text'>Java performance improvements touted</title><content type='html'>&lt;a href=&quot;http://www.infoworld.com/article/08/03/26/java-speed_1.html&quot; &gt;&lt;i&gt;&lt;br /&gt;&lt;b&gt;Java is not the slowpoke of old days and performance now matches or exceeds applications developed in C&lt;/b&gt;, technologists stressed Wednesday during a presentation at TheServerSide Java Symposium in Las Vegas.&lt;br /&gt;&lt;/i&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;From : &lt;a href=&quot;http://www.dzone.com/links/rss/java_performance_improvements_touted_infoworld_ne.html&quot;&gt;DZone&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Nice to see that written again.</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/1029933802223540440/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/1029933802223540440' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/1029933802223540440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/1029933802223540440'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2008/03/java-performance-improvements-touted.html' title='Java performance improvements touted'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-973374902577386972</id><published>2008-03-14T03:01:00.000-07:00</published><updated>2008-03-14T03:03:07.904-07:00</updated><title type='text'>IE 6 display = &#39;none&#39; not working</title><content type='html'>see &lt;a href=&quot;http://www.dynamicdrive.com/forums/showthread.php?t=6846&quot;&gt;Here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Using &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  element.style.display = &#39;&#39; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;instead solve the problem</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/973374902577386972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/973374902577386972' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/973374902577386972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/973374902577386972'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2008/03/ie-6-display-none-not-working.html' title='IE 6 display = &#39;none&#39; not working'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-7767979244056680102</id><published>2008-03-14T02:48:00.001-07:00</published><updated>2008-03-14T02:49:08.437-07:00</updated><title type='text'>How to disable escaping in xslt</title><content type='html'>&lt;pre&gt;&lt;br /&gt; &amp;lt;xsl:text disable-output-escaping=&quot;yes&quot;&gt;&amp;lt;!--&amp;lt;/xsl:text&gt;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/7767979244056680102/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/7767979244056680102' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/7767979244056680102'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/7767979244056680102'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2008/03/how-to-disble-escaping-in-xslt.html' title='How to disable escaping in xslt'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-1540466182070564831</id><published>2008-03-05T08:53:00.000-08:00</published><updated>2008-03-05T08:56:48.272-08:00</updated><title type='text'>NIO / IO debates</title><content type='html'>More NIO / IO benchmark or evidence &lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://paultyma.blogspot.com/2008/03/writing-java-multithreaded-servers.html&quot; &gt;Writing Java Multithreaded Servers - whats old is new (PDF Slides)&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;See &lt;a href=&quot;http://morningcofee.blogspot.com/2007/12/micro-benchmark-channel-vs-inputstream_04.html&quot; &gt;Micro benchmark Channel vs InputStream / 2&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/1540466182070564831/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/1540466182070564831' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/1540466182070564831'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/1540466182070564831'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2008/03/nio-io-debates.html' title='NIO / IO debates'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-5492759471938824099</id><published>2008-01-24T01:25:00.001-08:00</published><updated>2008-01-24T01:26:22.671-08:00</updated><title type='text'>String sorting tip</title><content type='html'>Good tip &lt;a href=&quot;http://blogs.sun.com/CoreJavaTechTips/entry/sorting_strings&quot;&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt; Collator esCollator =&lt;br /&gt;   Collator.getInstance(new Locale(&quot;es&quot;));&lt;br /&gt; Collections.sort(list, esCollator);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/5492759471938824099/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/5492759471938824099' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/5492759471938824099'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/5492759471938824099'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2008/01/string-sorting-tip.html' title='String sorting tip'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-491578277953767509</id><published>2008-01-05T04:13:00.000-08:00</published><updated>2008-04-30T06:04:03.066-07:00</updated><title type='text'>Image Resizer for widescreen picture frame and the main color problem</title><content type='html'>-- UPDate&lt;br /&gt;http://www.comesolvego.com/2008/04/29/resize-images-with-java-high-quality-and-working-solution/&lt;br /&gt;--&lt;br /&gt;&lt;br /&gt;For Xmas I receive a picture frame, unfortunately the image is expanded&lt;br /&gt;to the size of the frame without respecting the ratio.&lt;br /&gt;&lt;br /&gt;I try to find a batch solution to resize and fit the picture so that it&lt;br /&gt;would not be deformed.&lt;br /&gt;&lt;br /&gt;I did not find anything so I decided to try to write a small java&lt;br /&gt;program to do it.&lt;br /&gt;it would take the picture resize it so it fit in the frame and put it&lt;br /&gt;center in a image the size of the frame.&lt;br /&gt;&lt;br /&gt;It was relatively easy.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;package org.srf;&lt;br /&gt;&lt;br /&gt;import java.awt.Color;&lt;br /&gt;import java.awt.Graphics2D;&lt;br /&gt;import java.awt.Rectangle;&lt;br /&gt;import java.awt.RenderingHints;&lt;br /&gt;import java.awt.image.BufferedImage;&lt;br /&gt;&lt;br /&gt;public class FitImage {&lt;br /&gt;&lt;br /&gt; public BufferedImage  scaleImage(BufferedImage image, int width, int height) throws Exception {&lt;br /&gt;&lt;br /&gt;  int originalHeight = image.getHeight();&lt;br /&gt;  int originalWidth = image.getWidth();&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;  double scale = Math.min(&lt;br /&gt;    height/ (double)originalHeight,&lt;br /&gt;    originalWidth/ (double)originalWidth&lt;br /&gt;  );&lt;br /&gt;  &lt;br /&gt;  int newWidth = (int)Math.round(scale * originalWidth);&lt;br /&gt;  int newHeight = (int)Math.round(scale * originalHeight);&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;  // Draw the scaled image&lt;br /&gt;  BufferedImage thumbImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);&lt;br /&gt;  &lt;br /&gt;  Graphics2D graphics2D = thumbImage.createGraphics();&lt;br /&gt;  graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,&lt;br /&gt;    RenderingHints.VALUE_INTERPOLATION_BILINEAR);&lt;br /&gt;  &lt;br /&gt;  graphics2D.drawImage(image, 0, 0, newWidth, newHeight,&lt;br /&gt;    null);&lt;br /&gt;&lt;br /&gt;  return thumbImage;&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public BufferedImage frameImage(BufferedImage image, int width, int height, Color backgroundColor) throws Exception {&lt;br /&gt;  &lt;br /&gt;  int paddingX = (width - image.getWidth()) / 2;&lt;br /&gt;  int paddingY = (height - image.getHeight()) / 2;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;  // Draw the scaled image&lt;br /&gt;  BufferedImage thumbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;  Graphics2D graphics2D = thumbImage.createGraphics();&lt;br /&gt;  &lt;br /&gt;  graphics2D.setColor(backgroundColor);&lt;br /&gt;  &lt;br /&gt;  graphics2D.fill(new Rectangle(0, 0, width, height));&lt;br /&gt;  &lt;br /&gt;  graphics2D.drawImage(image, paddingX, paddingY, null);&lt;br /&gt;&lt;br /&gt;  return thumbImage;&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then what color do I want to draw the border. The average color of the&lt;br /&gt;picture? does not seems right if you have a picture with blue and green&lt;br /&gt;you might end up with a yellow ...&lt;br /&gt;&lt;br /&gt;So what about the dominant colour ? the main colour of the picture ?&lt;br /&gt;That quite a fusy concept like that. The color are distributed in a 4&lt;br /&gt;dimension space (red, green, blue, alpha) what would that mean to be the&lt;br /&gt;dominant color? What would be an efficient algorythm to determine it.&lt;br /&gt;&lt;br /&gt;I came up with something that give relatively good result also not sure&lt;br /&gt;about the validity of it.&lt;br /&gt;&lt;br /&gt;It iteratively cut the spaces in 2^4 boxes and keep the one where there&lt;br /&gt;is most color.&lt;br /&gt;It does the same thing on this box reduce it a specific number of time.&lt;br /&gt;As the color are define by a number between 0-256, each iteration&lt;br /&gt;dividing the solution possibilite by to, in 8 iteration I arrived to a&lt;br /&gt;result. What does it mean not sure... but on test I did it seems to work&lt;br /&gt;fine.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;package org.srf;&lt;br /&gt;&lt;br /&gt;import java.awt.Color;&lt;br /&gt;import java.awt.image.BufferedImage;&lt;br /&gt;&lt;br /&gt;public class ColorHelper {&lt;br /&gt; private boolean discardPixelOutOfTheBox = true;&lt;br /&gt; private boolean shiftRange = false;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; public void setDiscardPixelOutOfTheBox(boolean discardPixelOutOfTheBox) {&lt;br /&gt;  this.discardPixelOutOfTheBox = discardPixelOutOfTheBox;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; public void setShiftRange(boolean shiftRange) {&lt;br /&gt;  this.shiftRange = shiftRange;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; public Color getMainColor(BufferedImage image, int refineTo) {&lt;br /&gt;  Color c = null;&lt;br /&gt;  &lt;br /&gt;  int[] rgbs = image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;  int[][] colorRanges = new int[][]{ {0, 0xFF}, {0, 0xFF},{0, 0xFF}, {0, 0xFF}};&lt;br /&gt;  &lt;br /&gt;  for(int refine = 0; refine &lt; refineTo ; refine++) {&lt;br /&gt;   int[] colorSpace = new int[2 * 2 * 2 * 2];&lt;br /&gt;   for(int rgb : rgbs) {&lt;br /&gt;    int gi = calculateSpacePoint(colorRanges, rgb);&lt;br /&gt;    if (gi != -1 ) {&lt;br /&gt;     colorSpace[gi] ++;&lt;br /&gt;    }&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;   int ci = calculateSpacePointWinner(colorSpace);&lt;br /&gt;   &lt;br /&gt;   shrinkSpace(colorRanges, ci);&lt;br /&gt;   &lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  int[] crgbs = new int[4]; &lt;br /&gt;  // take middle of colorRange&lt;br /&gt;  for(int i = 0; i &lt; colorRanges.length; i++) {&lt;br /&gt;   int[] range = colorRanges[i];&lt;br /&gt;   crgbs[i] =  (range[0] +  range[1]) /2  ;&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  c = new Color(crgbs[2],crgbs[1],crgbs[0],   crgbs[3]);&lt;br /&gt;  &lt;br /&gt;  return c;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; private int calculateSpacePointWinner(int[] colorSpace) {&lt;br /&gt;  int ci = 0;&lt;br /&gt;  int ciValue = 0;&lt;br /&gt;  for(int i = 0; i &lt; colorSpace.length; i++) {&lt;br /&gt;   if (colorSpace[i] &gt; ciValue) {&lt;br /&gt;    ci = i;&lt;br /&gt;    ciValue = colorSpace[i];&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  return ci;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; private int calculateSpacePoint(int[][] colorRanges, int rgb) {&lt;br /&gt;  int gi = 0;&lt;br /&gt;  for(int i = 0; gi != - 1 &amp;&amp; i &lt; 4; i++) {&lt;br /&gt;   int v  = (rgb &gt;&gt; (i * 8)) &amp; 0xFF;&lt;br /&gt;   &lt;br /&gt;   if (!discardPixelOutOfTheBox &lt;br /&gt;     || (v &gt;= colorRanges[i][0] &amp;&amp; v &lt;= colorRanges[i][1])) {&lt;br /&gt;    int rangeMiddle = (colorRanges[i][0] + colorRanges[i][1]) / 2;&lt;br /&gt;    &lt;br /&gt;    int vi = v &lt; rangeMiddle ? 0:1;&lt;br /&gt;    &lt;br /&gt;    gi |=  vi &lt;&lt; i;&lt;br /&gt;   } else {&lt;br /&gt;    gi = -1;&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;  }&lt;br /&gt;  return gi;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; private void shrinkSpace(int[][] colorRanges, int ci) {&lt;br /&gt;  // re-adjust colorRange&lt;br /&gt;  for(int i = 0; i &lt; colorRanges.length; i++) {&lt;br /&gt;   int[] range = colorRanges[i];&lt;br /&gt;   int cri = (ci &gt;&gt; i ) &amp; 0x1;&lt;br /&gt;   &lt;br /&gt;   shrinkDimension(range, cri);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; private void shrinkDimension(int[] range, int cri) {&lt;br /&gt;  int rangeShift = shiftRange  ? (range[1] - range[0]) /4 : 0;&lt;br /&gt;  int middleRange = (range[0] +  range[1]) /2;&lt;br /&gt;  if (cri == 0) {&lt;br /&gt;   range[1] =  middleRange + rangeShift ;&lt;br /&gt;  } else {&lt;br /&gt;   range[0] = middleRange - rangeShift;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/491578277953767509/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/491578277953767509' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/491578277953767509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/491578277953767509'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2008/01/mage-resizer-for-widescreen-picture.html' title='Image Resizer for widescreen picture frame and the main color problem'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-4110108514171027072</id><published>2007-12-11T01:38:00.000-08:00</published><updated>2007-12-11T01:39:24.889-08:00</updated><title type='text'>XML/Castor notes 1</title><content type='html'>Marshal to a document object&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt; Document serializeObject(Object o) throws Exception {&lt;br /&gt;&lt;br /&gt;  DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();&lt;br /&gt;  &lt;br /&gt;  Document document = documentBuilder.newDocument();&lt;br /&gt;  &lt;br /&gt;  Marshaller marshaller = new Marshaller(d);&lt;br /&gt;  &lt;br /&gt;  synchronized (mapping) {&lt;br /&gt;   marshaller.setMapping(mapping);&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  marshaller.marshal(o);&lt;br /&gt;  &lt;br /&gt;  return document;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Write the Document to an xml file&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt; void write(Document doc, File f) throws Exception {&lt;br /&gt;  Transformer trans = TransformerFactory.newInstance().newTransformer();&lt;br /&gt;  &lt;br /&gt;  Source source = new DOMSource(doc);&lt;br /&gt;  Result result = new StreamResult(new FileOutputStream(f));&lt;br /&gt;  &lt;br /&gt;  trans.transform(source, result);&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/4110108514171027072/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/4110108514171027072' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/4110108514171027072'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/4110108514171027072'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2007/12/xmlcastor-notes-1.html' title='XML/Castor notes 1'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-8415037155275251110</id><published>2007-12-10T04:34:00.001-08:00</published><updated>2007-12-10T04:37:24.464-08:00</updated><title type='text'>Acegi 2</title><content type='html'>&lt;a href=&quot;http://blog.interface21.com/main/2007/12/06/whats-new-in-spring-security-2/&quot; &gt;does not kill fairy by murder anymore.&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/8415037155275251110/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/8415037155275251110' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/8415037155275251110'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/8415037155275251110'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2007/12/acegi-2.html' title='Acegi 2'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-5117738860226710451</id><published>2007-12-10T03:00:00.000-08:00</published><updated>2007-12-10T03:02:04.706-08:00</updated><title type='text'>Map &amp; Reduce explained for dummies</title><content type='html'>&lt;a href=&quot;http://www.joelonsoftware.com/items/2006/08/01.html&quot; &gt;Can Your Programming Language Do This?&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Also I&#39;m quite sure the cost of doing it in java is overrated - what about anonymous class, used in the common collection for example - ... This is a nice piece of explanation.</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/5117738860226710451/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/5117738860226710451' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/5117738860226710451'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/5117738860226710451'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2007/12/map-reduce-explained-for-dummies.html' title='Map &amp; Reduce explained for dummies'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-8606573300715465801</id><published>2007-12-06T07:34:00.001-08:00</published><updated>2007-12-06T07:39:50.763-08:00</updated><title type='text'>Interruptible Call</title><content type='html'>In the not so new concurrent api, a call - Executor.call(new Call()) can be cancel by the Future object return. &lt;br /&gt;&lt;br /&gt;Future.cancel(true) is gonna interrupt the thread. But does that mean that your code gonna stop automatically if it already started? Only if it&#39;s on a blocking call, which it&#39;s quite unlikely. So that your code is interruptible you need to test it the thread has been interrupted.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;   while(test) {&lt;br /&gt;      if (Thread.interrupted()) {&lt;br /&gt;         throw new InterruptedException();&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This way your cancel is more reactive.</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/8606573300715465801/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/8606573300715465801' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/8606573300715465801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/8606573300715465801'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2007/12/interruptible-call.html' title='Interruptible Call'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-5640362653304895884</id><published>2007-12-04T07:40:00.000-08:00</published><updated>2007-12-04T07:45:17.295-08:00</updated><title type='text'>Micro benchmark Channel vs InputStream / 2</title><content type='html'>If you follow actually the samples like &lt;a href=&quot;http://java.sun.com/j2se/1.4.2/docs/guide/nio/example/Grep.java&quot; &gt;Grep&lt;/a&gt;. Channel are slower than the BufferedReader&lt;br /&gt;&lt;br /&gt;On a directory with 16 files, with a total of 42 MB :&lt;br /&gt;nio direct=Time Taken: 3703ms,&lt;br /&gt;nio=Time Taken: 3781ms,&lt;br /&gt;io=Time Taken: 3063ms&lt;br /&gt;&lt;br /&gt;So ?&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; public class NIOReader implements Reader {&lt;br /&gt;&lt;br /&gt;  private ByteBuffer byteBuffer;&lt;br /&gt;  &lt;br /&gt;  public NIOReader(int bufferSize, boolean direct) {&lt;br /&gt;   if (direct) {&lt;br /&gt;    this.byteBuffer = ByteBuffer.allocateDirect(bufferSize);&lt;br /&gt;     &lt;br /&gt;   } else {&lt;br /&gt;    this.byteBuffer = ByteBuffer.allocate(bufferSize);&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public String readFile(File f) throws IOException {&lt;br /&gt;   FileInputStream fis = null;&lt;br /&gt;   FileChannel channel = null;&lt;br /&gt;   &lt;br /&gt;   try {&lt;br /&gt;    fis = new FileInputStream(f);&lt;br /&gt;    &lt;br /&gt;    channel = fis.getChannel();&lt;br /&gt;    &lt;br /&gt;    MappedByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0, channel.size());&lt;br /&gt;    &lt;br /&gt;    CharBuffer charBuffer = Charset.defaultCharset().decode(buffer);&lt;br /&gt;&lt;br /&gt;    return charBuffer.toString();&lt;br /&gt;    &lt;br /&gt;   } finally {&lt;br /&gt;    if (fis != null)&lt;br /&gt;     fis.close();&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/5640362653304895884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/5640362653304895884' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/5640362653304895884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/5640362653304895884'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2007/12/micro-benchmark-channel-vs-inputstream_04.html' title='Micro benchmark Channel vs InputStream / 2'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-2106998711846491458</id><published>2007-12-04T02:27:00.000-08:00</published><updated>2007-12-04T02:40:20.267-08:00</updated><title type='text'>Micro benchmark Channel vs InputStream</title><content type='html'>I wrote a little non representative test to check is it was worth rewriting the IO, in an application that write and read a lot of data from the file system, using the not so new NIO api.&lt;br /&gt;&lt;br /&gt;On a directory with containing 8 305 files all around 1 to 4 KB the result are around :&lt;br /&gt;nio direct=Time Taken: 5610ms&lt;br /&gt;nio=Time Taken: 5766ms &lt;br /&gt;io=Time Taken: 5578ms&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;On a directory with 16 files, with a total of 42 MB :&lt;br /&gt;nio direct=Time Taken: 875ms&lt;br /&gt;nio=Time Taken: 906ms&lt;br /&gt;io=Time Taken: 3079ms&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So for big files it&#39;s definitly worth it, but not for small file. &lt;br /&gt;&lt;br /&gt;It&#39;s tested under windows XP, would the result be the same under a Unix OS? Don&#39;t know ...&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;import java.io.File;&lt;br /&gt;import java.io.FileInputStream;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.nio.ByteBuffer;&lt;br /&gt;import java.nio.channels.FileChannel;&lt;br /&gt;import java.util.HashMap;&lt;br /&gt;import java.util.Map;&lt;br /&gt;&lt;br /&gt;import junit.framework.TestCase;&lt;br /&gt;&lt;br /&gt;import org.apache.log4j.Logger;&lt;br /&gt;&lt;br /&gt;public class NIOTest  extends TestCase {&lt;br /&gt; &lt;br /&gt; private static Logger  logger= Logger.getLogger(NIOTest.class);&lt;br /&gt; public class NIOReader implements Reader {&lt;br /&gt;&lt;br /&gt;  private ByteBuffer byteBuffer;&lt;br /&gt;  &lt;br /&gt;  public NIOReader(int bufferSize, boolean direct) {&lt;br /&gt;   if (direct) {&lt;br /&gt;    this.byteBuffer = ByteBuffer.allocateDirect(bufferSize);&lt;br /&gt;     &lt;br /&gt;   } else {&lt;br /&gt;    this.byteBuffer = ByteBuffer.allocate(bufferSize);&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public String readFile(File f) throws IOException {&lt;br /&gt;   FileInputStream fis = null;&lt;br /&gt;   FileChannel channel = null;&lt;br /&gt;   StringBuilder sb = new StringBuilder((int)f.length());&lt;br /&gt;   &lt;br /&gt;   try {&lt;br /&gt;    fis = new FileInputStream(f);&lt;br /&gt;    &lt;br /&gt;    channel = fis.getChannel();&lt;br /&gt;    &lt;br /&gt;    &lt;br /&gt;    while(channel.read(byteBuffer) != -1) {&lt;br /&gt;     byteBuffer.flip();&lt;br /&gt;     sb.append(byteBuffer.toString());&lt;br /&gt;     byteBuffer.clear();&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;   } finally {&lt;br /&gt;    if (fis != null)&lt;br /&gt;     fis.close();&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;   return sb.toString();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt; public class IOReader implements Reader {&lt;br /&gt;&lt;br /&gt;  private byte[] buffer;&lt;br /&gt;&lt;br /&gt;  public IOReader(int bufferSize) {&lt;br /&gt;   this.buffer = new byte[bufferSize];&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public String readFile(File f) throws IOException {&lt;br /&gt;   FileInputStream fis = null;&lt;br /&gt;   &lt;br /&gt;   StringBuilder sb = new StringBuilder((int)f.length());&lt;br /&gt;   &lt;br /&gt;   try {&lt;br /&gt;    fis = new FileInputStream(f);&lt;br /&gt;    &lt;br /&gt;    int c = -1;&lt;br /&gt;    &lt;br /&gt;    while( (c = fis.read(buffer)) != -1) {&lt;br /&gt;     sb.append(new String(buffer, 0 , c));&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;   } finally {&lt;br /&gt;    if (fis != null)&lt;br /&gt;     fis.close();&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;   return sb.toString();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; File dir = new File (&quot;C:\\my directory with files&quot;);&lt;br /&gt; &lt;br /&gt; int size = 3;&lt;br /&gt; int buffer = 4096;&lt;br /&gt; &lt;br /&gt; public void testIO() throws IOException {&lt;br /&gt;  for (int i = 0 ; i &lt; size; i++) {&lt;br /&gt;   Map&lt;String, StopWatch&gt; stopWatches = new HashMap&lt;String,StopWatch&gt;();&lt;br /&gt;   &lt;br /&gt;   logger.info(&quot;test io&quot;);&lt;br /&gt;   stopWatches.put(&quot;io&quot;, testLoop(size, new IOReader(buffer), dir));&lt;br /&gt;   logger.info(&quot;test nio&quot;);&lt;br /&gt;   stopWatches.put(&quot;nio&quot;, testLoop(size, new NIOReader(buffer, false), dir));&lt;br /&gt;   logger.info(&quot;test nio direct&quot;);&lt;br /&gt;   stopWatches.put(&quot;nio direct&quot;, testLoop(size, new NIOReader(buffer, true), dir));&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;   logger.info(stopWatches.toString());&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public StopWatch testLoop(int size, Reader reader, File dir) throws IOException {&lt;br /&gt;  StopWatch stopWatch = new StopWatch();&lt;br /&gt;  &lt;br /&gt;  stopWatch.start();&lt;br /&gt;  &lt;br /&gt;  for(int i = 0; i &lt; size; i ++) {&lt;br /&gt;   test(reader, dir);&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  stopWatch.stop();&lt;br /&gt;  &lt;br /&gt;  logger.info(&quot;end loop &quot; +stopWatch);&lt;br /&gt;  return stopWatch;&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public void test(Reader r, File dir) throws IOException {&lt;br /&gt;  for(File f: dir.listFiles()) {&lt;br /&gt;   if (f.isFile()) {&lt;br /&gt;    String str = r.readFile(f);&lt;br /&gt;    //logger.debug(&quot;read &quot;+ str.length()+&quot; in &quot;+f);&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; interface Reader {&lt;br /&gt;  String readFile(File f) throws IOException;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/2106998711846491458/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/2106998711846491458' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/2106998711846491458'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/2106998711846491458'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2007/12/micro-benchmark-channel-vs-inputstream.html' title='Micro benchmark Channel vs InputStream'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-5383540155554805674</id><published>2007-11-29T09:39:00.001-08:00</published><updated>2007-11-29T09:39:47.412-08:00</updated><title type='text'>7.4 Preventing Castor from checking for a default constructor (since 0.9.5)</title><content type='html'>Sometimes it&#39;s useful to prevent Castor from checking for a default constructor, such as when trying to write a mapping for an interface or type-safe enum. You can use the &quot;undocumented&quot; verify-constructable=&quot;false&quot; attribute on the &lt;class&gt; element to prevent Castor from looking for the default constructor. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;been looking for this one ...&lt;br /&gt;&lt;a href=&quot;http://castor.codehaus.org/xml-mapping.html&quot; &gt;See&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/5383540155554805674/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/5383540155554805674' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/5383540155554805674'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/5383540155554805674'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2007/11/74-preventing-castor-from-checking-for.html' title='7.4 Preventing Castor from checking for a default constructor (since 0.9.5)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-991875526381644589</id><published>2007-11-28T01:36:00.000-08:00</published><updated>2007-11-28T01:37:04.337-08:00</updated><title type='text'>Interesting post ab out Database Partitioning using Spring</title><content type='html'>&lt;a href=&quot;http://www.jroller.com/kenwdelong/entry/horizontal_database_partitioning_with_spring&quot; &gt;Horizontal Database Partitioning with Spring and Hibernate&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/991875526381644589/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/991875526381644589' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/991875526381644589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/991875526381644589'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2007/11/interesting-post-ab-out-database.html' title='Interesting post ab out Database Partitioning using Spring'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4396093936384561136.post-1882850638841656570</id><published>2007-11-01T06:10:00.000-07:00</published><updated>2007-11-01T06:18:35.815-07:00</updated><title type='text'>Castor elusive StackOverflowError</title><content type='html'>On one of my project, I&#39;m using Casor - 1.1.2.1 - to serialize an object tree to xml. At the beginning of the week I had a weird StackOverflowError when writing a big set of objects. I did not pay much attention do it, was not a priority. &lt;br /&gt;&lt;br /&gt;Today I had the same error, on a very reasonably size object tree. So I try to find where it was comming from - a cycling mapping maybe ... -. I putted my eclipse in debug mode, and add a breakpoint on the error. And then no more SOE ... but a error when setting the mapping in the Marshaller... weird ...&lt;br /&gt;&lt;br /&gt;What can it be? that looks like a multi thread issue... But the Marshaler are both distinct, the only common thing is the Mapping. Could it be ? &lt;br /&gt;So I replaced&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; Marshaller marshaller = new Marshaller(serializer&lt;br /&gt;   .asDocumentHandler());&lt;br /&gt; if (mapping != null) {&lt;br /&gt;     marshaller.setMapping(mapping);&lt;br /&gt; }&lt;br /&gt; marshaller.marshal(o);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;with &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; Marshaller marshaller = new Marshaller(serializer&lt;br /&gt;   .asDocumentHandler());&lt;br /&gt; if (mapping != null) {&lt;br /&gt;  synchronized (mapping) {&lt;br /&gt;   marshaller.setMapping(mapping);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; marshaller.marshal(o);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And it solve my problem.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;Castor Mapping object is not Thread Safe...&lt;br /&gt;&lt;br /&gt;How weird....</content><link rel='replies' type='application/atom+xml' href='http://morningcofee.blogspot.com/feeds/1882850638841656570/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4396093936384561136/1882850638841656570' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/1882850638841656570'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4396093936384561136/posts/default/1882850638841656570'/><link rel='alternate' type='text/html' href='http://morningcofee.blogspot.com/2007/11/castor-elusive-stackoverflowerror.html' title='Castor elusive StackOverflowError'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>