FileNioMapped(String fileName, String mode) throws IOException { if ("r".equals(mode)) { this.mode = MapMode.READ_ONLY; } else { this.mode = MapMode.READ_WRITE; } this.name = fileName; file = new RandomAccessFile(fileName, mode); reMap(); }
public synchronized void setFileLength(long newLength) throws IOException { checkFileSizeLimit(newLength); int oldPos = pos; unMap(); for (int i = 0;; i++) { try { file.setLength(newLength); break; } catch (IOException e) { if (i > 16 || e.toString().indexOf("user-mapped section open") < 0) { throw e; } } System.gc(); } reMap(); pos = (int) Math.min(newLength, oldPos); }