Example #1
0
 @Override
 public String getText() {
   Reader reader = getAsReader();
   try {
     try {
       return IOUtils.toString(reader);
     } finally {
       reader.close();
     }
   } catch (Exception e) {
     throw ResourceExceptions.failure(
         sourceUri, String.format("Could not read %s.", getDisplayName()), e);
   }
 }
Example #2
0
 @Override
 public boolean getHasEmptyContent() {
   Reader reader = getAsReader();
   try {
     try {
       return reader.read() == -1;
     } finally {
       reader.close();
     }
   } catch (Exception e) {
     throw ResourceExceptions.failure(
         sourceUri, String.format("Could not read %s.", getDisplayName()), e);
   }
 }
Example #3
0
 @Override
 public boolean getExists() {
   try {
     Reader reader = getInputStream(sourceUri);
     try {
       return true;
     } finally {
       reader.close();
     }
   } catch (FileNotFoundException e) {
     return false;
   } catch (Exception e) {
     throw ResourceExceptions.failure(
         sourceUri, String.format("Could not determine if %s exists.", getDisplayName()), e);
   }
 }
Example #4
0
 @Override
 public Reader getAsReader() {
   if (sourceFile != null && sourceFile.isDirectory()) {
     throw new ResourceIsAFolderException(
         sourceUri, String.format("Could not read %s as it is a directory.", getDisplayName()));
   }
   try {
     return getInputStream(sourceUri);
   } catch (FileNotFoundException e) {
     throw new MissingResourceException(
         sourceUri, String.format("Could not read %s as it does not exist.", getDisplayName()));
   } catch (Exception e) {
     throw ResourceExceptions.failure(
         sourceUri, String.format("Could not read %s.", getDisplayName()), e);
   }
 }