Example usage for java.io IOError IOError

List of usage examples for java.io IOError IOError

Introduction

In this page you can find the example usage for java.io IOError IOError.

Prototype

public IOError(Throwable cause) 

Source Link

Document

Constructs a new instance of IOError with the specified cause.

Usage

From source file:org.adridadou.ethereum.values.SoliditySource.java

public static SoliditySource from(File file) {
    try {//from  w ww . j av  a2  s  . c  o  m
        return from(new FileInputStream(file));
    } catch (IOException e) {
        throw new IOError(e);
    }
}

From source file:org.adridadou.ethereum.values.SoliditySource.java

public static SoliditySource from(InputStream file) {
    try {//  ww w.jav  a  2 s. co  m
        return new SoliditySource(IOUtils.toString(file, EthereumFacade.CHARSET));
    } catch (IOException e) {
        throw new IOError(e);
    }
}

From source file:se.lth.cs.nlp.wikiforia.App.java

/**
 * Application entrypoint//from   w w w  .  j a  v  a  2s  . c o  m
 * @param args input arguments
 */
public static void main(String[] args) {
    Logger logger = LoggerFactory.getLogger(App.class);

    logger.info("Wikiforia v1.1.1 by Marcus Klang");

    Options options = new Options();
    options.addOption(index);
    options.addOption(pages);
    options.addOption(threads);
    options.addOption(batch);
    options.addOption(output);
    options.addOption(lang);
    options.addOption(hadoop);
    options.addOption(gzip);
    options.addOption(filterNs);

    CommandLineParser parser = new PosixParser();
    try {
        CommandLine cmdline = parser.parse(options, args);

        File indexPath = null, pagesPath, outputPath;
        int batchsize = 100;
        int numThreads = Runtime.getRuntime().availableProcessors();

        //Read batch size
        if (cmdline.hasOption(batch.getOpt())) {
            batchsize = Integer.parseInt(cmdline.getOptionValue(batch.getOpt()));
        }

        //Read num threads
        if (cmdline.hasOption(threads.getOpt())) {
            numThreads = Integer.parseInt(cmdline.getOptionValue(threads.getOpt()));
        }

        //Read required paths
        pagesPath = new File(cmdline.getOptionValue(pages.getOpt()));
        outputPath = new File(cmdline.getOptionValue(output.getOpt()));

        //Create output directories if they do not exist
        if (!outputPath.getParentFile().getAbsoluteFile().exists()) {
            if (!outputPath.getParentFile().getAbsoluteFile().mkdirs()) {
                throw new IOError(new IOException(
                        "Failed to create directories for " + outputPath.getParentFile().getAbsolutePath()));
            }
        }

        //To to automatically select an index file if it does not exits
        if (!cmdline.hasOption(index.getOpt())) {
            //try to automatically identify if there is an index file
            if (pagesPath.getAbsolutePath().toLowerCase().endsWith("-multistream.xml.bz2")) {
                int pos = pagesPath.getAbsolutePath().lastIndexOf("-multistream.xml.bz2");
                indexPath = new File(
                        pagesPath.getAbsolutePath().substring(0, pos) + "-multistream-index.txt.bz2");
                if (!indexPath.exists())
                    indexPath = null;
            }
        } else {
            indexPath = new File(cmdline.getOptionValue(index.getOpt()));
        }

        //Validation
        if (!pagesPath.exists()) {
            logger.error("pages with absolute filepath {} could not be found.", pagesPath.getAbsolutePath());
            return;
        }

        if (indexPath != null && !indexPath.exists()) {
            logger.error("Could not find index file {}.", indexPath.getAbsolutePath());
            logger.error("Skipping index and continuing with singlestream parsing (no threaded decompression)");
            indexPath = null;
        }

        String langId;
        if (cmdline.hasOption(lang.getOpt())) {
            langId = cmdline.getOptionValue(lang.getOpt());
        } else {
            Pattern langmatcher = Pattern.compile("([a-z]{2})wiki-");
            Matcher matcher = langmatcher.matcher(pagesPath.getName());
            if (matcher.find()) {
                langId = matcher.group(1).toLowerCase();
            } else {
                logger.error("Could not find a suitable language, will default to English");
                langId = "en";
            }
        }

        ArrayList<Filter<WikipediaPage>> filters = new ArrayList<Filter<WikipediaPage>>();
        if (cmdline.hasOption(filterNs.getOpt())) {
            String optionValue = cmdline.getOptionValue(filterNs.getOpt());
            final TreeSet<Integer> ns = new TreeSet<Integer>();
            for (String s : optionValue.split(",")) {
                ns.add(Integer.parseInt(s));
            }

            if (ns.size() > 0) {
                filters.add(new Filter<WikipediaPage>() {
                    @Override
                    protected boolean accept(WikipediaPage item) {
                        return ns.contains(item.getNamespace());
                    }

                    @Override
                    public String toString() {
                        return String.format("Namespace filter { namespaces: %s }", StringUtils.join(ns, ","));
                    }
                });
            }
        }

        TemplateConfig config;
        if (langId.equals("sv")) {
            config = new SwedishConfig();
        } else if (langId.equals("en")) {
            config = new EnglishConfig();
        } else {
            config = new EnglishConfig();
            logger.error(
                    "language {} is not yet supported and will be defaulted to a English setting for Sweble.",
                    langId);
            langId = "en";
        }

        if (cmdline.hasOption(hadoop.getOpt())) {
            if (outputPath.exists()) {
                logger.error("The target location already exists, please remove before using the tool!");
                System.exit(1);
            } else {
                int splitsize = 64000000;
                if (cmdline.hasOption(App.splitsize.getOpt())) {
                    splitsize = Integer.parseInt(cmdline.getOptionValue(App.splitsize.getOpt()));
                }

                hadoopConvert(config, indexPath, pagesPath, outputPath, numThreads, batchsize, splitsize,
                        cmdline.hasOption(gzip.getOpt()), filters);
            }
        } else {
            convert(config, indexPath, pagesPath, outputPath, numThreads, batchsize, filters);
        }

    } catch (ParseException e) {
        System.out.println(e.getMessage());
        HelpFormatter writer = new HelpFormatter();
        writer.printHelp("wikiforia", options);
    }
}

