Skip to content

Instantly share code, notes, and snippets.

@louiszuckerman
Last active August 29, 2015 13:57
Show Gist options
  • Save louiszuckerman/9629461 to your computer and use it in GitHub Desktop.
Save louiszuckerman/9629461 to your computer and use it in GitHub Desktop.
Uses four threads to read four files and print chars to the console.
package com.peircean.glustest;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
public static final String PREFIX = "gluster://localhost:foo/";
public static void main(String[] args) {
new Print(PREFIX + "a");
new Print(PREFIX + "b");
new Print(PREFIX + "c");
new Print(PREFIX + "d");
}
}
class Print extends Thread {
String file;
public Print(String file) {
this.file = file;
start();
}
@Override
public void run() {
try {
BufferedReader reader = Files.newBufferedReader(
Paths.get(new URI(file)),
Charset.defaultCharset());
while (reader.ready()) {
System.out.print((char) reader.read());
}
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment