/** * Constructs a new FileOutputStream on the File {@code file}. The parameter {@code append} * determines whether or not the file is opened and appended to or just opened and overwritten. * * @param file the file to which this stream writes. * @param append indicates whether or not to append to an existing file. * @throws FileNotFoundException if the {@code file} cannot be opened for writing. * @throws SecurityException if a {@code SecurityManager} is installed and it denies the write * request. * @see java.lang.SecurityManager#checkWrite(FileDescriptor) * @see java.lang.SecurityManager#checkWrite(String) */ public FileOutputStream(File file, boolean append) throws FileNotFoundException { super(); if (file.getPath().isEmpty() || file.isDirectory()) { throw new FileNotFoundException(file.getAbsolutePath()); } fd = new FileDescriptor(); fd.readOnly = false; fd.descriptor = open(file.getAbsolutePath(), append); }
public static void setupGateway() throws Exception { File targetDir = new File(System.getProperty("user.dir"), "target"); File gatewayDir = new File(targetDir, "gateway-home-" + uuid); gatewayDir.mkdirs(); GatewayTestConfig testConfig = new GatewayTestConfig(); config = testConfig; testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath()); File topoDir = new File(testConfig.getGatewayTopologyDir()); topoDir.mkdirs(); File deployDir = new File(testConfig.getGatewayDeploymentDir()); deployDir.mkdirs(); createTopology(topoDir, "test-cluster.xml", true); createTopology(topoDir, "bad-cluster.xml", false); DefaultGatewayServices srvcs = new DefaultGatewayServices(); Map<String, String> options = new HashMap<String, String>(); options.put("persist-master", "false"); options.put("master", "password"); try { srvcs.init(testConfig, options); } catch (ServiceLifecycleException e) { e.printStackTrace(); // I18N not required. } }
/** * Constructs a new {@code FileOutputStream} that writes to {@code file}. If {@code append} is * true and the file already exists, it will be appended to; otherwise it will be truncated. The * file will be created if it does not exist. * * @throws FileNotFoundException if the file cannot be opened for writing. */ public FileOutputStream(File file, boolean append) throws FileNotFoundException { if (file == null) { throw new NullPointerException("file == null"); } this.mode = O_WRONLY | O_CREAT | (append ? O_APPEND : O_TRUNC); this.fd = IoBridge.open(file.getAbsolutePath(), mode); this.channel = new IOCipherFileChannel(this, fd, mode); this.shouldClose = true; }