Search in sources :

Example 1 with FSDataOutputStream

use of edu.iu.dsc.tws.api.data.FSDataOutputStream in project twister2 by DSC-SPIDAL.

the class HDFSFileStateStore method put.

@Override
public void put(String key, byte[] data) throws IOException {
    Path pathForKey = this.getPathForKey(key);
    FSDataOutputStream hadoopDataOutputStream = this.hdfs.create(pathForKey);
    IOUtils.copyBytes(new ByteArrayInputStream(data), hadoopDataOutputStream, data.length, true);
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) FSDataOutputStream(edu.iu.dsc.tws.api.data.FSDataOutputStream)

Example 2 with FSDataOutputStream

use of edu.iu.dsc.tws.api.data.FSDataOutputStream in project twister2 by DSC-SPIDAL.

the class DataGenerator method generateCSV.

/**
 * Generate a random csv file, we generate a csv with 10 attributes
 *
 * @param directory the path of the directory
 */
private static void generateCSV(Path directory, int numOfFiles, int sizeOfFile, int sizeMargin) throws IOException {
    FileSystem fs = FileSystemUtils.get(directory.toUri());
    Random random = new Random(System.currentTimeMillis());
    for (int i = 0; i < numOfFiles; i++) {
        FSDataOutputStream outputStream = fs.create(new Path(directory, generateRandom(10) + ".csv"));
        PrintWriter pw = new PrintWriter(outputStream);
        for (int j = 0; j < sizeOfFile + random.nextInt(sizeMargin); j++) {
            String row = generateCSVLine(10);
            pw.println(row);
        }
        pw.close();
    }
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) Random(java.util.Random) FileSystem(edu.iu.dsc.tws.api.data.FileSystem) FSDataOutputStream(edu.iu.dsc.tws.api.data.FSDataOutputStream) PrintWriter(java.io.PrintWriter)

Example 3 with FSDataOutputStream

use of edu.iu.dsc.tws.api.data.FSDataOutputStream in project twister2 by DSC-SPIDAL.

the class DataGenerator method generateText.

private static void generateText(Path directory, int numOfFiles, int sizeOfFile, int sizeMargin) throws IOException {
    FileSystem fs = FileSystemUtils.get(directory.toUri());
    Random random = new Random(System.currentTimeMillis());
    for (int i = 0; i < numOfFiles; i++) {
        FSDataOutputStream outputStream = fs.create(new Path(directory, generateRandom(10) + ".txt"));
        PrintWriter pw = new PrintWriter(outputStream);
        for (int j = 0; j < sizeOfFile + random.nextInt(sizeMargin); j++) {
            String row = generateRandom(20 + random.nextInt(10));
            pw.println(row);
        }
        pw.close();
    }
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) Random(java.util.Random) FileSystem(edu.iu.dsc.tws.api.data.FileSystem) FSDataOutputStream(edu.iu.dsc.tws.api.data.FSDataOutputStream) PrintWriter(java.io.PrintWriter)

Example 4 with FSDataOutputStream

use of edu.iu.dsc.tws.api.data.FSDataOutputStream in project twister2 by DSC-SPIDAL.

the class DataGenerator method generate.

public void generate(Path directory, int size, int dimension) {
    try {
        FileSystem fs = FileSystemUtils.get(directory.toUri(), config);
        if (fs.exists(directory)) {
            fs.delete(directory, true);
        }
        FSDataOutputStream outputStream = fs.create(new Path(directory, generateRandom(10) + ".txt"));
        PrintWriter pw = new PrintWriter(outputStream);
        String points = generatePoints(size, dimension, 100);
        pw.print(points);
        outputStream.sync();
        pw.close();
    } catch (IOException e) {
        throw new RuntimeException("Data Generation Error Occured", e);
    }
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) FileSystem(edu.iu.dsc.tws.api.data.FileSystem) FSDataOutputStream(edu.iu.dsc.tws.api.data.FSDataOutputStream) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 5 with FSDataOutputStream

use of edu.iu.dsc.tws.api.data.FSDataOutputStream in project twister2 by DSC-SPIDAL.

the class FileOutputWriter method write.

public void write(int partition, T out) {
    FSDataOutputStream fsOut;
    if (!openStreams.containsKey(partition)) {
        Path path = new Path(outPath, "part-" + partition);
        try {
            fsOut = fs.create(path);
            // lets ask user to create its own output method
            createOutput(partition, fsOut);
            openStreams.put(partition, fsOut);
        } catch (IOException e) {
            throw new RuntimeException("Failed to create output stream for file: " + path, e);
        }
    }
    writeRecord(partition, out);
}
Also used : Path(edu.iu.dsc.tws.api.data.Path) FSDataOutputStream(edu.iu.dsc.tws.api.data.FSDataOutputStream) IOException(java.io.IOException)

Aggregations

FSDataOutputStream (edu.iu.dsc.tws.api.data.FSDataOutputStream)7 Path (edu.iu.dsc.tws.api.data.Path)7 PrintWriter (java.io.PrintWriter)5 FileSystem (edu.iu.dsc.tws.api.data.FileSystem)4 IOException (java.io.IOException)4 Random (java.util.Random)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1