From source file:org.kiji.examples.phonebook.util.ConsolePrompt.java

/** Initialize a ConsolePrompt instance. */
public ConsolePrompt() {
    try {// w  w  w . j  a  v a  2  s  .co  m
        mConsoleReader = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
    } catch (UnsupportedEncodingException uee) {
        // UTF-8 is specified as supported everywhere on Java; should not get here.
        throw new IOError(uee);
    }
}

From source file:com.netflix.aegisthus.io.sstable.IndexDatabaseScanner.java

@Override
public boolean hasNext() {
    try {//from   w  w  w  .j  av a  2  s  .co  m
        return input.available() != 0;
    } catch (IOException e) {
        throw new IOError(e);
    }
}

From source file:org.kiji.examples.phonebook.util.ConsolePrompt.java

/**
 * Display a prompt and then wait for the user to respond with input.
 *
 * @param prompt the prompt string to deliver.
 * @return the user's response.//from ww w  .  j a v  a2  s  .c om
 * @throws IOError if there was an error reading from the console.
 */
public String readLine(String prompt) {
    System.out.print(prompt);

    try {
        return mConsoleReader.readLine();
    } catch (IOException ioe) {
        throw new IOError(ioe);
    }
}

From source file:com.netflix.aegisthus.io.sstable.IndexDatabaseScanner.java

@Override
@Nonnull/* w ww.jav a  2  s  . c  o m*/
public OffsetInfo next() {
    try {
        long indexOffset = countingInputStream.getByteCount();
        int keysize = input.readUnsignedShort();
        input.skipBytes(keysize);
        Long dataOffset = input.readLong();
        skipPromotedIndexes();
        return new OffsetInfo(dataOffset, indexOffset);
    } catch (IOException e) {
        throw new IOError(e);
    }
}

From source file:nlp.mediawiki.parser.SinglestreamXmlDumpParser.java

/**
 * File constructor with batchsize/*  w w w . j  a v  a 2  s  . co  m*/
 * @param path file to read from
 * @param batchsize the size of a batch
 */
public SinglestreamXmlDumpParser(File path, int batchsize) {
    this.pageInput = path;
    this.batchsize = batchsize;
    try {
        if (path.getAbsolutePath().toLowerCase().endsWith(".bz2")) {
            this.input = new BZip2CompressorInputStream(new FileInputStream(path), true);
        } else {
            this.input = new FileInputStream(path);
        }
    } catch (IOException e) {
        throw new IOError(e);
    }

    parser = new XmlDumpParser(input);

}

From source file:org.apache.cassandra.streaming.StreamOut.java

/**
 * Split out files for all tables on disk locally for each range and then stream them to the target endpoint.
*//*w w w .  j  a  va 2  s  .c o  m*/
public static void transferRanges(InetAddress target, String tableName, Collection<Range> ranges,
        Runnable callback, OperationType type) {
    assert ranges.size() > 0;

    // this is so that this target shows up as a destination while anticompaction is happening.
    StreamOutSession session = StreamOutSession.create(tableName, target, callback);

    logger.info("Beginning transfer to {}", target);
    logger.debug("Ranges are {}", StringUtils.join(ranges, ","));

    try {
        Table table = flushSSTable(tableName);
        // send the matching portion of every sstable in the keyspace
        transferSSTables(session, table.getAllSSTables(), ranges, type);
    } catch (IOException e) {
        throw new IOError(e);
    }
}

From source file:org.apache.cassandra.service.AbstractRowResolver.java

public void preprocess(Message message) {
    byte[] body = message.getMessageBody();
    ByteArrayInputStream bufIn = new ByteArrayInputStream(body);
    try {//  w w w . ja v a 2  s  .co  m
        ReadResponse result = ReadResponse.serializer().deserialize(new DataInputStream(bufIn),
                message.getVersion());
        if (logger.isDebugEnabled())
            logger.debug("Preprocessed {} response", result.isDigestQuery() ? "digest" : "data");
        replies.put(message, result);
    } catch (IOException e) {
        throw new IOError(e);
    }
}