Example usage for com.google.common.io Resources toString

List of usage examples for com.google.common.io Resources toString

Introduction

In this page you can find the example usage for com.google.common.io Resources toString.

Prototype

public static String toString(URL url, Charset charset) throws IOException 

Source Link

Document

Reads all characters from a URL into a String , using the given character set.

Usage

From source file:se.softhouse.common.testlib.ResourceLoader.java

/**
 * Loads a file and reads it as an {@link com.google.common.base.Charsets#UTF_8 UTF_8} file.
 * {@code resourceName} must start with a "/"
 * /*from   w  w  w.ja va 2s .c  o m*/
 * @return the file as a string
 * @throws IllegalArgumentException if {@code resourceName} can't be found/loaded
 */
public static String get(String resourceName) {
    URL resourcePath = Resources.getResource(ResourceLoader.class, resourceName);
    String fileContent = null;
    try {
        fileContent = Resources.toString(resourcePath, UTF_8);
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to load: " + resourcePath, e);
    }
    return fileContent;
}

From source file:google.registry.util.ResourceUtils.java

private static String resourceToString(URL url) {
    try {//  w  w  w  .java2s.c o m
        return Resources.toString(url, UTF_8);
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to load resource: " + url, e);
    }
}

From source file:org.guldenj.tools.WalletTool.java

