Search in sources :

Example 51 with IOError

use of java.io.IOError in project karaf by apache.

the class DeployMojo method deployWithSsh.

protected void deployWithSsh(List<String> locations) throws MojoExecutionException {
    SshClient client = null;
    try {
        final Console console = System.console();
        client = SshClient.setUpDefaultClient();
        setupAgent(user, keyFile, client);
        client.setUserInteraction(new UserInteraction() {

            @Override
            public void welcome(ClientSession s, String banner, String lang) {
                console.printf(banner);
            }

            @Override
            public String[] interactive(ClientSession s, String name, String instruction, String lang, String[] prompt, boolean[] echo) {
                String[] answers = new String[prompt.length];
                try {
                    for (int i = 0; i < prompt.length; i++) {
                        if (console != null) {
                            if (echo[i]) {
                                answers[i] = console.readLine(prompt[i] + " ");
                            } else {
                                answers[i] = new String(console.readPassword(prompt[i] + " "));
                            }
                        }
                    }
                } catch (IOError e) {
                }
                return answers;
            }

            @Override
            public boolean isInteractionAllowed(ClientSession session) {
                return true;
            }

            @Override
            public void serverVersionInfo(ClientSession session, List<String> lines) {
            }

            @Override
            public String getUpdatedPassword(ClientSession session, String prompt, String lang) {
                return null;
            }
        });
        client.start();
        if (console != null) {
            console.printf("Logging in as %s\n", user);
        }
        ClientSession session = connect(client);
        if (password != null) {
            session.addPasswordIdentity(password);
        }
        session.auth().verify();
        StringWriter writer = new StringWriter();
        PrintWriter print = new PrintWriter(writer, true);
        for (String location : locations) {
            print.println("bundle:install -s " + location);
        }
        final ClientChannel channel = session.createChannel("exec", writer.toString().concat(NEW_LINE));
        channel.setIn(new ByteArrayInputStream(new byte[0]));
        final ByteArrayOutputStream sout = new ByteArrayOutputStream();
        final ByteArrayOutputStream serr = new ByteArrayOutputStream();
        channel.setOut(AnsiConsole.wrapOutputStream(sout));
        channel.setErr(AnsiConsole.wrapOutputStream(serr));
        channel.open();
        channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), 0);
        sout.writeTo(System.out);
        serr.writeTo(System.err);
        // Expects issue KARAF-2623 is fixed
        final boolean isError = (channel.getExitStatus() != null && channel.getExitStatus().intValue() != 0);
        if (isError) {
            final String errorMarker = Ansi.ansi().fg(Color.RED).toString();
            final int fromIndex = sout.toString().indexOf(errorMarker) + errorMarker.length();
            final int toIndex = sout.toString().lastIndexOf(Ansi.ansi().fg(Color.DEFAULT).toString());
            throw new MojoExecutionException(NEW_LINE + sout.toString().substring(fromIndex, toIndex));
        }
    } catch (MojoExecutionException e) {
        throw e;
    } catch (Throwable t) {
        t.printStackTrace();
        throw new MojoExecutionException(t, t.getMessage(), t.toString());
    } finally {
        try {
            client.stop();
        } catch (Throwable t) {
            throw new MojoExecutionException(t, t.getMessage(), t.toString());
        }
    }
}
Also used : SshClient(org.apache.sshd.client.SshClient) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClientChannel(org.apache.sshd.client.channel.ClientChannel) StringWriter(java.io.StringWriter) IOError(java.io.IOError) ByteArrayInputStream(java.io.ByteArrayInputStream) ClientSession(org.apache.sshd.client.session.ClientSession) Console(java.io.Console) AnsiConsole(org.fusesource.jansi.AnsiConsole) UserInteraction(org.apache.sshd.client.auth.keyboard.UserInteraction) PrintWriter(java.io.PrintWriter)

Example 52 with IOError

use of java.io.IOError in project embulk by embulk.

the class MavenArtifactFinder method create.

