private void copyFiles(ByteArrayInputStream fis, File dest) {
   FileOutputStream fos = null;
   byte[] buffer = new byte[512]; // Buffer 4K at a time (you can change this).
   int bytesRead;
   logger.debug("fis?" + fis);
   try {
     fos = new FileOutputStream(dest);
     while ((bytesRead = fis.read(buffer)) >= 0) {
       fos.write(buffer, 0, bytesRead);
     }
   } catch (IOException ioe) { // error while copying files
     OpenClinicaSystemException oe =
         new OpenClinicaSystemException(
             "Unable to copy file: "
                 + fis
                 + "to"
                 + dest.getAbsolutePath()
                 + "."
                 + dest.getAbsolutePath()
                 + ".");
     oe.initCause(ioe);
     oe.setStackTrace(ioe.getStackTrace());
     throw oe;
   } finally { // Ensure that the files are closed (if they were open).
     if (fis != null) {
       try {
         fis.close();
       } catch (IOException ioe) {
         OpenClinicaSystemException oe =
             new OpenClinicaSystemException(
                 "Unable to copy file: "
                     + fis
                     + "to"
                     + dest.getAbsolutePath()
                     + "."
                     + dest.getAbsolutePath()
                     + ".");
         oe.initCause(ioe);
         oe.setStackTrace(ioe.getStackTrace());
         logger.debug(ioe.getMessage());
         throw oe;
       }
     }
     if (fos != null) {
       try {
         fos.close();
       } catch (IOException ioe) {
         OpenClinicaSystemException oe =
             new OpenClinicaSystemException(
                 "Unable to copy file: "
                     + fis
                     + "to"
                     + dest.getAbsolutePath()
                     + "."
                     + dest.getAbsolutePath()
                     + ".");
         oe.initCause(ioe);
         oe.setStackTrace(ioe.getStackTrace());
         logger.debug(ioe.getMessage());
         throw oe;
       }
     }
   }
 }
  private void copyBaseToDest(ResourceLoader resourceLoader) {
    // System.out.println("Properties directory?"+resourceLoader.getResource("properties/xslt"));

    ByteArrayInputStream listSrcFiles[] = new ByteArrayInputStream[10];
    String[] fileNames = {
      "odm_spss_dat.xsl",
      "ODMToTAB.xsl",
      "odm_to_html.xsl",
      "odm_to_xslfo.xsl",
      "ODM-XSLFO-Stylesheet.xsl",
      "odm_spss_sps.xsl",
      "copyXML.xsl",
      "odm1.3_to_1.2.xsl",
      "odm1.3_to_1.2_extensions.xsl"
    };
    try {
      listSrcFiles[0] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[0])
                  .getInputStream();
      listSrcFiles[1] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[1])
                  .getInputStream();
      listSrcFiles[2] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[2])
                  .getInputStream();
      listSrcFiles[3] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[3])
                  .getInputStream();
      listSrcFiles[4] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[4])
                  .getInputStream();
      listSrcFiles[5] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[5])
                  .getInputStream();
      listSrcFiles[6] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[6])
                  .getInputStream();
      listSrcFiles[7] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[7])
                  .getInputStream();
      listSrcFiles[8] =
          (ByteArrayInputStream)
              resourceLoader
                  .getResource(
                      "classpath:properties"
                          + File.separator
                          + "xslt"
                          + File.separator
                          + fileNames[8])
                  .getInputStream();

    } catch (IOException ioe) {
      OpenClinicaSystemException oe = new OpenClinicaSystemException("Unable to read source files");
      oe.initCause(ioe);
      oe.setStackTrace(ioe.getStackTrace());
      logger.debug(ioe.getMessage());
      throw oe;
    }
    File dest = new File(getField("filePath") + "xslt");
    if (!dest.exists()) {
      if (!dest.mkdirs()) {
        throw new OpenClinicaSystemException(
            "Copying files, Could not create direcotry: " + dest.getAbsolutePath() + ".");
      }
    }

    for (int i = 0; i < fileNames.length; i++) {
      File dest1 = new File(dest, fileNames[i]);
      // File src1 = listSrcFiles[i];
      if (listSrcFiles[i] != null) copyFiles(listSrcFiles[i], dest1);
    }
  }