public static void main(String[] args) throws Exception {
    OptionParser parser = new OptionParser();
    parser.accepts("help");
    parser.accepts("force");
    parser.accepts("debuglog");
    OptionSpec<String> walletFileName = parser.accepts("wallet").withRequiredArg().defaultsTo("wallet");
    seedFlag = parser.accepts("seed").withRequiredArg();
    watchFlag = parser.accepts("watchkey").withRequiredArg();
    OptionSpec<NetworkEnum> netFlag = parser.accepts("net").withRequiredArg().ofType(NetworkEnum.class)
            .defaultsTo(NetworkEnum.MAIN);
    dateFlag = parser.accepts("date").withRequiredArg().ofType(Date.class)
            .withValuesConvertedBy(DateConverter.datePattern("yyyy/MM/dd"));
    OptionSpec<WaitForEnum> waitForFlag = parser.accepts("waitfor").withRequiredArg().ofType(WaitForEnum.class);
    OptionSpec<ValidationMode> modeFlag = parser.accepts("mode").withRequiredArg().ofType(ValidationMode.class)
            .defaultsTo(ValidationMode.SPV);
    OptionSpec<String> chainFlag = parser.accepts("chain").withRequiredArg();
    // For addkey/delkey.
    parser.accepts("pubkey").withRequiredArg();
    parser.accepts("privkey").withRequiredArg();
    parser.accepts("addr").withRequiredArg();
    parser.accepts("peers").withRequiredArg();
    xpubkeysFlag = parser.accepts("xpubkeys").withRequiredArg();
    OptionSpec<String> outputFlag = parser.accepts("output").withRequiredArg();
    parser.accepts("value").withRequiredArg();
    OptionSpec<String> feePerKbOption = parser.accepts("fee-per-kb").withRequiredArg();
    unixtimeFlag = parser.accepts("unixtime").withRequiredArg().ofType(Long.class);
    OptionSpec<String> conditionFlag = parser.accepts("condition").withRequiredArg();
    parser.accepts("locktime").withRequiredArg();
    parser.accepts("allow-unconfirmed");
    parser.accepts("offline");
    parser.accepts("ignore-mandatory-extensions");
    lookaheadSize = parser.accepts("lookahead-size").withRequiredArg().ofType(Integer.class);
    OptionSpec<String> passwordFlag = parser.accepts("password").withRequiredArg();
    OptionSpec<String> paymentRequestLocation = parser.accepts("payment-request").withRequiredArg();
    parser.accepts("no-pki");
    parser.accepts("tor");
    parser.accepts("dump-privkeys");
    OptionSpec<String> refundFlag = parser.accepts("refund-to").withRequiredArg();
    OptionSpec<String> txHashFlag = parser.accepts("txhash").withRequiredArg();
    options = parser.parse(args);/*w  ww  . ja v  a  2s . c om*/

    if (args.length == 0 || options.has("help") || options.nonOptionArguments().size() < 1
            || options.nonOptionArguments().contains("help")) {
        System.out.println(
                Resources.toString(WalletTool.class.getResource("wallet-tool-help.txt"), Charsets.UTF_8));
        return;
    }

    ActionEnum action;
    try {
        String actionStr = options.nonOptionArguments().get(0);
        actionStr = actionStr.toUpperCase().replace("-", "_");
        action = ActionEnum.valueOf(actionStr);
    } catch (IllegalArgumentException e) {
        System.err.println("Could not understand action name " + options.nonOptionArguments().get(0));
        return;
    }

    if (options.has("debuglog")) {
        BriefLogFormatter.init();
        log.info("Starting up ...");
    } else {
        // Disable logspam unless there is a flag.
        java.util.logging.Logger logger = LogManager.getLogManager().getLogger("");
        logger.setLevel(Level.SEVERE);
    }
    switch (netFlag.value(options)) {
    case MAIN:
    case PROD:
        params = MainNetParams.get();
        chainFileName = new File("mainnet.chain");
        break;
    case TEST:
        params = TestNet3Params.get();
        chainFileName = new File("testnet.chain");
        break;
    case REGTEST:
        params = RegTestParams.get();
        chainFileName = new File("regtest.chain");
        break;
    default:
        throw new RuntimeException("Unreachable.");
    }
    Context.propagate(new Context(params));

    mode = modeFlag.value(options);

    // Allow the user to override the name of the chain used.
    if (options.has(chainFlag)) {
        chainFileName = new File(chainFlag.value(options));
    }

    if (options.has("condition")) {
        condition = new Condition(conditionFlag.value(options));
    }

    if (options.has(passwordFlag)) {
        password = passwordFlag.value(options);
    }

    walletFile = new File(walletFileName.value(options));
    if (action == ActionEnum.CREATE) {
        createWallet(options, params, walletFile);
        return; // We're done.
    }
    if (!walletFile.exists()) {
        System.err.println("Specified wallet file " + walletFile + " does not exist. Try wallet-tool --wallet="
                + walletFile + " create");
        return;
    }

    if (action == ActionEnum.RAW_DUMP) {
        // Just parse the protobuf and print, then bail out. Don't try and do a real deserialization. This is
        // useful mostly for investigating corrupted wallets.
        FileInputStream stream = new FileInputStream(walletFile);
        try {
            Protos.Wallet proto = WalletProtobufSerializer.parseToProto(stream);
            proto = attemptHexConversion(proto);
            System.out.println(proto.toString());
            return;
        } finally {
            stream.close();
        }
    }

    InputStream walletInputStream = null;
    try {
        boolean forceReset = action == ActionEnum.RESET || (action == ActionEnum.SYNC && options.has("force"));
        WalletProtobufSerializer loader = new WalletProtobufSerializer();
        if (options.has("ignore-mandatory-extensions"))
            loader.setRequireMandatoryExtensions(false);
        walletInputStream = new BufferedInputStream(new FileInputStream(walletFile));
        wallet = loader.readWallet(walletInputStream, forceReset, (WalletExtension[]) (null));
        if (!wallet.getParams().equals(params)) {
            System.err.println("Wallet does not match requested network parameters: "
                    + wallet.getParams().getId() + " vs " + params.getId());
            return;
        }
    } catch (Exception e) {
        System.err.println("Failed to load wallet '" + walletFile + "': " + e.getMessage());
        e.printStackTrace();
        return;
    } finally {
        if (walletInputStream != null) {
            walletInputStream.close();
        }
    }

    // What should we do?
    switch (action) {
    case DUMP:
        dumpWallet();
        break;
    case ADD_KEY:
        addKey();
        break;
    case ADD_ADDR:
        addAddr();
        break;
    case DELETE_KEY:
        deleteKey();
        break;
    case CURRENT_RECEIVE_ADDR:
        currentReceiveAddr();
        break;
    case RESET:
        reset();
        break;
    case SYNC:
        syncChain();
        break;
    case SEND:
        if (options.has(paymentRequestLocation) && options.has(outputFlag)) {
            System.err.println("--payment-request and --output cannot be used together.");
            return;
        } else if (options.has(outputFlag)) {
            Coin feePerKb = null;
            if (options.has(feePerKbOption))
                feePerKb = parseCoin((String) options.valueOf(feePerKbOption));
            String lockTime = null;
            if (options.has("locktime")) {
                lockTime = (String) options.valueOf("locktime");
            }
            boolean allowUnconfirmed = options.has("allow-unconfirmed");
            send(outputFlag.values(options), feePerKb, lockTime, allowUnconfirmed);
        } else if (options.has(paymentRequestLocation)) {
            sendPaymentRequest(paymentRequestLocation.value(options), !options.has("no-pki"));
        } else {
            System.err.println("You must specify a --payment-request or at least one --output=addr:value.");
            return;
        }
        break;
    case SEND_CLTVPAYMENTCHANNEL: {
        if (!options.has(outputFlag)) {
            System.err.println("You must specify a --output=addr:value");
            return;
        }
        Coin feePerKb = null;
        if (options.has(feePerKbOption))
            feePerKb = parseCoin((String) options.valueOf(feePerKbOption));
        if (!options.has("locktime")) {
            System.err.println("You must specify a --locktime");
            return;
        }
        String lockTime = (String) options.valueOf("locktime");
        boolean allowUnconfirmed = options.has("allow-unconfirmed");
        if (!options.has(refundFlag)) {
            System.err.println("You must specify an address to refund money to after expiry: --refund-to=addr");
            return;
        }
        sendCLTVPaymentChannel(refundFlag.value(options), outputFlag.value(options), feePerKb, lockTime,
                allowUnconfirmed);
    }
        break;
    case SETTLE_CLTVPAYMENTCHANNEL: {
        if (!options.has(outputFlag)) {
            System.err.println("You must specify a --output=addr:value");
            return;
        }
        Coin feePerKb = null;
        if (options.has(feePerKbOption))
            feePerKb = parseCoin((String) options.valueOf(feePerKbOption));
        boolean allowUnconfirmed = options.has("allow-unconfirmed");
        if (!options.has(txHashFlag)) {
            System.err.println("You must specify the transaction to spend: --txhash=tx-hash");
            return;
        }
        settleCLTVPaymentChannel(txHashFlag.value(options), outputFlag.value(options), feePerKb,
                allowUnconfirmed);
    }
        break;
    case REFUND_CLTVPAYMENTCHANNEL: {
        if (!options.has(outputFlag)) {
            System.err.println("You must specify a --output=addr:value");
            return;
        }
        Coin feePerKb = null;
        if (options.has(feePerKbOption))
            feePerKb = parseCoin((String) options.valueOf(feePerKbOption));
        boolean allowUnconfirmed = options.has("allow-unconfirmed");
        if (!options.has(txHashFlag)) {
            System.err.println("You must specify the transaction to spend: --txhash=tx-hash");
            return;
        }
        refundCLTVPaymentChannel(txHashFlag.value(options), outputFlag.value(options), feePerKb,
                allowUnconfirmed);
    }
        break;
    case ENCRYPT:
        encrypt();
        break;
    case DECRYPT:
        decrypt();
        break;
    case MARRY:
        marry();
        break;
    case ROTATE:
        rotate();
        break;
    case SET_CREATION_TIME:
        setCreationTime();
        break;
    }

    if (!wallet.isConsistent()) {
        System.err.println("************** WALLET IS INCONSISTENT *****************");
        return;
    }

    saveWallet(walletFile);

    if (options.has(waitForFlag)) {
        WaitForEnum value;
        try {
            value = waitForFlag.value(options);
        } catch (Exception e) {
            System.err.println("Could not understand the --waitfor flag: Valid options are WALLET_TX, BLOCK, "
                    + "BALANCE and EVER");
            return;
        }
        wait(value);
        if (!wallet.isConsistent()) {
            System.err.println("************** WALLET IS INCONSISTENT *****************");
            return;
        }
        saveWallet(walletFile);
    }
    shutdown();
}

