IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IKVM.Java.Externs.java.io.RandomAccessFile Class Reference

Implements the native methods for 'RandomAccessFile'. More...

Static Public Member Functions

static void open0 (object self, string name, int mode)
 Implements the native method 'open0'.
 
static int read0 (object self)
 Implements the native method 'read0'.
 
static int readBytes (object self, byte[] bytes, int off, int len)
 Implements the native method 'readBytes'.
 
static void write0 (object self, int @byte)
 Implements the native method 'write'.
 
static void writeBytes (object self, byte[] bytes, int off, int len)
 Implements the native method 'writeBytes'.
 
static long getFilePointer (object self)
 Implements the native method 'getFilePointer'.
 
static void seek0 (object self, long pos)
 Implements the native method 'seek0'.
 
static long length (object self)
 Implements the native method 'length'.
 
static void setLength (object self, long newLength)
 Implements the native method 'setLength'.
 
static void close0 (object self)
 Implements the native method 'close0'.
 

Detailed Description

Implements the native methods for 'RandomAccessFile'.

These operations support both standard file operations, and operations against the IKVM VFS. In the case of files on the VFS, operations are implemented directly against the .NET stream object.

Definition at line 20 of file RandomFileAccess.cs.

Member Function Documentation

◆ close0()

static void IKVM.Java.Externs.java.io.RandomAccessFile.close0 ( object self)
static

Implements the native method 'close0'.

Parameters
self

Definition at line 650 of file RandomFileAccess.cs.

651 {
652#if FIRST_PASS
653 throw new NotImplementedException();
654#else
655 var fd = RandomAccessFileAccessor.GetFd(self);
656 if (fd == null)
657 return;
658
659 if (FileDescriptorAccessor.GetStream(fd) is Stream stream)
660 {
661 try
662 {
663 stream.Close();
664 FileDescriptorAccessor.SetPtr(fd, -1);
665 }
666 catch
667 {
668 // ignore
669 }
670 }
671 else
672 {
673 __callerID ??= global::ikvm.@internal.CallerID.create(typeof(global::java.io.RandomAccessFile).TypeHandle);
674 __jniPtr__close0 ??= Marshal.GetDelegateForFunctionPointer<__jniDelegate__close0>(JNIFrame.GetFuncPtr(__callerID, "java/io/RandomAccessFile", nameof(close0), "()V"));
675 var jniFrm = new JNIFrame();
676 var jniEnv = jniFrm.Enter(__callerID);
677 try
678 {
679 __jniPtr__close0(jniEnv, jniFrm.MakeLocalRef(self));
680 }
681 catch (Exception ex)
682 {
683 System.Console.WriteLine("*** exception in native code ***");
684 System.Console.WriteLine(ex);
685 throw;
686 }
687 finally
688 {
689 jniFrm.Leave();
690 }
691 }
692#endif
693 }
static void close0(object self)
Implements the native method 'close0'.
static nint GetFuncPtr(object callerID, string clazz, string name, string sig)
Invoked by managed code to acquire a function pointer to a native JNI method.
Definition JNIFrame.cs:43

◆ getFilePointer()

static long IKVM.Java.Externs.java.io.RandomAccessFile.getFilePointer ( object self)
static

Implements the native method 'getFilePointer'.

Parameters
self
Returns

Definition at line 408 of file RandomFileAccess.cs.

