Jan 222014
 
/* Copyright (c) 2014 Aaron Johnson
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 */

    /** Returns the next available non-existent file by incrementing a numerical value at the end of the file name. <br/> Copyright (c) 2014 Aaron Johnson <br/>
     * abcdefg.html -> abcdefg.1.html -> abcdefg.2.html -> abcdefg.3.html -> abcdefg.4.html <br/>
     * abcdefg -> abcdefg.1 -> abcdefg.2 -> abcdefg.3 -> abcdefg.4 <br/>
     * @param originalFile
     * @return
     */

    public static File findNextAvailableFilename(final File originalFile) {
        final Path originalPath = Paths.get(originalFile.getAbsolutePath());
        String extension = FilenameUtils.getExtension(originalPath.toString());

        // if there is no extension then we just add .
        if (extension.length() > 0) {
            extension = "." + extension;
            // if the number is in the extension then there is no extension - there is only the number.
            if (extension.matches("[.]\\d+")) {
                extension = "";
            }
        }
        Path path = originalPath;

        // loop until the file does not exist.
        while (Files.exists(path)) {
            // find and extract the number currently used.
            int number = 0;
            String newFilename = originalPath.getFileName().toString();
            if (newFilename.matches(".+[.]\\d+" + Pattern.quote(extension))) {
                number = Integer.valueOf(newFilename.replaceFirst(".+[.](\\d+)" + Pattern.quote(extension), "$1"));
            }
            number++;

            // if there is a number currently used then replace it.
            if (newFilename.matches(".+[.]\\d+" + Pattern.quote(extension))) {
                newFilename = newFilename.replaceFirst("(.+[.])(\\d+)" + Pattern.quote(extension), "$1" + number + extension);
            } else {
                // there is no number currently used so insert a number.
                final String filenameWithoutExtension = newFilename.substring(0, newFilename.length() - extension.length());
                newFilename = filenameWithoutExtension + "." + number + extension;
            }
            path = originalPath.getParent().resolve(newFilename);
        }

        return path.toFile();
    }


// -----------------------

    /** Copyright (c) 2014 Aaron Johnson <br/>
     * Test method for {@link #findNextAvailableFilename(java.io.File)}.
     * @throws IOException
     */

    @Test(timeout=3000)
    public void testFindNextAvailableFilenameWithExtension() throws IOException {
        final List<Path> filesToDelete = new LinkedList<>();
        try {
            final Path tempFolder = Paths.get(System.getProperty("java.io.tmpdir"));
            Path tempFile = tempFolder.resolve(FileDescriptionTestCase.class.getSimpleName() + ".html");

            // assure the file does not exist.
            Files.deleteIfExists(tempFile);

            // this should return the same name because the file name is available.
            File newFilename = FileUtils.findNextAvailableFilename(tempFile.toFile());
            assertEquals("The same file should have been returned because the file doesn't exist.",
                    newFilename.getAbsolutePath(), tempFile.toAbsolutePath().toString());

            // create the file.
            new FileOutputStream(tempFile.toFile()).close();
            filesToDelete.add(tempFile);
            assertTrue("The file should exist now. (This just assures that we have write access to the disk.)", Files.exists(tempFile));

            for (int i = 1; i < 100; i++) {
                newFilename = FileUtils.findNextAvailableFilename(tempFile.toFile());
                tempFile = Paths.get(newFilename.toString());
                assertFalse("File should not exist.", Files.exists(tempFile));
                assertEquals("The file was not named correctly.",
                        tempFile.getFileName().toString(), FileDescriptionTestCase.class.getSimpleName() + "." + i + ".html");

                new FileOutputStream(tempFile.toFile()).close();
                filesToDelete.add(tempFile);
                assertTrue("The file should exist now. (This just assures that we have write access to the disk.)", Files.exists(tempFile));
            }

        } finally {
            // delete all temp files
            for (final Path fileToDelete: filesToDelete) {
                try {
                    Files.deleteIfExists(fileToDelete);
                } catch (final Exception e) {
                    // ignored.
                }
            }
        }
    }

    /** Copyright (c) 2014 Aaron Johnson <br/>
     * Test method for {@link #findNextAvailableFilename(java.io.File)}.
     * @throws IOException
     */

    @Test//(timeout=3000)
    public void testFindNextAvailableFilenameWithoutExtension() throws IOException {
        final List<Path> filesToDelete = new LinkedList<>();
        try {
            final Path tempFolder = Paths.get(System.getProperty("java.io.tmpdir"));
            Path tempFile = tempFolder.resolve(FileDescriptionTestCase.class.getSimpleName());

            // assure the file does not exist.
            Files.deleteIfExists(tempFile);

            // this should return the same name because the file name is available.
            File newFilename = FileUtils.findNextAvailableFilename(tempFile.toFile());
            assertEquals("The same file should have been returned because the file doesn't exist.",
                    newFilename.getAbsolutePath(), tempFile.toAbsolutePath().toString());

            // create the file.
            new FileOutputStream(tempFile.toFile()).close();
            filesToDelete.add(tempFile);
            assertTrue("The file should exist now. (This just assures that we have write access to the disk.)", Files.exists(tempFile));

            for (int i = 1; i < 100; i++) {
                newFilename = FileUtils.findNextAvailableFilename(tempFile.toFile());
                tempFile = Paths.get(newFilename.toString());
                assertFalse("File should not exist.", Files.exists(tempFile));
                assertEquals("The file was not named correctly.",
                        tempFile.getFileName().toString(), FileDescriptionTestCase.class.getSimpleName() + "." + i);

                new FileOutputStream(tempFile.toFile()).close();
                filesToDelete.add(tempFile);
                assertTrue("The file should exist now. (This just assures that we have write access to the disk.)", Files.exists(tempFile));
            }

        } finally {
            // delete all temp files
            for (final Path fileToDelete: filesToDelete) {
                try {
                    Files.deleteIfExists(fileToDelete);
                } catch (final Exception e) {
                    // ignored.
                }
            }
        }
    }
 Posted by at 9:51 pm  Tagged with:
