public static File appendSuffix(File file, String suffix) throws IOException { if (file == null) { Throw.ioe(TAG, "File is null."); return null; // To make static analysis happy } checkValidSuffix(suffix); if (file.getAbsolutePath().endsWith(suffix)) Throw.ioe(TAG, "File already has suffix %s: %s", suffix, file.getAbsolutePath()); return new File(file.getAbsolutePath() + suffix); }
private boolean overridesToString(Object object) { try { Class<?> type = object.getClass(); Method toString = type.getMethod("toString"); return toString.getDeclaringClass() != Object.class; } catch (SecurityException ex) { throw Throw.exception(ex); } catch (NoSuchMethodException ex) { throw Throw.exception(ex); } }
public static void checkReadableDirectory(File dir) throws IOException { if (dir == null) { Throw.ioe(TAG, "Directory object File is null."); } else { if (!dir.exists()) Throw.ioe(TAG, "Directory does not exist: " + dir.getAbsolutePath()); if (!dir.isDirectory()) Throw.ioe(TAG, "Not a directory: " + dir.getAbsolutePath()); if (!dir.canRead()) Throw.ioe(TAG, "No read permission: " + dir.getAbsolutePath()); if (!dir.canExecute()) Throw.ioe(TAG, "No execute (access files) permission: " + dir.getAbsolutePath()); } }
public static File replaceSuffix(File file, String newSuffix) throws IOException { if (file == null) { Throw.ioe(TAG, "File is null."); return null; // To make static analysis happy } checkValidSuffix(newSuffix); String currentSuffix = getSuffix(file); if (newSuffix.equals(currentSuffix)) Throw.ioe(TAG, "File already has suffix %s: %s", newSuffix, file.getAbsolutePath()); String path = file.getAbsolutePath(); String withoutSuffix = StringUtils.removeEnd(path, currentSuffix); return appendSuffix(new File(withoutSuffix), newSuffix); }
public T create(Object obj1, Object obj2, Object obj3) { try { return takeThree.newInstance(obj1, obj2, obj3); } catch (Exception ex) { throw Throw.exception(ex); } }
public T create(Object obj) { try { return takeOne.newInstance(obj); } catch (Exception ex) { throw Throw.exception(ex); } }
public final PrintOn append(CharSequence string, int start, int end) { try { buf.append(string, start, end); } catch (IOException ex) { throw Throw.exception(ex); } return this; }
public final PrintOn append(char c) { try { buf.append(c); } catch (IOException ex) { throw Throw.exception(ex); } return this; }
public final void close() { if (buf instanceof Closeable) { try { ((Closeable) buf).close(); } catch (IOException ex) { throw Throw.exception(ex); } } }
public static String getSuffix(File file) throws IOException { if (file == null) { Throw.ioe(TAG, "File is null."); return null; // To make static analysis happy } String path = file.getAbsolutePath(); String suffix = "." + StringUtils.substringAfterLast(path, "."); checkValidSuffix(suffix); return suffix; }
/** Returns a subdirectory of outer. Creates it if necesssary and checks for write permissions. */ public static synchronized File getSubdir(File outer, String name) throws IOException { File dir = new File(outer, name); if (!dir.exists()) { if (!dir.mkdirs()) { Throw.ioe(TAG, "Failed to create " + dir.getAbsolutePath()); } } checkWritableDirectory(dir); return dir; }
public void run() { InstField instField = new InstField(); instField.run(); StaticField.run(); IntMath.run(); FloatMath.run(); Compare.run(); Monitor.run(); Switch.run(); Array.run(); Classes.run(); Goto.run(); MethodCall.run(); Throw.run(); try { UnresTest1.run(); } catch (VerifyError ve) { System.out.println("Caught: " + ve); } try { UnresTest1.run(); } catch (VerifyError ve) { System.out.println("Caught (retry): " + ve); } try { UnresTest2.run(); } catch (VerifyError ve) { System.out.println("Caught: " + ve); } catch (Throwable th) { // We and the RI throw ClassNotFoundException, but that isn't declared so javac // won't let us try to catch it. th.printStackTrace(); } InternedString.run(); }
public static void checkValidSuffix(String suffix) throws IOException { if (suffix == null) { Throw.ioe(TAG, "Suffix is null."); } else { if ("".equals(suffix)) Throw.ioe(TAG, "Suffix is empty string."); if (!suffix.startsWith(".")) Throw.ioe(TAG, "Suffix must start with a dot: \"%s\".", suffix); if (suffix.length() < 2) Throw.ioe(TAG, "Suffix \"%s\" is too short. Must be (dot)[a-z]{1,10}.", suffix); if (suffix.length() > 11) Throw.ioe(TAG, "Suffix \"%s\" is too long. Must be (dot)[a-z]{1,10}.", suffix); if (!StringUtils.containsOnly( suffix.substring(1, suffix.length()), "abcdefghijklmnopqrstuvwxyz")) Throw.ioe( TAG, "Suffix \"%s\" contains weird characters. Must be (dot)[a-z]{1,10}.", suffix); } }
public void throw_clause_end() { IExceptionBlock exception_code = findNearestEnclosingTryExceptBlock(); if (exception_code != null) { ((Throw) currentCode).setInTryBlock(true); } }
public static void checkWritableDirectory(File dir) throws IOException { checkReadableDirectory(dir); if (!dir.canWrite()) Throw.ioe(TAG, "No write permission: " + dir.getAbsolutePath()); }