/*
 * Copyright 2000-2017 JetBrains s.r.o.
 *
 * 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.
 */
package org.apache.sanselan.util;

import com.intellij.openapi.util.io.FileUtil;

import java.io.*;

/**
 * For plugin compatibility only, DO NOT USE.
 * todo check external usages & DELETE ASAP.
 * <p>
 * Required due to sanselan-0.98 -> commons-imaging migration.
 * e791557ca1489b02d178aa68960d645ab501e674
 */
@Deprecated
public class IOUtils {

  public static byte[] getInputStreamBytes(InputStream is) throws IOException {
    return FileUtil.loadBytes(is);
  }

  public static byte[] getFileBytes(File file) throws IOException {
    return FileUtil.loadFileBytes(file);
  }

  public static void writeToFile(byte[] src, File file) throws IOException {
    FileUtil.writeToFile(file, src);
  }

  public static void putInputStreamToFile(InputStream src, File file) throws IOException {
    FileUtil.ensureCanCreateFile(file);
    copyStreamToStream(src, new FileOutputStream(file), true);
  }

  public static void copyStreamToStream(InputStream src, OutputStream dst) throws IOException {
    copyStreamToStream(src, dst, true);
  }

  public static void copyStreamToStream(InputStream src, OutputStream dst, boolean close_streams) throws IOException {
    try {
      FileUtil.copy(new BufferedInputStream(src), new BufferedOutputStream(dst));
    }
    finally {
      if (close_streams) {
        try {
          src.close();
        }
        catch (IOException ignore) {
        }
        finally {
          try {
            dst.close();
          }
          catch (IOException ignore) {
          }
        }
      }
    }
  }
}
@@ -1764,34 +1764,99 @@
     
-try %7B%0A      FileUtil.copy(
+BufferedInputStream bis = null;%0A    BufferedOutputStream bos = null;%0A    try %7B%0A      bis = 
 new 
@@ -1879,17 +1879,29 @@
 eam(src)
-,
+;%0A      bos =
  new Buf
@@ -1922,16 +1922,65 @@
 eam(dst)
+;%0A      FileUtil.copy(bis, bos);%0A      bos.flush(
 );%0A    %7D
@@ -2049,20 +2049,63 @@
     
-src.close();
+if (bis != null) %7B%0A            bis.close();%0A          %7D
 %0A   
@@ -2208,20 +2208,67 @@
     
-dst.close();
+if (bos != null) %7B%0A              bos.close();%0A            %7D
 %0A   

fix incorrect closing streams in sanselan IOUtils (PR #708)