public long tell() throws IOException { try { return raf.getFilePointer(); } catch (IOException e) { PortableFileSystem.processIOException(e); throw e; //unreachable } }
static void processIOException(IOException e) throws IOException { if (e instanceof EOFException) { throw new IOException("EOF"); } processErrno(e.getMessage(), e); } }
@Test public void testReadFile() throws Exception { when(files.resolveWorkingDirectory(Matchers.anyString())).thenAnswer(new Answer<java.io.File>() { @Override public java.io.File answer(InvocationOnMock invocation) throws Throwable { return new java.io.File((String)invocation.getArguments()[0]); } }); PortableFileSystem fs = new PortableFileSystem(kem, files); long fd = fs.open(new java.io.File(getClass().getResource("/fs-test.txt").toURI()).getAbsolutePath(), "r"); File f = fs.get(fd); byte[] file = "foo\n".getBytes(Charset.forName("ASCII")); Assert.assertArrayEquals(file, f.read(4)); try { f.read(1); Assert.fail(); } catch (IOException e) { Assert.assertEquals("EOF", e.getMessage()); } }
FileOutputStream f = new FileOutputStream(path); fileFD = f.getFD(); file = new OutputStreamFile(f, kem); } else { RandomAccessFile f = new RandomAccessFile(fileUtil.resolveWorkingDirectory(path), mode); fileFD = f.getFD(); file = new RandomAccessFileFile(f); } catch (FileNotFoundException e) { try { processFileNotFoundException(e); } catch (IOException ioe) { if (ioe.getMessage().equals("EISDIR") && mode.equals("r")) {
@Inject public PortableFileSystem(KExceptionManager kem, FileUtil fileUtil) { this.fileUtil = fileUtil; this.kem = kem; descriptors.put(0L, FileDescriptor.in); descriptors.put(1L, FileDescriptor.out); descriptors.put(2L, FileDescriptor.err); files.put(FileDescriptor.in, new InputStreamFile(System.in, kem)); files.put(FileDescriptor.out, new OutputStreamFile(System.out, kem)); files.put(FileDescriptor.err, new OutputStreamFile(System.err, kem)); }
public void write(byte[] b) throws IOException { try { raf.write(b); } catch (IOException e) { PortableFileSystem.processIOException(e); } }
static void processFileNotFoundException(FileNotFoundException e) throws IOException { String message = e.getMessage(); int startIdx = message.lastIndexOf("(") + 1; int endIdx = message.length() - 1; String realMessage = message.substring(startIdx, endIdx); processErrno(realMessage, e); }
void close() throws IOException { try { os.close(); } catch (IOException e) { PortableFileSystem.processIOException(e); } } }
void close() throws IOException { try { is.close(); } catch (IOException e) { PortableFileSystem.processIOException(e); } } }
public void seek(long pos) throws IOException { try { raf.seek(pos); } catch (IOException e) { PortableFileSystem.processIOException(e); } }
void close() throws IOException { try { raf.close(); } catch (IOException e) { PortableFileSystem.processIOException(e); } } }
public void putc(byte b) throws IOException { try { os.write(b); } catch (IOException e) { PortableFileSystem.processIOException(e); } finally { os.flush(); } }
public void write(byte[] b) throws IOException { try { os.write(b); } catch (IOException e) { PortableFileSystem.processIOException(e); } finally { os.flush(); } }
public byte getc() throws IOException { int read; try { read = is.read(); } catch (IOException e) { PortableFileSystem.processIOException(e); throw e; //unreachable } if (read == -1) { throw new IOException("EOF"); } return (byte)read; }
public byte getc() throws IOException { try { return raf.readByte(); } catch (IOException e) { PortableFileSystem.processIOException(e); throw e; //unreachable } }
public void putc(byte b) throws IOException { try { raf.writeByte(b); } catch (IOException e) { PortableFileSystem.processIOException(e); } }
public byte[] read(int n) throws IOException { int read; byte[] bytes; try { bytes = new byte[n]; read = is.read(bytes); } catch (IOException e) { PortableFileSystem.processIOException(e); throw e; //unreachable } if (read == -1) { throw new IOException("EOF"); } return Arrays.copyOfRange(bytes, 0, read); }
public byte[] read(int n) throws IOException { int read; byte[] bytes; try { bytes = new byte[n]; read = raf.read(bytes); } catch (IOException e) { PortableFileSystem.processIOException(e); throw e; //unreachable } if (read == -1) { throw new IOException("EOF"); } return Arrays.copyOfRange(bytes, 0, read); }