From source file:com.articulate.sigma.test.JsonReader.java

public static <T> Collection<T> transform(String resourcePath, Function<JSONObject, T> transformer) {
    Collection<T> result = Lists.newArrayList();

    URL jsonTests = Resources.getResource(resourcePath);
    System.out.println("Reading JSON file: " + jsonTests.getPath());
    JSONParser parser = new JSONParser();
    try {//from  www. j  a v a 2s .co m
        Object obj = parser.parse(Resources.toString(jsonTests, Charsets.UTF_8));
        JSONArray jsonObject = (JSONArray) obj;
        ListIterator<JSONObject> li = jsonObject.listIterator();
        while (li.hasNext()) {
            JSONObject jo = li.next();
            result.add(transformer.apply(jo));
        }
    } catch (Exception e) {
        System.out.println("Parse exception reading: " + resourcePath);
        System.out.println(e.getMessage());
        e.printStackTrace();
        throw new RuntimeException("Parse exception reading: " + resourcePath);
    }
    return result;
}

From source file:org.immutables.value.processor.meta.ExtensionLoader.java

static ImmutableSet<String> findExtensions(String resource) {
    List<String> annotations = Lists.newArrayList();

    ClassLoader classLoader = ExtensionLoader.class.getClassLoader();
    try {//from w  w  w.j a v  a  2  s .c  om
        Enumeration<URL> resources = classLoader.getResources(resource);
        while (resources.hasMoreElements()) {
            URL nextElement = resources.nextElement();
            String lines = Resources.toString(nextElement, StandardCharsets.UTF_8);
            annotations.addAll(RESOURCE_SPLITTER.splitToList(lines));
        }
    } catch (IOException cannotReadFromClasspath) {
        // we ignore this as we did or best effort
        // and there are no plans to halt whole compilation
    }
    return FluentIterable.from(annotations).toSet();
}

