Permalink
Browse files

fs impl to use FileChannel

  • Loading branch information...
1 parent 3c5fede commit ed1109b49c53c97e437bd188866c4c2b823175f5 @m0wfo m0wfo committed May 25, 2012
Showing with 8 additions and 28 deletions.
  1. +8 −5 resources/fs.js
  2. +0 −23 src/com/sprintstack/core/IFS.java
View
@@ -1,11 +1,14 @@
-importClass(com.sprintstack.core.IFS);
+importClass(java.io.RandomAccessFile);
+importClass(java.nio.ByteBuffer);
+importClass(java.nio.channels.FileChannel);
var Fs = function() {
- this.writeFileSync = function() {
- var filename = arguments[0];
- var data = arguments[1];
- IFS.writeFile(filename, data);
+ this.writeFileSync = function(filename, data) {
+ var f = new RandomAccessFile(filename, 'rwd');
+ var fc = f.getChannel();
+ var bb = ByteBuffer.wrap(new java.lang.String(data).getBytes('UTF-8'));
+ fc.write(bb);
}
}
@@ -1,23 +0,0 @@
-package com.sprintstack.core;
-
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.FileSystem;
-import java.nio.file.WatchService;
-import java.io.IOException;
-import java.util.concurrent.ConcurrentHashMap;
-
-
-public class IFS {
-
- public static void writeFile(String filename, String data) {
- Path file = Paths.get(filename);
- try {
- Files.write(file, data.getBytes());
- } catch (IOException e) {
- System.out.println(e);
- }
- }
-
-}

0 comments on commit ed1109b

Please sign in to comment.