Example usage for java.nio.file NoSuchFileException getMessage

List of usage examples for java.nio.file NoSuchFileException getMessage

Introduction

In this page you can find the example usage for java.nio.file NoSuchFileException getMessage.

Prototype

@Override
public String getMessage() 

Source Link

Document

Returns the detail message string.

Usage

From source file:com.arvato.thoroughly.util.CommonUtils.java

/**
 * @param path// w w w.  ja  v  a 2 s.c o  m
 * @return String
 */
public static String readFile(String path) {
    String content = null;
    try {
        File file = new File(path);
        content = FileUtils.readFileToString(file, "UTF-8");
    } catch (NoSuchFileException e) {
        LOGGER.error("File not found:" + e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.error("File read failed:" + e.getMessage(), e);
    }
    return content;
}

From source file:org.sakuli.utils.LoggerInitializer.java

protected String getConfigFileFromClasspath() {
    try {//w w w. j  a v  a  2  s .c  o m
        return ResourceHelper
                .getClasspathResource(getClass(), "/" + LOG_CONFIG_FILE_NAME,
                        "unexpected error by resolving the '" + LOG_CONFIG_FILE_NAME
                                + "' from classpath, now try to resolve it from the include folder.")
                .toAbsolutePath().toString();
    } catch (NoSuchFileException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}

From source file:com.ethercamp.harmony.service.wallet.FileSystemWalletStore.java

public List<WalletAddressItem> fromStore() {
    final ObjectMapper mapper = new ObjectMapper();

    try {// w ww . j  a va2 s.c  o m
        final File file = getKeyStoreLocation().resolve(FILE_NAME).toFile();

        final String content = Files.readAllLines(file.toPath()).stream().collect(Collectors.joining(""));

        return mapper.readValue(content, new TypeReference<List<WalletAddressItem>>() {
        });
    } catch (NoSuchFileException e) {
        return Collections.EMPTY_LIST;
    } catch (IOException e) {
        throw new RuntimeException("Problem loading data. Message: " + e.getMessage(), e);
    }
}

From source file:com.ericsson.eiffel.remrem.publish.cli.CLI.java

/**
 * Handle event from file// w w  w .  j a  va 2 s .c o m
 * @param filePath the path of the file where the messages reside
 */
public void handleContentFile(String filePath) {
    try {
        byte[] fileBytes = Files.readAllBytes(Paths.get(filePath));
        String fileContent = new String(fileBytes);
        handleContent(fileContent);
    } catch (final NoSuchFileException e) {
        log.debug("NoSuchFileException", e);
        System.err.println("File not found: " + e.getMessage());
        CliOptions.exit(CLIExitCodes.HANDLE_CONTENT_FILE_NOT_FOUND_FAILED);
    } catch (Exception e) {
        System.err.println("Could not read content file. Cause: " + e.getMessage());
        CliOptions.exit(CLIExitCodes.HANDLE_CONTENT_FILE_COULD_NOT_READ_FAILED);
    }
}

From source file:burstcoin.jminer.core.reader.task.ReaderLoadDriveTask.java

private boolean load(PlotFile plotFile) {
    try (SeekableByteChannel sbc = Files.newByteChannel(plotFile.getFilePath(),
            EnumSet.of(StandardOpenOption.READ))) {
        long currentScoopPosition = scoopNumber * plotFile.getStaggeramt() * MiningPlot.SCOOP_SIZE;

        long partSize = plotFile.getStaggeramt() / plotFile.getNumberOfParts();
        ByteBuffer partBuffer = ByteBuffer.allocate((int) (partSize * MiningPlot.SCOOP_SIZE));
        // optimized plotFiles only have one chunk!
        for (int chunkNumber = 0; chunkNumber < plotFile.getNumberOfChunks(); chunkNumber++) {
            long currentChunkPosition = chunkNumber * plotFile.getStaggeramt() * MiningPlot.PLOT_SIZE;
            sbc.position(currentScoopPosition + currentChunkPosition);
            for (int partNumber = 0; partNumber < plotFile.getNumberOfParts(); partNumber++) {
                sbc.read(partBuffer);//from  ww  w  . j av  a 2s  .  co m

                if (Reader.blockNumber != blockNumber) {
                    LOG.trace("loadDriveThread stopped!");
                    partBuffer.clear();
                    sbc.close();
                    return true;
                } else {
                    long chunkPartStartNonce = plotFile.getStartnonce()
                            + (chunkNumber * plotFile.getStaggeramt()) + (partNumber * partSize);
                    final byte[] scoops = partBuffer.array();
                    publisher.publishEvent(new ReaderLoadedPartEvent(blockNumber, scoops, chunkPartStartNonce));
                }
                partBuffer.clear();
            }
        }
        sbc.close();
    } catch (NoSuchFileException exception) {
        LOG.error("File not found ... please restart to rescan plot-files, maybe set rescan to 'true': "
                + exception.getMessage());
    } catch (ClosedByInterruptException e) {
        // we reach this, if we do not wait for task on shutdown - ByteChannel closed by thread interruption
        LOG.trace("reader stopped cause of new block ...");
    } catch (IOException e) {
        LOG.error("IOException: " + e.getMessage());
    }
    return false;
}

From source file:grakn.core.console.ConsoleSession.java

void run() throws IOException, InterruptedException {
    consoleReader.setExpandEvents(false); // Disable JLine feature when seeing a '!'
    consoleReader.print(COPYRIGHT);// w ww. j  a  va  2s  .  com

    tx = session.transaction().write();
    String input;

    while ((input = consoleReader.readLine()) != null && !terminated.get()) {
        if (input.equals(EDITOR)) {
            executeQuery(openTextEditor());

        } else if (input.startsWith(LOAD + ' ')) {
            try {
                input = readFile(Paths.get(unescapeJava(input.substring(LOAD.length() + 1))));
                executeQuery(input);
            } catch (NoSuchFileException e) {
                System.err.println("File not found: " + e.getMessage());
            }
        } else if (input.equals(COMMIT)) {
            commit();

        } else if (input.equals(ROLLBACK)) {
            rollback();

        } else if (input.equals(CLEAN)) {
            clean();
            consoleReader.flush();
            return;

        } else if (input.equals(CLEAR)) {
            consoleReader.clearScreen();

        } else if (input.equals(EXIT)) {
            consoleReader.flush();
            return;

        } else if (!input.isEmpty()) {
            executeQuery(input);

        } // We ignore empty commands
    }
}

From source file:lu.list.itis.dkd.aig.template.TemplateService.java

protected Response getTemplate(final ServletContext context, final String name, final String folder) {
    try {// w  w w  .  ja  v a2  s . c  o m
        return Response.status(200).type(MediaType.TEXT_XML)
                .entity(TemplateManager.fetch(context, name, folder)).build();
    } catch (final NoSuchFileException e) {
        return Response.status(404).type(MediaType.TEXT_PLAIN).entity("No template with given name was found!") //$NON-NLS-1$
                .build();
    } catch (final IOException e) {
        Logger.getLogger(TemplateService.class.getSimpleName()).log(Level.SEVERE, e.getMessage(), e);
        return Response.serverError()
                .entity("Error while attempting to retrieve the template!\n" + ExceptionUtils.getStackTrace(e)) //$NON-NLS-1$
                .build();
    }
}

From source file:org.lizardirc.beancounter.Beancounter.java

public static void main(String[] args) {
    Path configurationFile = Paths.get("config.props");

    // Expect 0 or 1 arguments.  If present, argument is the location of the startup configuration file to use
    if (args.length > 1) {
        System.err.println("Error: Too many arguments.");
        System.err.println("Usage: java -jar beancounter.jar [configurationFile]");
        System.err.println("Where: configurationFile is the optional path to a startup configuration file.");
        System.exit(2);//from   w w  w .  jav  a 2  s  .c  o m
    } else if (args.length == 1) {
        configurationFile = Paths.get(args[0]);
    }

    System.out.println("Reading configuration file " + configurationFile + "....");
    Properties properties = new Properties();
    try (InputStream is = Files.newInputStream(configurationFile)) {
        properties.load(is);
    } catch (NoSuchFileException e) {
        System.err.println("Error: Could not find configuration file " + configurationFile
                + " (NoSuchFileException). A default configuration file has been created for you at that location.");
        System.err.println(
                "The bot will now terminate to give you an opportunity to edit the configuration file.");
        try (InputStream defaultConfig = Beancounter.class.getResourceAsStream("/default.config.props")) {
            Files.copy(defaultConfig, configurationFile);
        } catch (IOException e1) {
            System.err.println("Error while writing out default configuration file.  Stack trace follows.");
            e1.printStackTrace();
        }
        System.exit(3);
    } catch (IOException e) {
        System.err.println("Error: Could not read configuration file " + configurationFile
                + ".  A stack trace follows.  The bot will now terminate.");
        e.printStackTrace();
        System.exit(3);
    }

    System.out.println("Creating bot....");
    Beancounter beancounter = new Beancounter(properties);

    System.out.println("Launching bot....");
    try {
        beancounter.run();
    } catch (Exception e) {
        System.err.println("Exception occurred launching bot: " + e.getMessage());
        System.err.println("Stack trace follows:");
        e.printStackTrace();
    }
}