OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 156
Line 36... Line 36...
36
import java.io.Reader;
36
import java.io.Reader;
37
import java.net.URI;
37
import java.net.URI;
38
import java.net.URL;
38
import java.net.URL;
39
import java.nio.channels.FileChannel;
39
import java.nio.channels.FileChannel;
40
import java.nio.charset.Charset;
40
import java.nio.charset.Charset;
-
 
41
import java.nio.charset.StandardCharsets;
41
import java.nio.file.CopyOption;
42
import java.nio.file.CopyOption;
42
import java.nio.file.DirectoryStream;
43
import java.nio.file.DirectoryStream;
43
import java.nio.file.DirectoryStream.Filter;
44
import java.nio.file.DirectoryStream.Filter;
44
import java.nio.file.FileVisitResult;
45
import java.nio.file.FileVisitResult;
45
import java.nio.file.Files;
46
import java.nio.file.Files;
Line 95... Line 96...
95
                throw new IOException("error (" + res + ") executing " + Arrays.asList(cmdarray));
96
                throw new IOException("error (" + res + ") executing " + Arrays.asList(cmdarray));
96
        }
97
        }
97
    }
98
    }
98
 
99
 
99
    public static void openFile(File f) throws IOException {
100
    public static void openFile(File f) throws IOException {
-
 
101
        if (!f.exists()) {
-
 
102
            throw new FileNotFoundException(f.getAbsolutePath() + " not found");
-
 
103
        }
100
        if (Desktop.isDesktopSupported()) {
104
        if (Desktop.isDesktopSupported()) {
101
            Desktop d = Desktop.getDesktop();
105
            Desktop d = Desktop.getDesktop();
102
            if (d.isSupported(Desktop.Action.OPEN)) {
106
            if (d.isSupported(Desktop.Action.OPEN)) {
103
                d.open(f.getCanonicalFile());
107
                d.open(f.getCanonicalFile());
104
            } else {
108
            } else {
Line 614... Line 618...
614
 
618
 
615
    public static final String readUTF8(File f) throws IOException {
619
    public static final String readUTF8(File f) throws IOException {
616
        return readUTF8(new FileInputStream(f));
620
        return readUTF8(new FileInputStream(f));
617
    }
621
    }
618
 
622
 
-
 
623
    public static final String readUTF8(Path p) throws IOException {
-
 
624
        return new String(Files.readAllBytes(p), StandardCharsets.UTF_8);
-
 
625
    }
-
 
626
 
619
    public static final String readUTF8(InputStream ins) throws IOException {
627
    public static final String readUTF8(InputStream ins) throws IOException {
620
        return read(ins, StringUtils.UTF8);
628
        return read(ins, StringUtils.UTF8);
621
    }
629
    }
622
 
630
 
623
    public static final String read(File f, Charset charset) throws IOException {
631
    public static final String read(File f, Charset charset) throws IOException {
Line 898... Line 906...
898
     * @param f the file to open.
906
     * @param f the file to open.
899
     * @param executables a list of executables to try, e.g. ["ooffice", "soffice"].
907
     * @param executables a list of executables to try, e.g. ["ooffice", "soffice"].
900
     * @throws IOException if the file can't be opened.
908
     * @throws IOException if the file can't be opened.
901
     */
909
     */
902
    public static final void open(File f, String[] executables) throws IOException {
910
    public static final void open(File f, String[] executables) throws IOException {
-
 
911
        if (!f.exists()) {
-
 
912
            throw new FileNotFoundException(f.getAbsolutePath() + " not found");
-
 
913
        }
903
        try {
914
        try {
904
            openNative(f);
915
            openNative(f);
905
        } catch (IOException exn) {
916
        } catch (IOException exn) {
906
            for (int i = 0; i < executables.length; i++) {
917
            for (int i = 0; i < executables.length; i++) {
907
                final String executable = executables[i];
918
                final String executable = executables[i];