Changed default options for cryptsetup

I use encrypted USB disks for my personal backups. When I tried to mount a disk on a CentOS 6 host recently it failed. What had happened? It turned out that I had used the default options for cryptsetup and the defaults changed between the versions used in CentOS 5 and 6. To fix the problem I simply had to specify the old default values:

cryptsetup create -c aes-cbc-plain -s 256 -h ripemd160 usbbackup /dev/sdd

Perhaps it is better to avoid defaults anyway.

Categories: Linux

Add Eclipse Marketplace to MuleSoft Anypoint Studio

Anypoint Studio, the IDE for Mule, is based on Eclipse, but ships without the Marketplace client. That is a pity, as it makes it harder to add useful extensions. Fortunately it is easy to fix. Select “Help/Install New Software…” and add the Juno repository ( as a site to work with. Search for Marketplace Client. It is found under General Purpose Tools.

Install Eclipse Marketplace client

Install it and there you are!

Note that this covers the current version of Anypoint Studio for Mule 3.5, which is based on Eclipse 3.8. Future versions may not use the Juno repository. Check the version of Eclipse that Anypoint is based on and use the proper repository.

Categories: Mule

Jens wins CodeMint’s coding challenge

CodeMint’s coding challenge is over and Jens Lideström is the winner! Check out the results in order to learn about high-performance lambda functions and streams for Java 8. The text is in Swedish, but the code speaks for itself.

The challenge was to process weather data from NCDC as fast as possible using the new streams and lambda functions available in Java SE 8. Jens used a custom spliterator in order to win. My solution is short and to the point, but it is four seconds slower. Congratulations to Jens (who joins CodeMint as a new consultant Tomorrow!).

Categories: Java

First Google Glass application released

Last week I released my first real GlassWare! It is a really cool application, but unfortunately under non-disclosure. Anyway, my first impressions of Google Glass as a target platform are fairly positive.
The API is still changing and that can make life a bit difficult. Some samples target the wrong version and either won’t compile or crash. Furthermore my computer wouldn’t recognize Google Glass correctly at first, so adb couldn’t find it as a device. I solved that as explained in this post. Finally the voice recognition for my Swedish accent is – well, let’s settle for not perfect.
All in all, though, it is fun to develop for Google Glass! The bleading edge is where I want to be.

Categories: Android, Google Glass, Java

Lazily read lines from gzip file with Java 8 streams

Java 8 can read lines lazily from files using the Files.lines method, but what to do if the files are compressed? I needed to do just that, so here is a class that provides a line stream from a gzipped file. It can easily be converted for other file formats!

public class GZIPFiles {
   * Get a lazily loaded stream of lines from a gzipped file, similar to
   * {@link Files#lines(java.nio.file.Path)}.
   * @param path
   *          The path to the gzipped file.
   * @return stream with lines.
  public static Stream<String> lines(Path path) {
    InputStream fileIs = null;
    BufferedInputStream bufferedIs = null;
    GZIPInputStream gzipIs = null;
    try {
      fileIs = Files.newInputStream(path);
      // Even though GZIPInputStream has a buffer it reads individual bytes
      // when processing the header, better add a buffer in-between
      bufferedIs = new BufferedInputStream(fileIs, 65535);
      gzipIs = new GZIPInputStream(bufferedIs);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    BufferedReader reader = new BufferedReader(new InputStreamReader(gzipIs));
    return reader.lines().onClose(() -> closeSafely(reader));

  private static void closeSafely(Closeable closeable) {
    if (closeable != null) {
      try {
      } catch (IOException e) {
        // Ignore

Share and enjoy…

Categories: Java

Affordable UML plugins for Eclipse

Nowadays there are almost as many UML plugins for Eclipse as there are logging frameworks for Java. While this is good, it makes it hard to pick the right one. Many are obsolete, but they still show up in search results. Others are overpriced to say the least.

Personally I don’t need a general-purpose UML editor in Eclipse. I tend to use Visio with a custom Visio UML stencil. What I need is a cheap, light-weight plugin that can generate good-looking class diagrams and sequence diagrams from the code. If it is free and open source, so much the better. It should be really easy to use and ideally it should be possible to tweak the generated diagrams manually.

ModelGoon UML4Java is free. It can generate class diagrams and sequence diagrams in a snap. It supports conditional statements and loops, which is important in some cases. Unfortunately there is little support for customizing the diagrams. I often want to remove all logging calls from sequence diagrams, for example, and ModelGoon does not support that. Furthermore it fails on some language constructs, such as for(;;) loops. Nevertheless, when it works it is good enough and gets the job done!

ObjectAid UML Explorer is another tool. It requires a license for sequence diagrams ($19 for a single user as of this writing), class diagrams are free. It is easy to use and generates good-looking diagrams that can be tweaked. Removing all logging calls is as easy as removing the logger class from the diagram. Unfortunately there seems to be no support for conditionals or loops. That can make it very difficult to see what is going on in some cases. If it is improved a bit it can be a winner.

Do you know of a better tool with an acceptable price tag? If so, let me know.

Categories: Java

Convert from milliseconds since epoch to Oracle timestamp

Today I needed to convert from numbers in a log file originally generated using System.currentTimeMillis() in Java to Oracle timestamps and I wanted to do it with PL/SQL, without involving Java in the database. I love Java, but inside Oracle? No thanks.

Surely this is simple and surely the Internet abounds with examples? No and no. It is easy to create a date, but date columns loose precision. I needed to preserve the milliseconds. There are many examples for getting the number of milliseconds since the epoch from an Oracle timestamp, but not for creating a timestamp from a millisecond value.

After some thinking I ended up with the following code:

create or replace function millis_to_timestamp(p_millis in number)
  return timestamp is
  v_datePart date;
  v_millisPart number;
  v_datePart := to_date('19700101', 'YYYYMMDD') + (p_millis / 86400000);
  v_millisPart := mod(p_millis, 1000);
  return to_timestamp(to_char(v_datePart, 'YYYYMMDDHH24MISS') ||
         substr(to_char(v_millisPart + 1000), 2, 3), 'YYYYMMDDHH24MISSFF');

Not that pretty, but it works! Share and enjoy…

Categories: Database, Oracle

Get every new post delivered to your Inbox.