409 {
410#if FIRST_PASS
411 throw new NotImplementedException();
412#else
413 var fd = RandomAccessFileAccessor.GetFd(self);
414 if (fd == null)
415 throw new global::java.io.IOException("Invalid file handle.");
416
417 if (FileDescriptorAccessor.GetStream(fd) is Stream stream)
418 {
419 try
420 {
421 return stream.Position;
422 }
423 catch (ObjectDisposedException e)
424 {
425 throw new global::java.io.IOException(e.Message);
426 }
427 catch (NotSupportedException e)
428 {
429 throw new global::java.io.IOException(e.Message);
430 }
431 catch (IOException e)
432 {
433 throw new global::java.io.IOException(e.Message);
434 }
435 }
436 else
437 {
438 __callerID ??= global::ikvm.@internal.CallerID.create(typeof(global::java.io.RandomAccessFile).TypeHandle);
439 __jniPtr__getFilePointer ??= Marshal.GetDelegateForFunctionPointer<__jniDelegate__getFilePointer>(JNIFrame.GetFuncPtr(__callerID, "java/io/RandomAccessFile", nameof(getFilePointer), "()J"));
440 var jniFrm = new JNIFrame();
441 var jniEnv = jniFrm.Enter(__callerID);
442 try
443 {
444 return __jniPtr__getFilePointer(jniEnv, jniFrm.MakeLocalRef(self));
445 }
446 catch (Exception ex)
447 {
448 System.Console.WriteLine("*** exception in native code ***");
449 System.Console.WriteLine(ex);
450 throw;
451 }
452 finally
453 {
454 jniFrm.Leave();
455 }
456 }
457#endif
458 }
static long getFilePointer(object self)
Implements the native method 'getFilePointer'.

◆ length()

static long IKVM.Java.Externs.java.io.RandomAccessFile.length ( object self)
static

Implements the native method 'length'.

Parameters
self
Returns

Definition at line 526 of file RandomFileAccess.cs.

527 {
528#if FIRST_PASS
529 throw new NotImplementedException();
530#else
531 var fd = RandomAccessFileAccessor.GetFd(self);
532 if (fd == null)
533 throw new global::java.io.IOException("Invalid file handle.");
534
535 if (FileDescriptorAccessor.GetStream(fd) is Stream stream)
536 {
537 try
538 {
539 return stream.Length;
540 }
541 catch (ObjectDisposedException e)
542 {
543 throw new global::java.io.IOException(e.Message);
544 }
545 catch (NotSupportedException e)
546 {
547 throw new global::java.io.IOException(e.Message);
548 }
549 catch (IOException e)
550 {
551 throw new global::java.io.IOException(e.Message);
552 }
553 }
554 else
555 {
556 __callerID ??= global::ikvm.@internal.CallerID.create(typeof(global::java.io.RandomAccessFile).TypeHandle);
557 __jniPtr__length ??= Marshal.GetDelegateForFunctionPointer<__jniDelegate__length>(JNIFrame.GetFuncPtr(__callerID, "java/io/RandomAccessFile", nameof(length), "()J"));
558 var jniFrm = new JNIFrame();
559 var jniEnv = jniFrm.Enter(__callerID);
560 try
561 {
562 return __jniPtr__length(jniEnv, jniFrm.MakeLocalRef(self));
563 }
564 catch (Exception ex)
565 {
566 System.Console.WriteLine("*** exception in native code ***");
567 System.Console.WriteLine(ex);
568 throw;
569 }
570 finally
571 {
572 jniFrm.Leave();
573 }
574 }
575#endif
576 }
static long length(object self)
Implements the native method 'length'.

◆ open0()

static void IKVM.Java.Externs.java.io.RandomAccessFile.open0 ( object self,
string name,
int mode )
static

Implements the native method 'open0'.

Parameters
self
name
mode

Definition at line 67 of file RandomFileAccess.cs.