From source file:uk.os.vt.demo.Schemas.java

private static Metadata inflate(String resource) {
    final URL url = Resources.getResource(resource);
    Metadata inflated;/*ww  w .j a va  2s  . c o m*/
    try {
        String schemaString = Resources.toString(url, Charsets.UTF_8);
        inflated = new Metadata.Builder().setTileJson(new JSONObject(schemaString)).build();
    } catch (final IOException ex) {
        LOG.error("problem inflating local schema", ex);
        inflated = new Metadata.Builder().build();
    } catch (JSONException je) {
        LOG.error("problem inflating JSON", je);
        inflated = new Metadata.Builder().build();
    }
    return inflated;
}

From source file:com.axemblr.provisionr.core.Mustache.java

public static String toString(URL resource, Map<String, ?> scopes) throws IOException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(outputStream);

    String content = Resources.toString(resource, Charsets.UTF_8);

    MustacheFactory factory = new DefaultMustacheFactory();
    factory.compile(new StringReader(content), resource.toString()).execute(writer, scopes);

    writer.close();/*from  w ww . ja  v a2s.  co m*/
    return outputStream.toString();
}

From source file:org.cloudifysource.cosmo.orchestrator.workflow.RuoteWorkflow.java

public static RuoteWorkflow createFromResource(String resourceName, RuoteRuntime runtime) {
    Preconditions.checkNotNull(resourceName);
    Preconditions.checkNotNull(runtime);
    try {//  w  ww.  ja v a2 s .  c  o  m
        final URL url = Resources.getResource(resourceName);
        final String workflow = Resources.toString(url, Charsets.UTF_8);
        return new RuoteWorkflow(workflow, runtime);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.bitcoinj.tools.WalletTool.java

public static void main(String[] args) throws Exception {
    OptionParser parser = new OptionParser();
    parser.accepts("help");
    parser.accepts("force");
    parser.accepts("debuglog");
    OptionSpec<String> walletFileName = parser.accepts("wallet").withRequiredArg().defaultsTo("wallet");
    seedFlag = parser.accepts("seed").withRequiredArg();
    watchFlag = parser.accepts("watchkey").withRequiredArg();
    OptionSpec<NetworkEnum> netFlag = parser.accepts("net").withRequiredArg().ofType(NetworkEnum.class)
            .defaultsTo(NetworkEnum.MAIN);
    dateFlag = parser.accepts("date").withRequiredArg().ofType(Date.class)
            .withValuesConvertedBy(DateConverter.datePattern("yyyy/MM/dd"));
    OptionSpec<WaitForEnum> waitForFlag = parser.accepts("waitfor").withRequiredArg().ofType(WaitForEnum.class);
    OptionSpec<ValidationMode> modeFlag = parser.accepts("mode").withRequiredArg().ofType(ValidationMode.class)
            .defaultsTo(ValidationMode.SPV);
    OptionSpec<String> chainFlag = parser.accepts("chain").withRequiredArg();
    // For addkey/delkey.
    parser.accepts("pubkey").withRequiredArg();
    parser.accepts("privkey").withRequiredArg();
    parser.accepts("addr").withRequiredArg();
    parser.accepts("peers").withRequiredArg();
    xpubkeysFlag = parser.accepts("xpubkeys").withRequiredArg();
    OptionSpec<String> outputFlag = parser.accepts("output").withRequiredArg();
    parser.accepts("value").withRequiredArg();
    OptionSpec<String> feePerKbOption = parser.accepts("fee-per-kb").withRequiredArg();
    OptionSpec<String> feeSatPerByteOption = parser.accepts("fee-sat-per-byte").withRequiredArg();
    unixtimeFlag = parser.accepts("unixtime").withRequiredArg().ofType(Long.class);
    OptionSpec<String> conditionFlag = parser.accepts("condition").withRequiredArg();
    parser.accepts("locktime").withRequiredArg();
    parser.accepts("allow-unconfirmed");
    parser.accepts("offline");
    parser.accepts("ignore-mandatory-extensions");
    lookaheadSize = parser.accepts("lookahead-size").withRequiredArg().ofType(Integer.class);
    OptionSpec<String> passwordFlag = parser.accepts("password").withRequiredArg();
    OptionSpec<String> paymentRequestLocation = parser.accepts("payment-request").withRequiredArg();
    parser.accepts("no-pki");
    parser.accepts("dump-privkeys");
    OptionSpec<String> refundFlag = parser.accepts("refund-to").withRequiredArg();
    OptionSpec<String> txHashFlag = parser.accepts("txhash").withRequiredArg();
    options = parser.parse(args);//w ww  .ja va 2s . c  o m

    if (args.length == 0 || options.has("help") || options.nonOptionArguments().size() < 1
            || options.nonOptionArguments().contains("help")) {
        System.out.println(
                Resources.toString(WalletTool.class.getResource("wallet-tool-help.txt"), Charsets.UTF_8));
        return;
    }

    ActionEnum action;
    try {
        String actionStr = options.nonOptionArguments().get(0);
        actionStr = actionStr.toUpperCase().replace("-", "_");
        action = ActionEnum.valueOf(actionStr);
    } catch (IllegalArgumentException e) {
        System.err.println("Could not understand action name " + options.nonOptionArguments().get(0));
        return;
    }

    if (options.has("debuglog")) {
        BriefLogFormatter.init();
        log.info("Starting up ...");
    } else {
        // Disable logspam unless there is a flag.
        java.util.logging.Logger logger = LogManager.getLogManager().getLogger("");
        logger.setLevel(Level.SEVERE);
    }
    switch (netFlag.value(options)) {
    case MAIN:
    case PROD:
        params = MainNetParams.get();
        chainFileName = new File("mainnet.chain");
        break;
    case TEST:
        params = TestNet3Params.get();
        chainFileName = new File("testnet.chain");
        break;
    case REGTEST:
        params = RegTestParams.get();
        chainFileName = new File("regtest.chain");
        break;
    default:
        throw new RuntimeException("Unreachable.");
    }
    Context.propagate(new Context(params));

    mode = modeFlag.value(options);

    // Allow the user to override the name of the chain used.
    if (options.has(chainFlag)) {
        chainFileName = new File(chainFlag.value(options));
    }

    if (options.has("condition")) {
        condition = new Condition(conditionFlag.value(options));
    }

    if (options.has(passwordFlag)) {
        password = passwordFlag.value(options);
    }

    walletFile = new File(walletFileName.value(options));
    if (action == ActionEnum.CREATE) {
        createWallet(options, params, walletFile);
        return; // We're done.
    }
    if (!walletFile.exists()) {
        System.err.println("Specified wallet file " + walletFile + " does not exist. Try wallet-tool --wallet="
                + walletFile + " create");
        return;
    }

    if (action == ActionEnum.RAW_DUMP) {
        // Just parse the protobuf and print, then bail out. Don't try and do a real deserialization. This is
        // useful mostly for investigating corrupted wallets.
        FileInputStream stream = new FileInputStream(walletFile);
        try {
            Protos.Wallet proto = WalletProtobufSerializer.parseToProto(stream);
            proto = attemptHexConversion(proto);
            System.out.println(proto.toString());
            return;
        } finally {
            stream.close();
        }
    }

    InputStream walletInputStream = null;
    try {
        boolean forceReset = action == ActionEnum.RESET || (action == ActionEnum.SYNC && options.has("force"));
        WalletProtobufSerializer loader = new WalletProtobufSerializer();
        if (options.has("ignore-mandatory-extensions"))
            loader.setRequireMandatoryExtensions(false);
        walletInputStream = new BufferedInputStream(new FileInputStream(walletFile));
        wallet = loader.readWallet(walletInputStream, forceReset, (WalletExtension[]) (null));
        if (!wallet.getParams().equals(params)) {
            System.err.println("Wallet does not match requested network parameters: "
                    + wallet.getParams().getId() + " vs " + params.getId());
            return;
        }
    } catch (Exception e) {
        System.err.println("Failed to load wallet '" + walletFile + "': " + e.getMessage());
        e.printStackTrace();
        return;
    } finally {
        if (walletInputStream != null) {
            walletInputStream.close();
        }
    }

    // What should we do?
    switch (action) {
    case DUMP:
        dumpWallet();
        break;
    case ADD_KEY:
        addKey();
        break;
    case ADD_ADDR:
        addAddr();
        break;
    case DELETE_KEY:
        deleteKey();
        break;
    case CURRENT_RECEIVE_ADDR:
        currentReceiveAddr();
        break;
    case RESET:
        reset();
        break;
    case SYNC:
        syncChain();
        break;
    case SEND:
        if (options.has(paymentRequestLocation) && options.has(outputFlag)) {
            System.err.println("--payment-request and --output cannot be used together.");
            return;
        } else if (options.has(feePerKbOption) && options.has(feeSatPerByteOption)) {
            System.err.println("--fee-per-kb and --fee-sat-per-byte cannot be used together.");
            return;
        } else if (options.has(outputFlag)) {
            Coin feePerKb = null;
            if (options.has(feePerKbOption))
                feePerKb = parseCoin((String) options.valueOf(feePerKbOption));
            if (options.has(feeSatPerByteOption))
                feePerKb = Coin.valueOf(Long.parseLong(options.valueOf(feeSatPerByteOption)) * 1000);
            String lockTime = null;
            if (options.has("locktime")) {
                lockTime = (String) options.valueOf("locktime");
            }
            boolean allowUnconfirmed = options.has("allow-unconfirmed");
            send(outputFlag.values(options), feePerKb, lockTime, allowUnconfirmed);
        } else if (options.has(paymentRequestLocation)) {
            sendPaymentRequest(paymentRequestLocation.value(options), !options.has("no-pki"));
        } else {
            System.err.println("You must specify a --payment-request or at least one --output=addr:value.");
            return;
        }
        break;
    case SEND_CLTVPAYMENTCHANNEL: {
        if (options.has(feePerKbOption) && options.has(feeSatPerByteOption)) {
            System.err.println("--fee-per-kb and --fee-sat-per-byte cannot be used together.");
            return;
        }
        if (!options.has(outputFlag)) {
            System.err.println("You must specify a --output=addr:value");
            return;
        }
        Coin feePerKb = null;
        if (options.has(feePerKbOption))
            feePerKb = parseCoin((String) options.valueOf(feePerKbOption));
        if (options.has(feeSatPerByteOption))
            feePerKb = Coin.valueOf(Long.parseLong(options.valueOf(feeSatPerByteOption)) * 1000);
        if (!options.has("locktime")) {
            System.err.println("You must specify a --locktime");
            return;
        }
        String lockTime = (String) options.valueOf("locktime");
        boolean allowUnconfirmed = options.has("allow-unconfirmed");
        if (!options.has(refundFlag)) {
            System.err.println("You must specify an address to refund money to after expiry: --refund-to=addr");
            return;
        }
        sendCLTVPaymentChannel(refundFlag.value(options), outputFlag.value(options), feePerKb, lockTime,
                allowUnconfirmed);
    }
        break;
    case SETTLE_CLTVPAYMENTCHANNEL: {
        if (options.has(feePerKbOption) && options.has(feeSatPerByteOption)) {
            System.err.println("--fee-per-kb and --fee-sat-per-byte cannot be used together.");
            return;
        }
        if (!options.has(outputFlag)) {
            System.err.println("You must specify a --output=addr:value");
            return;
        }
        Coin feePerKb = null;
        if (options.has(feePerKbOption))
            feePerKb = parseCoin((String) options.valueOf(feePerKbOption));
        if (options.has(feeSatPerByteOption))
            feePerKb = Coin.valueOf(Long.parseLong(options.valueOf(feeSatPerByteOption)) * 1000);
        boolean allowUnconfirmed = options.has("allow-unconfirmed");
        if (!options.has(txHashFlag)) {
            System.err.println("You must specify the transaction to spend: --txhash=tx-hash");
            return;
        }
        settleCLTVPaymentChannel(txHashFlag.value(options), outputFlag.value(options), feePerKb,
                allowUnconfirmed);
    }
        break;
    case REFUND_CLTVPAYMENTCHANNEL: {
        if (options.has(feePerKbOption) && options.has(feeSatPerByteOption)) {
            System.err.println("--fee-per-kb and --fee-sat-per-byte cannot be used together.");
            return;
        }
        if (!options.has(outputFlag)) {
            System.err.println("You must specify a --output=addr:value");
            return;
        }
        Coin feePerKb = null;
        if (options.has(feePerKbOption))
            feePerKb = parseCoin((String) options.valueOf(feePerKbOption));
        if (options.has(feeSatPerByteOption))
            feePerKb = Coin.valueOf(Long.parseLong(options.valueOf(feeSatPerByteOption)) * 1000);
        boolean allowUnconfirmed = options.has("allow-unconfirmed");
        if (!options.has(txHashFlag)) {
            System.err.println("You must specify the transaction to spend: --txhash=tx-hash");
            return;
        }
        refundCLTVPaymentChannel(txHashFlag.value(options), outputFlag.value(options), feePerKb,
                allowUnconfirmed);
    }
        break;
    case ENCRYPT:
        encrypt();
        break;
    case DECRYPT:
        decrypt();
        break;
    case MARRY:
        marry();
        break;
    case ROTATE:
        rotate();
        break;
    case SET_CREATION_TIME:
        setCreationTime();
        break;
    }

    if (!wallet.isConsistent()) {
        System.err.println("************** WALLET IS INCONSISTENT *****************");
        return;
    }

    saveWallet(walletFile);

    if (options.has(waitForFlag)) {
        WaitForEnum value;
        try {
            value = waitForFlag.value(options);
        } catch (Exception e) {
            System.err.println("Could not understand the --waitfor flag: Valid options are WALLET_TX, BLOCK, "
                    + "BALANCE and EVER");
            return;
        }
        wait(value);
        if (!wallet.isConsistent()) {
            System.err.println("************** WALLET IS INCONSISTENT *****************");
            return;
        }
        saveWallet(walletFile);
    }
    shutdown();
}

From source file:uk.ac.bris.cs.scotlandyard.ui.controller.License.java

License(Stage stage) {
    Controller.bind(this);
    try {/*from ww  w. ja  va2s.  com*/
        String license = Resources.toString(getClass().getResource("/LICENSE.txt"), StandardCharsets.UTF_8);
        content.setText(license);

        dismiss.setOnAction(e -> stage.close());
    } catch (IOException e) {
        e.printStackTrace();
    }
}