public static MavenArtifactFinder create(final Path localMavenRepositoryPath) throws MavenRepositoryNotFoundException {
    final Path absolutePath;
    try {
        absolutePath = localMavenRepositoryPath.normalize().toAbsolutePath();
    } catch (IOError ex) {
        throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, ex);
    } catch (SecurityException ex) {
        throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, ex);
    }
    if (!Files.exists(absolutePath)) {
        throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, absolutePath, new NoSuchFileException(absolutePath.toString()));
    }
    if (!Files.isDirectory(absolutePath)) {
        throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, absolutePath, new NotDirectoryException(absolutePath.toString()));
    }
    final RepositorySystem repositorySystem = createRepositorySystem();
    return new MavenArtifactFinder(localMavenRepositoryPath, absolutePath, repositorySystem, createRepositorySystemSession(repositorySystem, absolutePath));
}
Also used : Path(java.nio.file.Path) RepositorySystem(org.eclipse.aether.RepositorySystem) NotDirectoryException(java.nio.file.NotDirectoryException) IOError(java.io.IOError) NoSuchFileException(java.nio.file.NoSuchFileException)

Example 53 with IOError

use of java.io.IOError in project JavaApps by stephenbaiuoft.

the class MergeSortWiki method sort.

// only takes input and prints
public void sort(String input) {
    Scanner in = new Scanner(input);
    int t = in.nextInt();
    for (int a0 = 0; a0 < t; a0++) {
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int arr_i = 0; arr_i < n; arr_i++) {
            try {
                arr[arr_i] = in.nextInt();
            } catch (IOError ie) {
                System.out.println("arr_i is" + arr_i);
                ie.printStackTrace();
                ;
            } finally {
            // System.out.println("arr_i is"+ arr_i);
            }
        }
        // localTemp = Arrays.copyOf(arr, arr.length);
        mergeSort(arr, 0, arr.length - 1);
        if (verifySorted(arr)) {
            System.out.println(Arrays.toString(arr));
            System.out.println("num of swap is: " + countSwap);
        } else {
            System.out.println("ary is not sorted!!!");
        }
    }
}
Also used : Scanner(java.util.Scanner) IOError(java.io.IOError)

Example 54 with IOError

use of java.io.IOError in project error-prone by google.

the class BaseErrorProneCompiler method run.

public Result run(String[] argv) {
    try {
        argv = CommandLine.parse(argv);
    } catch (IOException e) {
        throw new IOError(e);
    }
    List<String> javacOpts = new ArrayList<>();
    List<String> sources = new ArrayList<>();
    for (String arg : argv) {
        // TODO(cushon): is there a better way to categorize javacopts?
        if (!arg.startsWith("-") && arg.endsWith(".java")) {
            sources.add(arg);
        } else {
            javacOpts.add(arg);
        }
    }
    StandardJavaFileManager fileManager = new MaskedFileManager();
    return run(javacOpts.toArray(new String[0]), fileManager, ImmutableList.copyOf(fileManager.getJavaFileObjectsFromStrings(sources)), /* processors= */
    null);
}
Also used : MaskedFileManager(com.google.errorprone.MaskedClassLoader.MaskedFileManager) IOError(java.io.IOError) ArrayList(java.util.ArrayList) StandardJavaFileManager(javax.tools.StandardJavaFileManager) IOException(java.io.IOException)

Example 55 with IOError

use of java.io.IOError in project error-prone by google.

the class ErrorProneInMemoryFileManager method forResource.

/**
 * Loads a resource of the provided class into a {@link JavaFileObject}.
 */
public JavaFileObject forResource(Class<?> clazz, String fileName) {
    Path path = fileSystem.getPath("/", clazz.getPackage().getName().replace('.', '/'), fileName);
    try (InputStream is = findResource(clazz, fileName)) {
        Files.createDirectories(path.getParent());
        Files.copy(is, path);
    } catch (IOException e) {
        throw new IOError(e);
    }
    return Iterables.getOnlyElement(getJavaFileObjects(path));
}
Also used : Path(java.nio.file.Path) IOError(java.io.IOError) InputStream(java.io.InputStream) IOException(java.io.IOException)

Aggregations

IOError (java.io.IOError)78 IOException (java.io.IOException)58 File (java.io.File)11 ArrayList (java.util.ArrayList)8 Path (java.nio.file.Path)5 Status (ch.qos.logback.core.status.Status)4 BufferedReader (java.io.BufferedReader)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Console (java.io.Console)4 DataInputStream (java.io.DataInputStream)4 IPartitioner (org.apache.cassandra.dht.IPartitioner)4 FastByteArrayInputStream (org.apache.cassandra.io.util.FastByteArrayInputStream)4 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 ByteBuffer (java.nio.ByteBuffer)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 QueryPath (org.apache.cassandra.db.filter.QueryPath)3 CorruptSSTableException (org.apache.cassandra.io.sstable.CorruptSSTableException)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)3