68 {
69#if FIRST_PASS
70 throw new NotImplementedException();
71#else
72 if (JVM.Vfs.IsPath(name))
73 {
74 var fd = RandomAccessFileAccessor.GetFd(self);
75 if (fd == null)
76 throw new global::java.io.IOException("Invalid file handle.");
77
78 try
79 {
80 var fileMode = (FileMode)0;
81 if ((mode & O_RDONLY) == O_RDONLY)
82 fileMode |= FileMode.Open;
83 if ((mode & O_RDWR) == O_RDWR)
84 fileMode |= FileMode.OpenOrCreate;
85
86 var fileAccess = (FileAccess)0;
87 if ((mode & O_RDONLY) == O_RDONLY)
88 fileAccess |= FileAccess.Read;
89 if ((mode & O_RDWR) == O_RDWR)
90 fileAccess |= FileAccess.ReadWrite;
91
92 FileDescriptorAccessor.SetPtr(fd, -1);
93 FileDescriptorAccessor.SetStream(fd, JVM.Vfs.Open(name, fileMode, fileAccess));
94 return;
95 }
96 catch (ObjectDisposedException e)
97 {
98 throw new global::java.io.IOException(e.Message);
99 }
100 catch (ArgumentException e)
101 {
102 throw new global::java.io.FileNotFoundException(e.Message);
103 }
104 catch (SecurityException e)
105 {
106 throw new global::java.lang.SecurityException(e.Message);
107 }
108 catch (UnauthorizedAccessException)
109 {
110 throw new global::java.io.FileNotFoundException(name + " (Access is denied)");
111 }
112 catch (IOException e)
113 {
114 throw new global::java.io.FileNotFoundException(e.Message);
115 }
116 catch (NotSupportedException e)
117 {
118 throw new global::java.io.FileNotFoundException(e.Message);
119 }
120 }
121 else
122 {
123 __callerID ??= global::ikvm.@internal.CallerID.create(typeof(global::java.io.RandomAccessFile).TypeHandle);
124 __jniPtr__open0 ??= Marshal.GetDelegateForFunctionPointer<__jniDelegate__open0>(JNIFrame.GetFuncPtr(__callerID, "java/io/RandomAccessFile", nameof(open0), "(Ljava/lang/String;I)V"));
125 var jniFrm = new JNIFrame();
126 var jniEnv = jniFrm.Enter(__callerID);
127 try
128 {
129 __jniPtr__open0(jniEnv, jniFrm.MakeLocalRef(self), jniFrm.MakeLocalRef(name), mode);
130 }
131 catch (Exception ex)
132 {
133 System.Console.WriteLine("*** exception in native code ***");
134 System.Console.WriteLine(ex);
135 throw;
136 }
137 finally
138 {
139 jniFrm.Leave();
140 }
141 }
142#endif
143 }
static void open0(object self, string name, int mode)
Implements the native method 'open0'.
Main state of the running JVM.

◆ read0()

static int IKVM.Java.Externs.java.io.RandomAccessFile.read0 ( object self)
static

Implements the native method 'read0'.

Parameters
self
Returns

Definition at line 150 of file RandomFileAccess.cs.

151 {
152#if FIRST_PASS
153 throw new NotImplementedException();
154#else
155 var fd = RandomAccessFileAccessor.GetFd(self);
156 if (fd == null)
157 throw new global::java.io.IOException("Invalid file handle.");
158
159 if (FileDescriptorAccessor.GetStream(fd) is Stream stream)
160 {
161 if (stream.CanRead == false)
162 throw new global::java.io.IOException("Read failed.");
163
164 try
165 {
166 stream.Flush();
167 return stream.ReadByte();
168 }
169 catch (ObjectDisposedException e)
170 {
171 throw new global::java.io.IOException(e.Message);
172 }
173 catch (NotSupportedException e)
174 {
175 throw new global::java.io.IOException(e.Message);
176 }
177 catch (IOException e)
178 {
179 throw new global::java.io.IOException(e.Message);
180 }
181 }
182 else
183 {
184 __callerID ??= global::ikvm.@internal.CallerID.create(typeof(global::java.io.RandomAccessFile).TypeHandle);
185 __jniPtr__read0 ??= Marshal.GetDelegateForFunctionPointer<__jniDelegate__read0>(JNIFrame.GetFuncPtr(__callerID, "java/io/RandomAccessFile", nameof(read0), "()I"));
186 var jniFrm = new JNIFrame();
187 var jniEnv = jniFrm.Enter(__callerID);
188 try
189 {
190 return __jniPtr__read0(jniEnv, jniFrm.MakeLocalRef(self));
191 }
192 catch (Exception ex)
193 {
194 System.Console.WriteLine("*** exception in native code ***");
195 System.Console.WriteLine(ex);
196 throw;
197 }
198 finally
199 {
200 jniFrm.Leave();
201 }
202 }
203#endif
204 }
static int read0(object self)
Implements the native method 'read0'.

