@Override public void delete(File file) throws IOException { // If delete() fails, make sure it's because the file didn't exist! if (!file.delete() && file.exists()) { throw new IOException("failed to delete " + file); } }
private InputFile(File file) throws IOException { if (!file.exists()) { throw new IOException("File not found: " + file.getAbsolutePath()); } this.file = file; }
protected File toFileForceExists(String filename) throws IOException { File file = new File(filename); if (!file.exists()) { throw new IOException(filename + " does not exist. This check is to prevent accidental file generation into a wrong path."); } return file; }
private static void checkAndCreateDirectory(File directory) throws IOException { if (directory.exists()) { if (!directory.isDirectory()) { throw new IOException("Not a directory: " + directory); } } else { if (!directory.mkdirs()) { throw new IOException( String.format("Could not create RocksDB data directory at %s.", directory)); } } }
public static void checkJarFile(URL jar) throws IOException { File jarFile; try { jarFile = new File(jar.toURI()); } catch (URISyntaxException e) { throw new IOException("JAR file path is invalid '" + jar + "'"); } if (!jarFile.exists()) { throw new IOException("JAR file does not exist '" + jarFile.getAbsolutePath() + "'"); } if (!jarFile.canRead()) { throw new IOException("JAR file can't be read '" + jarFile.getAbsolutePath() + "'"); } // TODO: Check if proper JAR file }
public void run() throws Exception { File file = new File("README.md"); Request request = new Request.Builder() .url("https://api.github.com/markdown/raw") .post(RequestBody.create(MEDIA_TYPE_MARKDOWN, file)) .build(); try (Response response = client.newCall(request).execute()) { if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); System.out.println(response.body().string()); } }
/** * Creates single folders. */ public static void mkdir(File dir) throws IOException { if (dir.exists()) { if (!dir.isDirectory()) { throw new IOException(MSG_NOT_A_DIRECTORY + dir); } return; } if (!dir.mkdir()) { throw new IOException(MSG_CANT_CREATE + dir); } }
@Override public String invoke(File dir, VirtualChannel channel) throws IOException { if(!inThisDirectory) dir = new File(System.getProperty("java.io.tmpdir")); else mkdirs(dir); File f; try { f = creating(File.createTempFile(prefix, suffix, dir)); } catch (IOException e) { throw new IOException("Failed to create a temporary directory in "+dir,e); } try (Writer w = new FileWriter(writing(f))) { w.write(contents); } return f.getAbsolutePath(); } }
private static void throwExceptionIfDirectoryIsNotCreatable(File to) throws IOException { if (!to.exists() && !to.mkdirs()) { throw new IOException(ERROR_CREATING_DIRECTORY + to); } }
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { try { read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); } }
protected static TProtocol newProtocol(URL url, ChannelBuffer buffer) throws IOException { String protocol = url.getParameter(ThriftConstants.THRIFT_PROTOCOL_KEY, ThriftConstants.DEFAULT_PROTOCOL); if (ThriftConstants.BINARY_THRIFT_PROTOCOL.equals(protocol)) { return new TBinaryProtocol(new TIOStreamTransport(new ChannelBufferOutputStream(buffer))); } throw new IOException("Unsupported protocol type " + protocol); }
/** * Creates all folders at once. */ public static void mkdirs(File dirs) throws IOException { if (dirs.exists()) { if (!dirs.isDirectory()) { throw new IOException(MSG_NOT_A_DIRECTORY + dirs); } return; } if (!dirs.mkdirs()) { throw new IOException(MSG_CANT_CREATE + dirs); } }
private Props loadDBProps() throws IOException { final File dbPropsFile = new File(this.scriptPath, "database.properties"); if (!dbPropsFile.exists()) { throw new IOException( "Cannot find 'database.properties' file in " + dbPropsFile.getAbsolutePath()); } return new Props(null, dbPropsFile); }
// File (or directory) with old name File file = new File("oldname"); // File (or directory) with new name File file2 = new File("newname"); if (file2.exists()) throw new java.io.IOException("file exists"); // Rename file (or directory) boolean success = file.renameTo(file2); if (!success) { // File was not successfully renamed }
@Override public void visitSymlink(File link, String target, String relativePath) throws IOException { try { mkdirsE(new File(dest, relativePath).getParentFile()); writing(new File(dest, target)); Util.createSymlink(dest, target, relativePath, TaskListener.NULL); } catch (InterruptedException x) { throw new IOException(x); } count.incrementAndGet(); } }));
public void setSignData(File signatureFile, String keypass, String storealias, String storepass) throws IOException { if (mUseSignAPk) { mSignatureFile = signatureFile; if (!mSignatureFile.exists()) { throw new IOException( String.format("the signature file do not exit, raw path= %s\n", mSignatureFile.getAbsolutePath()) ); } mKeyPass = keypass; mStoreAlias = storealias; mStorePass = storepass; } }
private static void checkDirCopy(File srcDir, File destDir) throws IOException { if (!srcDir.exists()) { throw new FileNotFoundException(MSG_NOT_FOUND + srcDir); } if (!srcDir.isDirectory()) { throw new IOException(MSG_NOT_A_DIRECTORY + srcDir); } if (equals(srcDir, destDir)) { throw new IOException("Source '" + srcDir + "' and destination '" + destDir + "' are equal"); } }
@Override public void delete(File file) throws IOException { // If delete() fails, make sure it's because the file didn't exist! if (!file.delete() && file.exists()) { throw new IOException("failed to delete " + file); } }
@Override public Void invoke(File f, VirtualChannel channel) throws IOException { // JENKINS-16846: if f.getName() is the same as one of the files/directories in f, // then the rename op will fail File tmp = new File(f.getAbsolutePath()+".__rename"); if (!f.renameTo(tmp)) throw new IOException("Failed to rename "+f+" to "+tmp); File t = new File(target.getRemote()); for(File child : reading(tmp).listFiles()) { File target = new File(t, child.getName()); if(!stating(child).renameTo(creating(target))) throw new IOException("Failed to rename "+child+" to "+target); } deleting(tmp).delete(); return null; } }
@Override public void mkdirs( File path ) throws IOException { if ( path.exists() ) { return; } path.mkdirs(); if ( path.exists() ) { return; } throw new IOException( format( UNABLE_TO_CREATE_DIRECTORY_FORMAT, path ) ); }