summaryrefslogtreecommitdiff
path: root/gnu/java/nio/FileChannelImpl.java
blob: 047a432af227cb09ce8da931ed27e10410f98494 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package gnu.java.nio;

import java.io.*;
import java.nio.*;
import java.nio.channels.*;


public class FileChannelImpl  extends FileChannel
{
    public long address, length;
    public int fd;
    public MappedByteBuffer buf;
    public Object file_obj; // just to keep it live...
    
    public FileChannelImpl(int fd,
			   Object obj)
    {
	this.fd       = fd;
	this.file_obj = obj;
    }

    public FileChannelImpl(FileDescriptor fd,
			   Object obj)
    {
	//this(fd.getNativeFD(), obj);
	this(0, obj);
	
	System.err.println("we need to get the native file-des here !\n");
    }
    
    
    public boolean isOpen()
    {
	// FIXME
	return fd != 0;
    }    

    public void close()
    {
    }

    public int read(java.nio.ByteBuffer  dst) throws IOException
    {
	System.out.println("in here-1");
	return 0;
    }

    public int write(java.nio.ByteBuffer  src) throws IOException
    {
	System.out.println("in here-2");
	return 0;
    }
    
    public long write(java.nio.ByteBuffer[]  srcs, 
		     int  offset,
		     int  length) throws IOException
    {
	System.out.println("in here-3");
	return 0;
    }

    static native long nio_mmap_file(int fd,
					  long pos,
					  int size,
					  int mode);

    static native void nio_unmmap_file(int fd,
					    long pos,
					    int size);
        
    public MappedByteBuffer map(java.nio.channels.FileChannel.MapMode mode,
				long  position,
				int  size) throws IOException
    {
	int cmode = 0;

	address = nio_mmap_file(fd, position, size, cmode);

	buf = new MappedByteFileBuffer(this);
	return buf;
    }

    static MappedByteBuffer create_direct_mapped_buffer(long address,
							long length)
    {
	FileChannelImpl ch = new FileChannelImpl(-1, null);
		
	ch.address = address;
	ch.length  = length;

	ch.buf = new MappedByteFileBuffer(ch);
	return ch.buf;			 
    }
}