◆ readBytes()

static int IKVM.Java.Externs.java.io.RandomAccessFile.readBytes ( object self,
byte[] bytes,
int off,
int len )
static

Implements the native method 'readBytes'.

Parameters
self
bytes
off
len
Returns

Definition at line 214 of file RandomFileAccess.cs.

215 {
216#if FIRST_PASS
217 throw new NotImplementedException();
218#else
219 var fd = RandomAccessFileAccessor.GetFd(self);
220 if (fd == null)
221 throw new global::java.io.IOException("Invalid file handle.");
222
223 if (FileDescriptorAccessor.GetStream(fd) is Stream stream)
224 {
225 if (bytes == null)
226 throw new global::java.lang.NullPointerException();
227
228 if ((off < 0) || (off > bytes.Length) || (len < 0) || (len > (bytes.Length - off)))
229 throw new global::java.lang.IndexOutOfBoundsException();
230
231 if (len == 0)
232 return 0;
233
234 if (stream.CanRead == false)
235 throw new global::java.io.IOException("Read failed.");
236
237 try
238 {
239 var n = stream.Read(bytes, off, len);
240 return n == 0 ? -1 : n;
241 }
242 catch (ObjectDisposedException e)
243 {
244 throw new global::java.io.IOException(e.Message);
245 }
246 catch (NotSupportedException e)
247 {
248 throw new global::java.io.IOException(e.Message);
249 }
250 catch (IOException e)
251 {
252 throw new global::java.io.IOException(e.Message);
253 }
254 }
255 else
256 {
257 __callerID ??= global::ikvm.@internal.CallerID.create(typeof(global::java.io.RandomAccessFile).TypeHandle);
258 __jniPtr__readBytes ??= Marshal.GetDelegateForFunctionPointer<__jniDelegate__readBytes>(JNIFrame.GetFuncPtr(__callerID, "java/io/RandomAccessFile", nameof(readBytes), "([BII)I"));
259 var jniFrm = new JNIFrame();
260 var jniEnv = jniFrm.Enter(__callerID);
261 try
262 {
263 return __jniPtr__readBytes(jniEnv, jniFrm.MakeLocalRef(self), jniFrm.MakeLocalRef(bytes), off, len);
264 }
265 catch (Exception ex)
266 {
267 System.Console.WriteLine("*** exception in native code ***");
268 System.Console.WriteLine(ex);
269 throw;
270 }
271 finally
272 {
273 jniFrm.Leave();
274 }
275 }
276#endif
277 }
static int readBytes(object self, byte[] bytes, int off, int len)
Implements the native method 'readBytes'.

◆ seek0()

static void IKVM.Java.Externs.java.io.RandomAccessFile.seek0 ( object self,
long pos )
static

Implements the native method 'seek0'.

Parameters
self
pos

Definition at line 465 of file RandomFileAccess.cs.

