Skip to content

Instantly share code, notes, and snippets.

@haruyama
Created December 9, 2013 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haruyama/7869684 to your computer and use it in GitHub Desktop.
Save haruyama/7869684 to your computer and use it in GitHub Desktop.
file dumper
import ceylon.file { File, Path, parsePath }
import ceylon.io { OpenFile, newOpenFile }
import ceylon.io.charset { utf8, Decoder }
import ceylon.io.buffer { ByteBuffer }
import java.util { ArrayList }
shared void cat(String filename) {
Path path = parsePath(filename);
OpenFile file = newOpenFile(path.resource);
try {
ArrayList<Integer> bytes = ArrayList<Integer>();
file.readFully(void (ByteBuffer buffer) {
for (Integer byte in buffer) {
bytes.add(byte);
}
});
print(bytes);
} finally {
file.close();
}
}
shared void run(){
if (nonempty args=process.arguments) {
for (arg in args) {
cat(arg);
}
}
else {
throw IllegalArgumentException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment