java.io.IOException.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(248)

本文整理了Java中java.io.IOException.<init>()方法的一些代码示例,展示了IOException.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOException.<init>()方法的具体详情如下:
包路径:java.io.IOException
类名称:IOException
方法名:<init>

IOException.<init>介绍

[英]Constructs a new IOException with its stack trace filled in.
[中]构造一个新的IOException,并填充其堆栈跟踪。

代码示例

代码示例来源:origin: square/okhttp

@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);
 }
}

代码示例来源:origin: skylot/jadx

private InputFile(File file) throws IOException {
  if (!file.exists()) {
    throw new IOException("File not found: " + file.getAbsolutePath());
  }
  this.file = file;
}

代码示例来源:origin: greenrobot/greenDAO

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;
}

代码示例来源:origin: apache/flink

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));
    }
  }
}

代码示例来源:origin: apache/flink

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
}

代码示例来源:origin: square/okhttp

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());
 }
}

代码示例来源:origin: redisson/redisson

/**
 * 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);
  }
}

代码示例来源:origin: jenkinsci/jenkins

@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();
  }
}

代码示例来源:origin: SonarSource/sonarqube

private static void throwExceptionIfDirectoryIsNotCreatable(File to) throws IOException {
 if (!to.exists() && !to.mkdirs()) {
  throw new IOException(ERROR_CREATING_DIRECTORY + to);
 }
}

代码示例来源:origin: apache/zeppelin

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);
 }
}

代码示例来源:origin: apache/incubator-dubbo

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);
}

代码示例来源:origin: redisson/redisson

/**
 * 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);
  }
}

代码示例来源:origin: azkaban/azkaban

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);
}

代码示例来源:origin: stackoverflow.com

// 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
}

代码示例来源:origin: jenkinsci/jenkins

@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();
  }
}));

代码示例来源:origin: Tencent/tinker

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;
  }
}

代码示例来源:origin: redisson/redisson

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");
  }
}

代码示例来源:origin: prestodb/presto

@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);
 }
}

代码示例来源:origin: jenkinsci/jenkins

@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;
    }
}

代码示例来源:origin: neo4j/neo4j

@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 ) );
}

相关文章