Dec 242012
 

What a year! 2012 was a year of big changes for the Johnson family!

 

The biggest change, of course, was our move to Aix en Provence France. After our going away party where we said goodbye to our many good friends and family we boarded a plane headed to Germany. Our layover lasted something like 6 hours so we found a quiet corner and all took naps before our short flight to France. We arrived on the evening of Valentine’s Day and checked into our hotel.

IMG_1197 IMG_1380

 

After a couple of weeks we were able to find an apartment and after a few trips to Ikea we were finally able to settle in. Aaron started his new job and Little Miss started attending her new school, Les Boutons d’Or (the Buttercups). Weekends were spent visiting neighboring towns and getting used to our new home.

IMG_1300

The summer brought lots of time to explore Aix and find new things to do. Jennifer, Little Miss and Little Man found some pools and fountains to splash in and spent at least one day a week getting wet. There were also visits to the zoo and the indoor playground, Urban Kids. The month of August is very hot in the south of France and we’re proud to say that we made it through without an air conditioner!

IMG_2004

One of our favorite things to do in the summer is visit the beach. We live about 30 minutes away from the Mediterranean and are able to visit whenever we like. Little Miss and Little Man love to play in the sand and surf while Mom and Dad sit in the shade and watch.

IMG_1986

In September Little Miss headed back to school 4 days a week. We love that she is attending a Steiner Waldorf school and couldn’t be happier with her teacher. She is able to do lots of interesting things like making bread and watercolor painting. Most Fridays she also takes a walk with her class to a neighboring agricultural area where they are able to run and play and have their snack before heading back to the school. Jennifer and Little Man accompany the class a couple of times a month.

 

Over the summer we decided to move to a less expensive apartment, which we finally found in September. We were able to move in at the beginning of October. It only took us a couple of days to settle in and we are really happy with the new place. In the middle of the month Jennifer headed to Paris for a mini-vacation with her friend Little Miss while Aaron held down the fort at home with the kids.

IMG_2763 IMG_1332

 

Aaron’s mom Judy came to visit us in November and we had a great time showing her around. Little Miss and Little Man loved having her here to play with every day for two weeks! We did more some more sightseeing, heading to Avignon, Marseille, Cassis and Tarascon (where we saw a really neat castle!)

IMG_3029 IMG_2985

 

Now it’s Christmas Eve. We have decorated our tree, all of the presents are wrapped and we are looking forward to tomorrow morning. We sincerely hope that everyone is enjoying the time spent with family and friends during this special time of year. We will be celebrating tomorrow with new bikes (ssshhhh it’s a secret!), phone calls, skype and Mexican food!

IMG_3150 IMG_3132 IMG_3090

 

Merry Christmas! And wishes for a wonderful 2013!

IMG_2870

The Johnsons

 

 

 Posted by at 3:28 pm
Aug 262012
 

Our week wasn’t too exciting. It has continued to be really hot in Aix so we have spent a lot of time outside of our apartment. Monday we went to a park called Cuques. There are two little kiddie pools there for the kids to play in and lots of grass for picnics. The kids love to play in the water. While we were there this week Little Man decided that he didn’t want to wear his swim trunks so you have a super cute picture of his little booty. 🙂

Later that day we started a new routine in our house. Now every day at about 5pm I play a Sparkle Story for Little Miss and Little Man. You can go to www.sparklestories.com to check it out. Little Miss sits and draws or plays with playdough for at least 40 minutes each day while listening to these stories. And the amazing thing is that Little Man plays quietly also, almost as if he is listening to the stories too.

On Wednesday I took the kids to the only real zoo in the area, Zoo de la Barben. The kids had a lot of fun walking around and picnicking. One of the neat things about this zoo is that it has a really large playground for the kids. I do highly suggest making sure that you have a few euros to ride the train to the top of the mountain so that you don’t have to climb the very large staircase or walk up the very big hill.

 

Friday we had some errands to run that kept us out of the house at lunchtime so I decided that we would head to McDonald’s for lunch. I try not to make this a habit but the kids have fun when we go every once in a while.

On Saturday Aaron took the kids to the park while I headed to the beach with a couple of my friends. After coming home and showering we headed out to meet some of Aaron’s friends, Olivier and Laurence. They took us to a little fair in the town where they live and the kids had a ball! It is amazing how some little rides can just make their day. They rode a carousel, a little ferris wheel and a really big slide. After the fair we headed back to Olivier’s house for ice cream and then they treated us to a picnic that they made at a park nearby. The park was beautiful and we were lucky enough to be there at sunset. The kids got to stay up about two hours later than usual and they were so tired on the way home. It was worth it though for such a fun day.

 

Sunday was a bit of a lazy day. We took a walk to the park for a picnic breakfast and then came home to relax for the rest of the morning. Little Miss and Little Man painted a little and we skyped with Judy and Andrew. Then Aaron headed out to do Accrobranch with some of his friends while I took the kids out for pizza.

Well, that was our week. Hope you had a good one too!

 Posted by at 10:18 pm
Aug 192012
 

We had a busy week! We took care of some paperwork with the social security office here in Aix and got a brand new fridge!

Wednesday was a holiday here in France (August 15th The Assumption of Mary) so Aaron had the day off. We decided to head to the beach! So far our favorite sandy beach near Aix is Sainte Croix. It is a really nice beach near Sausset les Pins. There are lots of steps to reach the beach from the cliff top but it is a good size and we were even able to score some shade for most of the morning and early afternoon. We had a great time!



Thursday we headed to La Torse, a really nice big park in Aix. We had a fun time playing and picnicking there with some friends. Little Miss and Little Man are becoming great friends! I love to watch them run around together playing!

It has been getting really hot in Aix so we went to an indoor play area called Urban Kids on Friday. The kids really liked going down the slide together and eating their hot dogs and fries for lunch 🙂

We headed back to the beach on Saturday. This time to a small beach in La Ciotat named Le Mugel. This beach is rocky and much less busy than the sandy beaches nearby. The water is clear and calm and many people snorkel near the rocky cliffs on either side. The kids had a terrific time here. They both were able to float along as Aaron and I pulled them out into deeper water to “swim” and check out the little crabs on the rocks. Another great day!

After our busy week we stayed home on Sunday. The kids got a little stir crazy in the afternoon so I made them a little activity to keep them busy for a bit. I got this idea courtesy of Pinterest 🙂 Pour some baking soda into a shallow pan, mix up some colored vinegar, add a dropper and let the fun begin! The kids loved this. It only kept them busy for about 20 minutes or so. I think that I will give them a bigger pan of baking soda next time 🙂