466 {
467#if FIRST_PASS
468 throw new NotImplementedException();
469#else
470 var fd = RandomAccessFileAccessor.GetFd(self);
471 if (fd == null)
472 throw new global::java.io.IOException("Invalid file handle.");
473
474 if (FileDescriptorAccessor.GetStream(fd) is Stream stream)
475 {
476 try
477 {
478 stream.Position = pos;
479 }
480 catch (ObjectDisposedException e)
481 {
482 throw new global::java.io.IOException(e.Message);
483 }
484 catch (NotSupportedException e)
485 {
486 throw new global::java.io.IOException(e.Message);
487 }
488 catch (ArgumentOutOfRangeException)
489 {
490 throw new global::java.io.IOException("Negative seek offset.");
491 }
492 catch (IOException e)
493 {
494 throw new global::java.io.IOException(e.Message);
495 }
496 }
497 else
498 {
499 __callerID ??= global::ikvm.@internal.CallerID.create(typeof(global::java.io.RandomAccessFile).TypeHandle);
500 __jniPtr__seek0 ??= Marshal.GetDelegateForFunctionPointer<__jniDelegate__seek0>(JNIFrame.GetFuncPtr(__callerID, "java/io/RandomAccessFile", nameof(seek0), "(J)V"));
501 var jniFrm = new JNIFrame();
502 var jniEnv = jniFrm.Enter(__callerID);
503 try
504 {
505 __jniPtr__seek0(jniEnv, jniFrm.MakeLocalRef(self), pos);
506 }
507 catch (Exception ex)
508 {
509 System.Console.WriteLine("*** exception in native code ***");
510 System.Console.WriteLine(ex);
511 throw;
512 }
513 finally
514 {
515 jniFrm.Leave();
516 }
517 }
518#endif
519 }
static void seek0(object self, long pos)
Implements the native method 'seek0'.

◆ setLength()

static void IKVM.Java.Externs.java.io.RandomAccessFile.setLength ( object self,
long newLength )
static

Implements the native method 'setLength'.

Parameters
self
newLength

Definition at line 583 of file RandomFileAccess.cs.

584 {
585#if FIRST_PASS
586 throw new NotImplementedException();
587#else
588 var fd = RandomAccessFileAccessor.GetFd(self);
589 if (fd == null)
590 throw new global::java.io.IOException("Invalid file handle.");
591
592 if (FileDescriptorAccessor.GetStream(fd) is Stream stream)
593 {
594 var p = stream.Position;
595
596 try
597 {
598 stream.SetLength(newLength);
599 stream.Position = Math.Min(p, stream.Length);
600 }
601 catch (ObjectDisposedException e)
602 {
603 stream.Position = p;
604 throw new global::java.io.IOException(e.Message);
605 }
606 catch (NotSupportedException e)
607 {
608 stream.Position = p;
609 throw new global::java.io.IOException(e.Message);
610 }
611 catch (UnauthorizedAccessException e)
612 {
613 stream.Position = p;
614 throw new global::java.io.IOException(e.Message);
615 }
616 catch (IOException e)
617 {
618 stream.Position = p;
619 throw new global::java.io.IOException(e.Message);
620 }
621 }
622 else
623 {
624 __callerID ??= global::ikvm.@internal.CallerID.create(typeof(global::java.io.RandomAccessFile).TypeHandle);
625 __jniPtr__setLength ??= Marshal.GetDelegateForFunctionPointer<__jniDelegate__setLength>(JNIFrame.GetFuncPtr(__callerID, "java/io/RandomAccessFile", nameof(setLength), "(J)V"));
626 var jniFrm = new JNIFrame();
627 var jniEnv = jniFrm.Enter(__callerID);
628 try
629 {
630 __jniPtr__setLength(jniEnv, jniFrm.MakeLocalRef(self), newLength);
631 }
632 catch (Exception ex)
633 {
634 System.Console.WriteLine("*** exception in native code ***");
635 System.Console.WriteLine(ex);
636 throw;
637 }
638 finally
639 {
640 jniFrm.Leave();
641 }
642 }
643#endif
644 }
static void setLength(object self, long newLength)
Implements the native method 'setLength'.

◆ write0()

static void IKVM.Java.Externs.java.io.RandomAccessFile.write0 ( object self,
int @ byte )
static

Implements the native method 'write'.

Parameters
self
byte

Definition at line 284 of file RandomFileAccess.cs.

