package jp.number64.fileoperation;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FilesClassSample {
    private static final Logger LOGGER = LoggerFactory.getLogger(FilesClassSample.class);

    /**
     * Capture a web page, and Write it to local file. <br>
     * @param targetUri InputStream target
     * @param outputPath Output target (filepath)
     * @return captured text
     * @see java.nio.file.Files#copy(java.nio.file.Path, java.io.OutputStream)
     */
    public String captureAndSaveWebPage(String targetUri, String outputPath) throws IOException {
        LOGGER.debug("** captureAndSaveWebPage");

        LOGGER.debug("** URI: {}", targetUri);
        LOGGER.debug("** FILEPATH: {}", outputPath);

        File outputFile = new File(outputPath);
        if (!outputFile.getParentFile().isDirectory()) {
            throw new IOException("Invalid path: not directory.");
        }
        Path path = outputFile.toPath();

        URI uri = URI.create(targetUri);

        try (InputStream in = uri.toURL().openStream()) {
           Long captureSize = Files.copy(in, path);
           LOGGER.debug("** captureSize: {}", captureSize);
        }

        return null;
    }


}

@@ -181,16 +181,57 @@
 le.Path;
+%0Aimport java.nio.file.StandardCopyOption;
 %0A%0Aimport
@@ -401,24 +401,25 @@
 le.class);%0A%0A
+%0A
     /**%0A    
@@ -582,16 +582,26 @@
 @return 
+a copy of 
 captured
@@ -605,12 +605,12 @@
 red 
-text
+file
 %0A   
@@ -704,22 +704,20 @@
  public 
-String
+File
  capture
@@ -1203,24 +1203,56 @@
 argetUri);%0A%0A
+        File returnFile = null;%0A
         try 
@@ -1308,17 +1308,18 @@
         
-L
+ l
 ong capt
@@ -1317,24 +1317,25 @@
 long capture
+d
 Size = Files
@@ -1347,24 +1347,25 @@
 (in, path);%0A
+ 
            L
@@ -1409,14 +1409,213 @@
 ture
+d
 Size);
+%0A%0A            returnFile = new File(outputPath + %22.copy%22);%0A            Files.copy(path, returnFile.toPath(),%0A                StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
 %0A   
@@ -1641,20 +1641,26 @@
 urn 
-null
+returnFile
 ;%0A    %7D%0A
 %0A%0A%7D%0A
@@ -1655,12 +1655,10 @@
 ;%0A    %7D%0A
-%0A%0A
 %7D%0A

Implement CaptureAndSaveWebPage