Skip to content

Commit 5a130f7

Browse files
hansonrhansonr
authored andcommitted
java.nio.file.Files,.Path,.FileSystem support -- preliminary
1 parent 123b827 commit 5a130f7

File tree

10 files changed

+722
-367
lines changed

10 files changed

+722
-367
lines changed

sources/net.sf.j2s.java.core/src/java/awt/AWTEvent.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public abstract class AWTEvent extends EventObject {
9090

9191
private static int idnum; // SwingJS for testing
9292

93-
byte bdata[];
93+
public byte bdata[];
9494

9595
/**
9696
* The event's id.
@@ -605,8 +605,12 @@ protected boolean isConsumed() {
605605
* freed when the that is finalized. Upon completion,
606606
* this event is not changed.
607607
*/
608-
void copyPrivateDataInto(AWTEvent that) {
608+
609+
// SwingJS allow JSDnD to do this.
610+
611+
protected void copyPrivateDataInto(AWTEvent that) {
609612
that.bdata = bdata;
613+
// For JSDnD, we need to also copy over the dispatch() method if it exists.
610614
// // Copy canAccessSystemClipboard value from this into that.
611615
// if (this instanceof InputEvent && that instanceof InputEvent) {
612616
//// Field field = get_InputEvent_CanAccessSystemClipboard();

sources/net.sf.j2s.java.core/src/java/io/File.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@
3030

3131
import java.net.URI;
3232
import java.net.URISyntaxException;
33+
import java.nio.file.FileSystems;
34+
import java.nio.file.Path;
3335
import java.security.AccessControlException;
3436
import java.util.ArrayList;
3537
import java.util.Random;
3638

39+
import swingjs.JSFileSystem.JSPath;
3740
import swingjs.JSTempFile;
3841

3942

@@ -139,7 +142,7 @@ public class File
139142
{
140143

141144

142-
protected byte[] _bytes; // filled in by SwingJS ajax call
145+
public byte[] _bytes; // filled in by SwingJS ajax call or drag-drop from JSDnD
143146
//
144147
// /**
145148
// * The FileSystem object representing the platform's local file system.
@@ -162,6 +165,7 @@ public class File
162165
private transient int prefixLength;
163166

164167
private long lastModified;
168+
private Path filePath;
165169

166170
/**
167171
* Returns the length of this abstract pathname's prefix.
@@ -1983,5 +1987,20 @@ public int hashCode() {
19831987
public String toString() {
19841988
return getPath();
19851989
}
1986-
1990+
1991+
public Path toPath() {
1992+
Path result = filePath;
1993+
if (result == null) {
1994+
synchronized (this) {
1995+
result = filePath;
1996+
if (result == null) {
1997+
result = FileSystems.getDefault().getPath(path);
1998+
((JSPath) result)._bytes = _bytes;
1999+
filePath = result;
2000+
}
2001+
}
2002+
}
2003+
return result;
2004+
}
2005+
19872006
}

sources/net.sf.j2s.java.core/src/java/nio/channels/Channels.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import sun.nio.ch.ChannelInputStream;
4343
import sun.nio.cs.StreamDecoder;
4444
import sun.nio.cs.StreamEncoder;
45+
import swingjs.JSFileSystem;
4546

4647

4748
/**
@@ -122,7 +123,8 @@ private static void writeFully(WritableByteChannel ch, ByteBuffer bb)
122123
*/
123124
public static InputStream newInputStream(ReadableByteChannel ch) {
124125
checkNotNull(ch, "ch");
125-
return new sun.nio.ch.ChannelInputStream(ch);
126+
return ((JSFileSystem.JSSeekableByteChannel) ch).getInputStream();
127+
// return new sun.nio.ch.ChannelInputStream(ch);
126128
}
127129

128130
/**

0 commit comments

Comments
 (0)