Java File Read by Charset toFiles(@Nonnull Process p, @Nonnull Charset charset)

Here you can find the source of toFiles(@Nonnull Process p, @Nonnull Charset charset)

Description

to Files

License

EUPL

Declaration

@Nonnull
    public static File[] toFiles(@Nonnull Process p, @Nonnull Charset charset) throws IOException 

Method Source Code


//package com.java2s;
/*/*from w w w  .java  2 s.  c  om*/
 * Copyright 2015 National Bank of Belgium
 * 
 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved 
 * by the European Commission - subsequent versions of the EUPL (the "Licence");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at:
 * 
 * http://ec.europa.eu/idabc/eupl
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the Licence is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and 
 * limitations under the Licence.
 */

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;

import java.io.InputStreamReader;
import java.nio.charset.Charset;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;

public class Main {
    @Nonnull
    public static File[] toFiles(@Nonnull Process p, @Nonnull Charset charset) throws IOException {
        List<File> result = new ArrayList<>();

        try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream(), charset))) {
            // we need the process to end, else we'll get an illegal Thread State Exception
            String line;
            while ((line = reader.readLine()) != null) {
                result.add(new File(line));
            }
            try {
                p.waitFor();
            } catch (InterruptedException ex) {
                // do nothing?
            }
        }

        return result.toArray(new File[result.size()]);
    }
}

Related

  1. setFileText(File file, Charset charset, String text)
  2. setPropertiesVaule(File file, String key, String value, String comments, Charset charset)
  3. setText(File file, Charset charset, String text)
  4. stringToFile(final String s, final File f, final Charset c)
  5. stringToFile(final String string, final Path path, final Charset charset)
  6. toString(File file, String charset)
  7. toString(final Path filePath, final Charset encoding)
  8. utf8Decoder(CodingErrorAction codingErrorAction, Charset fileCharset)