Search in sources :

Example 6 with LocalFileSystem

use of com.alibaba.alink.common.io.filesystem.LocalFileSystem in project Alink by alibaba.

the class Chap03 method c_1_1.

static void c_1_1() throws Exception {
    LocalFileSystem local = new LocalFileSystem();
    System.out.println(local.getHomeDirectory());
    System.out.println(local.getKind());
    if (!local.exists(LOCAL_DIR)) {
        local.mkdirs(LOCAL_DIR);
    }
    for (FileStatus status : local.listStatus(LOCAL_DIR)) {
        System.out.println(status.getPath().toUri() + " \t" + status.getLen() + " \t" + new Date(status.getModificationTime()));
    }
    String path = LOCAL_DIR + "hello.txt";
    OutputStream outputStream = local.create(path, WriteMode.OVERWRITE);
    outputStream.write("Hello Alink!".getBytes());
    outputStream.close();
    FileStatus status = local.getFileStatus(path);
    System.out.println(status);
    System.out.println(status.getLen());
    System.out.println(new Date(status.getModificationTime()));
    InputStream inputStream = local.open(path);
    String readString = IOUtils.toString(inputStream);
    System.out.println(readString);
}
Also used : FileStatus(org.apache.flink.core.fs.FileStatus) LocalFileSystem(com.alibaba.alink.common.io.filesystem.LocalFileSystem) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Date(java.util.Date)

Aggregations

LocalFileSystem (com.alibaba.alink.common.io.filesystem.LocalFileSystem)6 FilePath (com.alibaba.alink.common.io.filesystem.FilePath)4 Date (java.util.Date)3 FileStatus (org.apache.flink.core.fs.FileStatus)3 Path (org.apache.flink.core.fs.Path)3 HttpFileSplitReader (com.alibaba.alink.operator.common.io.reader.HttpFileSplitReader)2 FileNotFoundException (java.io.FileNotFoundException)2 ObjectPath (org.apache.flink.table.catalog.ObjectPath)2 PluginNotExistException (com.alibaba.alink.common.exceptions.PluginNotExistException)1 HadoopFileSystem (com.alibaba.alink.common.io.filesystem.HadoopFileSystem)1 OssFileSystem (com.alibaba.alink.common.io.filesystem.OssFileSystem)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)1