Older blog entries for waffel (starting at number 7)

Fast stream copy using java.nio channels


Many times I was asked how to copy fast and simple an input stream to an output stream. I have found a nice solution on koders.com . A programmer named Mr. Hitchens has contributed this code.

Here are my utility method which makes the real fast copy stuff:


public final class ChannelTools {
  public static void fastChannelCopy(final ReadableByteChannel src, final WritableByteChannel dest) throws IOException {
    final ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024);
    while (src.read(buffer) != -1) {
      // prepare the buffer to be drained
      buffer.flip();
      // write to the channel, may block
      dest.write(buffer);
      // If partial transfer, shift remainder down
      // If buffer is empty, same as doing clear()
      buffer.compact();
    }
    // EOF will leave buffer in fill state
    buffer.flip();
    // make sure the buffer is fully drained.
    while (buffer.hasRemaining()) {
      dest.write(buffer);
    }
  }
}

And how you can use this method to copy an input stream into an output stream? Here comes the answer:


// allocate the stream ... only for example
final InputStream input = new FileInputStream(inputFile);
final OutputStream output = new FileOutputStream(outputFile);
// get an channel from the stream
final ReadableByteChannel inputChannel = Channels.newChannel(input);
final WriteableByteChannel outputChannel = Channels.newChannel(output);
// copy the channels
ChannelTools.fastChannelCopy(inputChannel, outputChannel);
// closing the channels
inputChannel.close();
outputChannel.close()

Syndicated 2007-10-09 09:21:31 from waffel's Weblog

Replacing deprecated ValueBindung stuff from JSF with ELResolver


I have searched for a solution to replace the as deprecated marked ValutBinding stuff with a better solution.

For example if you have a method to retrieve a JSF Bean from the faces context:

public static Object accessBeanFromFacesContext(final String theBeanName, final FacesContext theFacesContext) {
final StringBuffer valueBinding = new StringBuffer();
valueBinding.append(’#');
valueBinding.append(’{');
valueBinding.append(theBeanName);
valueBinding.append(’}');
final Object returnObject = theFacesContext.getApplication().
createValueBinding(valueBinding.toString()).getValue(theFacesContext);
if (returnObject == null) {
LOG
.error(”Bean with name ” + theBeanName + ” was not found. Check the faces-config.xml file if the given bean name is ok.”); //$NON-NLS-1$ //$NON-NLS-2$
}
return returnObject;
}

You can replace this now with following code:

public static Object accessBeanFromFacesContext(final String theBeanName, final FacesContext theFacesContext) {
final Object returnObject = theFacesContext.getELContext().getELResolver().getValue(theFacesContext.getELContext(), null, theBeanName);
if (returnObject == null) {
LOG
.error(”Bean with name ” + theBeanName + ” was not found. Check the faces-config.xml file if the given bean name is ok.”); //$NON-NLS-1$ //$NON-NLS-2$
}
return returnObject;
}

This retrieves a bean from the faces context. You can use the method for example to retrieve a TestBean form the faces context like

TestBean testBean = (TestBean)JSFUtils.accessBeanFromFacesContext(”testBean”, FacesContext.getCurrentInstance());

The TestBean object have to be added to the faces-config.xml as a managed bean. If the bean was not created at the point where you ask for it, the default constructor is called and the bean is created for you from the JSF framework.

Syndicated 2007-09-27 09:21:22 from waffel's Weblog

log4cpp release 1.0


A little bit late but hopefully for your interest.

I have pushed out the 1.0 release of the nice log4cpp package.

This release contains many small bug fixes and some new features. Currently we have problems under some windows environments with the building. But hey … I don’t have any platform, we support in this project to test it. Because my main focus is on linux, I have only created and tested it under the cool gentoo environment.

Today my friend ahöhma has created his own blogg (in german only).

Syndicated 2007-09-24 13:11:45 from waffel's Weblog

Welcome


Hello anybody!

This is my first Blog on wordpress and I hope that I have enough time to blog anymore than yet.

Today I have recieved bad new from the columba project. Our maintainer leaves the project. You can read his blog here.

- waffel

Syndicated 2007-08-13 08:01:03 from waffel's Weblog

buzztard

Created the buildbot and buildmaster for buzztard (see Buildbot project page). The buildbot runs now every 6 hours. Currently it builds the application but the test cases fails. Will have a look today whats wrong there.

JSF

Got today the book "pro JSF and Ajax" from Jonas Jacobi and John R. Fallows. I will read it the next days and hope they can help me to develop some nice ajax enabled JSF components.

The communication problem with my big application is now solved and looks after the first test working.

JSF

Started to work with Java Server Faces. It is quite complicated to learn and the best documentation is currently the mailling list.

I have to create a big application where my small part is called from one struts application, and then I have to call inside the java server faces application another struts web application. Quite complicated but I hope I can reache this today.

Log4cpp

Two new developers are now on the project.

I have to check there commits and create a small release.

Currently there are many open bug and one security patch on the mailling list.

Getting gnome-vfs compiling from cvs.

Today I got gnome-vfs compiling on my gentoo box. With the help of jhbuild it was easy to compile gnome core stuff from cvs and then compiling gnome-vfs from my project folder.

With the help of the command jhbuild shell I can switch to the gnome-cvs environment and check out the newest stuff.

Now it's time to start working on the gnome-vfs zip module.

Wow. Today I had the time to update log4cpp and applying some patches I got from the maillinglist.

Now it's time for another minor release with some fixups and cleanups. Removed the debian directories and build dependencies because we have now a debian package manager.

But before I must fix the testchain.

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!