Reading/writing compressed and not compressed files in Java

Main reason for this post is trying don’t repeat yourself (DRY) because, often, I fall in the recursive need to read and write compressed and not compressed files (mainly JSON and CSV).

Let’s to see first how to read text files. Note I’m working with (relatively small) text files so:

  1. The read methods returns an String with the whole content.
  2. I’m using BufferedReader to read line by line.

Note: there are more than one way to do things. In the entry Best way to read a text file, where you can find many different ways to read a text file depending on your JDK version and the size of the file.

Similarly to write a String to a file:

To read/write compressed files, that is with binary data, we need to work with streams and buffers. So to read a GZIP compressed file and obtain a String:

and similarly to write a String to a GZip compressed file:


Next you can find a couple of great links with Java code for various JDK versions:

Related Posts:

Using more than one property file in Spring MVC

Spring is one of the most important, powerful and also complex frameworks in the actual Java panorama.

Unfortunately for me, I’m very forgetful so it is worth to write a post-reminder to increment the possibilities I never forget again something like this.

Using property files in Spring

Since Spring 3, the use of properties in our code was made really simple thanks to the placeholders.

Supposing a property file with next content:

It is enough to add the next configuration element in our servlet configuration XML file:

Later, at any place of our program we can easily get the properties using @Value annotation:

And what if you have more than one property files?

Supposing we have a second property file with the values:

Spring allows to specify more than one properties file adding a new placeholder:

The problem comes when you try to use the property from the second file, using @Value("${second_file_prop}"), Spring will throw an exception saying it can find the second_file_prop value. This is because Spring try to find the property in the first file and if it does not find it throws an error.

To avoid this ugly effect we need to use the ignore-unresolvable attribute in the placeholder:

This way if Spring does not find a property in the first file it will continue looking at the second one.

The order

In addition, the placeholder element can use the order attribute that determines the order in which Spring must look at the files. So a good way to express the previous configuration is:

Related Posts:

The Book: GeoServer Beginner’s Guide

GeoServer is one of the most importants open source geospatial servers nowadays. Implemented in Java, based on the powerful GeoTools libraries, GeoServer offers a great degree of interporability publishing data from major spatial data sources using Open Geospatial Consortium (OGC) standards.

Hopefully, for those who work or start working with GeoServer, recently Packt Publishing has released a new book titled GeoServer Beginner’s Guide.

Written by Stefano Iacovella, with contributions from Brian Youngblood, the book guide us on the main topics to work with GeoServer, through the next list of chapters:

Chapter 1: GIS Fundamentals
Chapter 2: Getting Started with GeoServer
Chapter 3: Exploring the Administrative Interface
Chapter 4: Accessing Layers
Chapter 5: Adding Your Data
Chapter 6: Styling Your Layers
Chapter 7: Creating Simple Maps
Chapter 8: Performance and Caching
Chapter 9: Automating Tasks: GeoServer REST Interface
Chapter 10: Securing GeoServer Before Production
Chapter 11: Tuning GeoServer in a Production Environment
Chapter 12: Going Further: Getting Help and Troubleshooting

Despite of its title, the book is great from newbies to those with intermediate knowledges on GeoServer, and also put some efforts on advance topics, like performance and configuration for production environment chapters.

Personally, I like the way Stefano writes: simply, plain and, most important, making clear complex questions. In addition, the book is plenty of samples and figures which help us to understand better what is talking on.

Conceptually, we can divide the book in three sections: introduction (chapter 1, 2 and 3), basic or common usage (chapters 4, 5, 6 and 7) and advanced topics (chapter 8, 9, 10 and 11).

The book introduces us in the GIS world  (chapter 1) starting with an introduction of many related topics: projections, coordinate systems, modeling information, etc. After this, it shows how to install GeoServer (chapter 2) in two different operating systems: Ubuntu Linux and Windows and finally, passed to show the main aspects of the administrative interface of GeoServer (chapter 3).

From here, the book covers the main aspect on how to access, add and serve data (chapter 4 and 5), how to style to serve them in a better way (chapter 6) and basic samples on how to create maps against GeoServer using Google Maps, OpenLayers and Leaflet libraries.

The third block, concentrates improving the performance of the server using the GeoWebCache system (chapter 8), administer GeoServer via its REST interface (chapter 9), securing its access and administration (chapter 10) and tune it up ready for a production environment (chapter 11).

The book is mainly oriented to WMS but dedicates the chapter 12 to talk specifically on WFS and WCS, also supported by GeoServer.

Without a doubt, GeoServer Beginner’s Guide is a book must be on your working table.

Related Posts:

Architexa product review

Architexa product is an Eclipse plugin from company. As their web site say:

Architexa helps you understand and document large/complex Java code bases within Eclipse

and allowing to create and explore diagrams that make sense.

I have tried it really little but the conclusions are clear: Architexa is a tool with a great potential.


Installing Architexa is really easy because it is prepared as any other Eclipse plugin (see the install section).

I’m using Eclipse 4.2 (Juno) and the steps were:

  • Go to Help > Install new software and add a new place called architexa with the URL:
  • Select the Architexa plugin and click next button until installation is done.

Really easy, don’t you?

After Eclipse restarts you will be asked for a valid Architexa user. Go to the registration page and register for a free license. That’s all.

Exploring a project

To test Architexa I have opened a relatively small maven project, which allows to download files from an FTP server. It haven’t a great domain model neither thousand of classes but has all the necessary to test the basic Architexa capabilities.

  • Layered diagrams
  • Class diagrams
  • Sequence diagrams

The bad

Before to continue, I must say Architexa seems to me a product with a great potential, but on the other hand it leaves me with bad feelings.

I prefer to comment all the bad things first so the good things comes later and the reader was left with a good feeling.

  • The Architexta web site is IMO horrible and much more the personal area of each user ( In addition it seems not much stable, at least for me the profile and setting sections fails with a 500 server error.
  • Once Architexa is installed it needs to build an index from your code. Initially I don’t built the index (when the tool ask me to do it) and after importing the project and building it by hand, it seems not work properly. For some reason my index was corrupted and I need to remove and import the project a couple of times before it woks.
  • The layered, class and sequence diagrams are powerful tools but the way to explore and navigate could be a bit more intuitive. In addition the shapes and colors used could be improved.

As you can see the bad things are almost all related to design and visual aspects, not to the product functionality. Nothing a good web designer can solve.

My opinion for Architexa guys is: Architexa is a great product so make it looks like a great product.

Working with the diagrams

Because the project is a small the most useful diagrams has been the class and sequence diagrams.

In the case of class diagram I added some classes related to the task to download and read radar files. Once a class is added to the diagram you can make actions like:

  • select which methods can be visible in the diagram
  • navigate from a method to other classes (show called method)
  • show which classes references a method (show calling method)

Thanks to this actions you can explore the classes and its dependencies in both directions.

The sequence diagram works in a similar way, you start adding a class or method and, for example, given a method add all the used methods from the same class or from other classes:

Finally, in the layered diagram I have added some classes to see its dependencies. Easily we can see the classes and the packages they belong to.

In addition, on any diagram you can select a class or method and navigate directly to the source code to see the corresponding lines of code.


As I commented previously Architexa is a tool with a great potential. It can help team members to understand better how code works or documenting processes.

As a future features I would like to suggest its integration with the debugger. First the possibility to highlight the current executed method on the class or sequence diagram. Second, the possibility to allow to create a diagram step by step while debugging, that is, selecting which methods or classes we want to add to the sequence diagram while advancing step by step in the code.

Congratulations to the Architexa team for their product !!!

Related Posts: