Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
blueBill Core - open source birding Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. WWW: http://bluebill.tidalwave.it SCM: https://java.net/hg/bluebill~core-src /
 
 package it.tidalwave.mobile.io;
 
 import  javax.annotation.Nonnull;
 import  javax.annotation.Nullable;
 import java.io.File;

Author(s):
Fabrizio Giudici
Version:
$Id$ /
 
 public class IoUtils
   {
     private static final Logger log = LoggerFactory.getLogger(IoUtils.class); 

    
/
 
     public static void safeClose (final @Nullable Closeable is)
       {
         if (is != null)
           {
             try
               {
                 is.close();
               }
             catch (IOException e)
               {
 
               }
           }
       }

    
/
 
     public static void safeClose (final @Nullable ZipFile zipFile)
       {
         if (zipFile != null)
           {
             try
               {
                 zipFile.close();
               }
             catch (IOException e)
               {
 
               }
           }
       }

    
/
 
     public static void copy (final @Nonnull InputStream isfinal @Nonnull OutputStream os)
       throws IOException
       {
         final byte[] buffer = new byte[64 * 1024];
         
         for (;;)
           {
             final int n = is.read(buffer);
 
             if (n <= 0)
              {
                break;
              }
            os.write(buffer, 0, n);
          }
      }

    
/
    public static void copy (final @Nonnull File srcFilefinal @Nonnull File destFile)
      throws IOException
      {
        .debug("copy({} -> {})"srcFile.getAbsolutePath(), destFile.getAbsolutePath());
        InputStream is = null;
        OutputStream os = null;
        final File parentFile = destFile.getParentFile();
        if (!parentFile.exists() && !parentFile.mkdirs())
          {
            throw new IOException("Cannot create path " + parentFile.getAbsolutePath());
          }
        try
          {
            is = new FileInputStream(srcFile);
            os = new FileOutputStream(destFile);
            copy(isos);
          }
        finally
          {
            safeClose(is);
            safeClose(os);
          }
      }
  }
New to GrepCode? Check out our FAQ X