Retrieve a writer for a given path or create a new one if it does not exist.
@param path The path to retrieve writer for.
@param codec Optional compression codec.
@return Writer for a given path.
@throws Exception on error
354948
public FileWriter getOrCreateWriter(LogFilePath path, CompressionCodec codec)
            throws Exception {
        FileWriter writer = mWriters.get(path);
        if (writer == null) {
            // Just in case.
            FileUtil.delete(path.getLogFilePath());
            FileUtil.delete(path.getLogFileCrcPath());
            TopicPartitionGroup topicPartition = new TopicPartitionGroup(path.getTopic(),
                    path.getKafkaPartitions());
            HashSet<LogFilePath> files = mFiles.get(topicPartition);
            if (files == null) {
                files = new HashSet<LogFilePath>();
                mFiles.put(topicPartition, files);
            }
            if (!files.contains(path)) {
                files.add(path);
            }
            writer = ReflectionUtil.createFileWriter(mConfig.getFileReaderWriterFactory(), path, codec, mConfig);
            mWriters.put(path, writer);
            mCreationTimes.put(path, System.currentTimeMillis() / 1000L);
            LOG.debug("created writer for path {}", path.getLogFilePath());
            LOG.debug("Register deleteOnExit for path {}", path.getLogFilePath());
            FileUtil.deleteOnExit(path.getLogFileParentDir());
            FileUtil.deleteOnExit(path.getLogFileDir());
            FileUtil.deleteOnExit(path.getLogFilePath());
            FileUtil.deleteOnExit(path.getLogFileCrcPath());
        }
        return writer;
    }
1336092
public static Writer buildBufferedAppendWriter(Path path, Charset charset) {
        try {
            if (JMPath.notExists(path))
                JMPathOperation.createFileWithParentDirectories(path);
            return Files.newBufferedWriter(path, charset, StandardOpenOption
                    .APPEND);
        } catch (IOException e) {
            return JMExceptionManager.handleExceptionAndReturnNull(log, e,
                    "buildBufferedAppendWriter", path, charset);
        }
    }
609731
public static File maybeMarkUnwritable(File path)
    {
        File directory = getDirectory(path);
        if (instance.unwritableDirectories.add(directory))
        {
            logger.warn("Blacklisting {} for writes", directory);
            return directory;
        }
        return null;
    }
831213
public <T extends Normalizer> T restore(@NonNull String path) throws Exception {
        try (InputStream in = new BufferedInputStream(new FileInputStream(path))) {
            return restore(in);
        }
    }
5948
public static BufferedWriter getWriter(String path, Charset charset, boolean isAppend) throws IORuntimeException {
		return getWriter(touch(path), charset, isAppend);
	}
452302
public static String encodePath(String path) throws NullPointerException {
		return new String(encode(path, UriComponentEncoderBitSets.allowed_abs_path));
	}
1324503
public void write(final Path path, final Writer<? super T> writer) {
		try {
			final File tempFile = createTempFile("__trial_meter__", ".xml");
			try {
				try (OutputStream out = new FileOutputStream(tempFile)) {
					write(out, writer);
				}

				move(tempFile.toPath(), path, REPLACE_EXISTING);
			} finally {
				deleteIfExists(tempFile.toPath());
			}
		} catch (IOException e) {
			throw new UncheckedIOException(e);
		}
	}
400601
public static void writeStringToFile(String contents, String path, String encoding) throws IOException {
		OutputStream writer = null;
		if (path.endsWith(".gz")) {
      writer = new GZIPOutputStream(new FileOutputStream(path));
    } else {
      writer = new BufferedOutputStream(new FileOutputStream(path));
    }
		writer.write(contents.getBytes(encoding));
	}
764637
public Response get(String path) throws IOException, RESTException {
        return get(path, null, null);
    }
73033
public static Stream<String> getLineStream(Path path, Charset charset) {
        try {
            return charset == null ? Files.lines(path) : Files
                    .lines(path, charset);
        } catch (Exception e) {
            return JMExceptionManager.handleExceptionAndReturn(log, e,
                    "getLineStream", Stream::empty, path, charset);
        }
    }
1232819
public static String getFilename(String path) throws IllegalArgumentException {
        if (Pattern.matches(sPatternUrl, path))
            return getURLFilename(path);

        return new File(path).getName();
    }
529963
@GwtIncompatible("Unnecessary")
  private Writer openExternExportsStream(B options, String path) throws IOException {
    if (options.externExportsPath == null) {
      return null;
    }

    String exPath = options.externExportsPath;

    if (!exPath.contains(File.separator)) {
      File outputFile = new File(path);
      exPath = outputFile.getParent() + File.separatorChar + exPath;
    }

    return fileNameToOutputWriter2(exPath);
  }
621369
public static ByteBuffer create(Path path, int maxSize) throws IOException
    {
        try (FileChannel fc = FileChannel.open(path, READ, WRITE, CREATE))
        {
            return fc.map(FileChannel.MapMode.READ_WRITE, 0, maxSize);
        }
    }
396963
def writer(path):
    
    filename, extension = extract_extension(path)
    if extension in FILE_WRITERS:
        writer_func = FILE_WRITERS[extension]
        return writer_func(path)
    else:
        raise RuntimeError("Output compression {0} not supported.  Type {1}"
                           .format(extension, tuple(FILE_WRITERS.keys())))
828644
public WritableByteChannel create(URI path) throws IOException {
    logger.atFine().log("create(%s)", path);
    return create(path, CreateFileOptions.DEFAULT);
  }
583422
public static String get(String host, String path, String param) {
        ExceptionUtil.notNull(host);
        return get(host, path, null, param);
    }
344723
protected String rewriteUrl(String path) throws UnsupportedEncodingException {

        return new String(URLCodec.encodeUrl(URL_SAFE_CHARS, path.getBytes("ISO-8859-1")));
    }