// Path: src/main/java/be/bagofwords/virtualfile/VirtualFile.java
// public interface VirtualFile {
// 
//     public VirtualFile getFile(String relativePath);
// 
//     public InputStream createInputStream();
// 
//     public OutputStream createOutputStream();
// 
//     public boolean exists();
// }
// 
// Path: src/main/java/be/bagofwords/virtualfile/local/LocalFileService.java
// public class LocalFileService extends VirtualFileService {
// 
//     private File rootDirectory;
// 
//     public LocalFileService(ApplicationContext context) {
//         this.rootDirectory = new File(context.getProperty("data_directory"), "virtualFiles");
//         if (this.rootDirectory.exists()) {
//             if (!this.rootDirectory.isDirectory()) {
//                 throw new RuntimeException("Expected " + this.rootDirectory.getAbsolutePath() + " to be a directory");
//             }
//         } else {
//             boolean success = this.rootDirectory.mkdirs();
//             if (!success) {
//                 throw new RuntimeException("Failed to created directory " + this.rootDirectory.getAbsolutePath());
//             }
//         }
//     }
// 
//     @Override
//     public VirtualFile getRootDirectory() {
//         return new LocalFile(rootDirectory);
//     }
// }


import be.bagofwords.application.MinimalApplicationDependencies;
import be.bagofwords.web.SocketServer;
import be.bagofwords.minidepi.ApplicationContext;
import be.bagofwords.util.Utils;
import be.bagofwords.virtualfile.VirtualFile;
import be.bagofwords.virtualfile.local.LocalFileService;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
package be.bagofwords.virtualfile.remote;



public class TestRemoteFileService {

    @Test
    public void testWriteAndRead() throws IOException {
        Map<String, String> config = new HashMap<>();
        config.put("data_directory", "/tmp/myFiles");
        config.put("socket.port", "1208");
        ApplicationContext context = new ApplicationContext(config);
        context.registerBean(MinimalApplicationDependencies.class);
        context.registerBean(LocalFileService.class);
        context.registerBean(RemoteFileServer.class);
        context.registerBean(SocketServer.class);
        Utils.threadSleep(1000); //Make sure server has started
        RemoteFileService remoteFileService = new RemoteFileService(context);
        VirtualFile dir = remoteFileService.getRootDirectory();
// Path: src/main/java/be/bagofwords/virtualfile/VirtualFile.java
// public interface VirtualFile {
// 
//     public VirtualFile getFile(String relativePath);
// 
//     public InputStream createInputStream();
// 
//     public OutputStream createOutputStream();
// 
//     public boolean exists();
// }
// 
// Path: src/main/java/be/bagofwords/virtualfile/local/LocalFileService.java
// public class LocalFileService extends VirtualFileService {
// 
//     private File rootDirectory;
// 
//     public LocalFileService(ApplicationContext context) {
//         this.rootDirectory = new File(context.getProperty("data_directory"), "virtualFiles");
//         if (this.rootDirectory.exists()) {
//             if (!this.rootDirectory.isDirectory()) {
//                 throw new RuntimeException("Expected " + this.rootDirectory.getAbsolutePath() + " to be a directory");
//             }
//         } else {
//             boolean success = this.rootDirectory.mkdirs();
//             if (!success) {
//                 throw new RuntimeException("Failed to created directory " + this.rootDirectory.getAbsolutePath());
//             }
//         }
//     }
// 
//     @Override
//     public VirtualFile getRootDirectory() {
//         return new LocalFile(rootDirectory);
//     }
// }


// Path: src/test/java/be/bagofwords/virtualfile/remote/TestRemoteFileService.java
import be.bagofwords.application.MinimalApplicationDependencies;
import be.bagofwords.web.SocketServer;
import be.bagofwords.minidepi.ApplicationContext;
import be.bagofwords.util.Utils;
import be.bagofwords.virtualfile.VirtualFile;
import be.bagofwords.virtualfile.local.LocalFileService;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

package be.bagofwords.virtualfile.remote;



public class TestRemoteFileService {

    @Test
    public void testWriteAndRead() throws IOException {
        Map<String, String> config = new HashMap<>();
        config.put("data_directory", "/tmp/myFiles");
        config.put("socket.port", "1208");
        ApplicationContext context = new ApplicationContext(config);
        context.registerBean(MinimalApplicationDependencies.class);
        context.registerBean(LocalFileService.class);
        context.registerBean(RemoteFileServer.class);
        context.registerBean(SocketServer.class);
        Utils.threadSleep(1000); //Make sure server has started
        RemoteFileService remoteFileService = new RemoteFileService(context);
        VirtualFile dir = remoteFileService.getRootDirectory();
        VirtualFile file = dir.getFile("test1");