AbstractFileResource.java

  1. package org.jruby.util;

  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import jnr.constants.platform.Errno;

  5. abstract class AbstractFileResource implements FileResource {

  6.     @Override
  7.     public boolean canExecute() {
  8.         return false;
  9.     }

  10.     public int errno() {
  11.         return Errno.ENOENT.intValue();
  12.     }

  13.     @Override
  14.     public InputStream inputStream() throws ResourceException {
  15.         if (!exists()) {
  16.             throw new ResourceException.NotFound(absolutePath());
  17.         }
  18.         if (isDirectory()) {
  19.             throw new ResourceException.FileIsDirectory(absolutePath());
  20.         }
  21.         try {
  22.             return openInputStream();
  23.         }
  24.         catch (IOException e) {
  25.             throw new ResourceException.IOError(e);
  26.         }
  27.     }

  28.     abstract InputStream openInputStream() throws IOException;

  29. }