285 {
286#if FIRST_PASS
287 throw new NotImplementedException();
288#else
289 var fd = RandomAccessFileAccessor.GetFd(self);
290 if (fd == null)
291 throw new global::java.io.IOException("Invalid file handle.");
292
293 if (FileDescriptorAccessor.GetStream(fd) is Stream stream)
294 {
295 if (stream.CanWrite == false)
296 throw new global::java.io.IOException("Write failed.");
297
298 try
299 {
300 stream.WriteByte((byte)@byte);
301 }
302 catch (ObjectDisposedException e)
303 {
304 throw new global::java.io.IOException(e.Message);
305 }
306 catch (NotSupportedException e)
307 {
308 throw new global::java.io.IOException(e.Message);
309 }
310 catch (IOException e)
311 {
312 throw new global::java.io.IOException(e.Message);
313 }
314 }
315 else
316 {
317 __callerID ??= global::ikvm.@internal.CallerID.create(typeof(global::java.io.RandomAccessFile).TypeHandle);
318 __jniPtr__write0 ??= Marshal.GetDelegateForFunctionPointer<__jniDelegate__write0>(JNIFrame.GetFuncPtr(__callerID, "java/io/RandomAccessFile", nameof(write0), "(I)V"));
319 var jniFrm = new JNIFrame();
320 var jniEnv = jniFrm.Enter(__callerID);
321 try
322 {
323 __jniPtr__write0(jniEnv, jniFrm.MakeLocalRef(self), @byte);
324 }
325 catch (Exception ex)
326 {
327 System.Console.WriteLine("*** exception in native code ***");
328 System.Console.WriteLine(ex);
329 throw;
330 }
331 finally
332 {
333 jniFrm.Leave();
334 }
335 }
336#endif
337 }
static void write0(object self, int @byte)
Implements the native method 'write'.

◆ writeBytes()

static void IKVM.Java.Externs.java.io.RandomAccessFile.writeBytes ( object self,
byte[] bytes,
int off,
int len )
static

Implements the native method 'writeBytes'.

Parameters
self
bytes
off
len

Definition at line 346 of file RandomFileAccess.cs.

347 {
348#if FIRST_PASS
349 throw new NotImplementedException();
350#else
351 var fd = RandomAccessFileAccessor.GetFd(self);
352 if (fd == null)
353 throw new global::java.io.IOException("Invalid file handle.");
354
355 if (FileDescriptorAccessor.GetStream(fd) is Stream stream)
356 {
357 if ((off < 0) || (off > bytes.Length) || (len < 0) || (len > (bytes.Length - off)))
358 throw new global::java.lang.IndexOutOfBoundsException();
359 if (stream.CanWrite == false)
360 throw new global::java.io.IOException("Write failed.");
361
362 try
363 {
364 stream.Write(bytes, off, len);
365 }
366 catch (ObjectDisposedException e)
367 {
368 throw new global::java.io.IOException(e.Message);
369 }
370 catch (NotSupportedException e)
371 {
372 throw new global::java.io.IOException(e.Message);
373 }
374 catch (IOException e)
375 {
376 throw new global::java.io.IOException(e.Message);
377 }
378 }
379 else
380 {
381 __callerID ??= global::ikvm.@internal.CallerID.create(typeof(global::java.io.RandomAccessFile).TypeHandle);
382 __jniPtr__writeBytes ??= Marshal.GetDelegateForFunctionPointer<__jniDelegate__writeBytes>(JNIFrame.GetFuncPtr(__callerID, "java/io/RandomAccessFile", nameof(writeBytes), "([BII)V"));
383 var jniFrm = new JNIFrame();
384 var jniEnv = jniFrm.Enter(__callerID);
385 try
386 {
387 __jniPtr__writeBytes(jniEnv, jniFrm.MakeLocalRef(self), jniFrm.MakeLocalRef(bytes), off, len);
388 }
389 catch (Exception ex)
390 {
391 System.Console.WriteLine("*** exception in native code ***");
392 System.Console.WriteLine(ex);
393 throw;
394 }
395 finally
396 {
397 jniFrm.Leave();
398 }
399 }
400#endif
401 }
static void writeBytes(object self, byte[] bytes, int off, int len)
Implements the native method 'writeBytes'.

The documentation for this class was generated from the following file: