Java Code Examples for org.web3j.utils.Files

The following examples show how to use org.web3j.utils.Files. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: client-sdk-java   Source File: KeyImporter.java    License: Apache License 2.0 6 votes vote down vote up
private void run(String input) {
    File keyFile = new File(input);

    if (keyFile.isFile()) {
        String privateKey = null;
        try {
            privateKey = Files.readString(keyFile);
        } catch (IOException e) {
            exitError("Unable to read file " + input);
        }

        createWalletFile(privateKey.trim());
    } else {
        createWalletFile(input.trim());
    }
}
 
Example 2
private void run(String input) {
    File keyFile = new File(input);

    if (keyFile.isFile()) {
        String privateKey = null;
        try {
            privateKey = Files.readString(keyFile);
        } catch (IOException e) {
            exitError("Unable to read file " + input);
        }

        createWalletFile(privateKey.trim());
    } else {
        createWalletFile(input.trim());
    }
}
 
Example 3
private void generate() throws IOException, ClassNotFoundException {

		File binaryFile = new File(binaryFileLocation);
		if (!binaryFile.exists()) {
			exitError("Invalid input binary file specified: " + binaryFileLocation);
		}

		byte[] bytes = Files.readBytes(new File(binaryFile.toURI()));
		String binary = new String(bytes);

		File absFile = new File(absFileLocation);
		if (!absFile.exists() || !absFile.canRead()) {
			exitError("Invalid input ABI file specified: " + absFileLocation);
		}
		String fileName = absFile.getName();
		String contractName = getFileNameNoExtension(fileName);
		bytes = Files.readBytes(new File(absFile.toURI()));
		String abi = new String(bytes);

		List<AbiDefinition> functionDefinitions = loadContractDefinition(absFile);

		if (functionDefinitions.isEmpty()) {
			exitError("Unable to parse input ABI file");
		} else {
			String className = Strings.capitaliseFirstLetter(contractName);
			System.out.printf("Generating " + basePackageName + "." + className + " ... ");
			new SolidityFunctionWrapper(useJavaNativeTypes).generateJavaFiles(contractName, binary, abi, destinationDirLocation.toString(),
					basePackageName);
			System.out.println("File written to " + destinationDirLocation.toString() + "\n");
		}
	}
 
Example 4
private void generate() throws IOException, ClassNotFoundException {

		File binaryFile = new File(binaryFileLocation);
		if (!binaryFile.exists()) {
			exitError("Invalid input binary file specified: " + binaryFileLocation);
		}

		byte[] bytes = Files.readBytes(new File(binaryFile.toURI()));
		// String binary = new String(bytes);
		String binary = Numeric.toHexString(bytes);

		File absFile = new File(absFileLocation);
		if (!absFile.exists() || !absFile.canRead()) {
			exitError("Invalid input ABI file specified: " + absFileLocation);
		}
		String fileName = absFile.getName();
		String contractName = getFileNameNoExtension(getFileNameNoExtension(fileName));
		bytes = Files.readBytes(new File(absFile.toURI()));
		String abi = new String(bytes);

		List<WasmAbiDefinition> functionDefinitions = loadContractDefinition(absFile);

		if (functionDefinitions.isEmpty()) {
			exitError("Unable to parse input ABI file");
		} else {
			String className = Strings.capitaliseFirstLetter(contractName);

			System.out.println("Generating " + basePackageName + "." + className + " ... ");

			new WasmFunctionWrapper().generateJavaFiles(contractName, binary, abi, destinationDirLocation.toString(), basePackageName);

			System.out.println("File written to " + destinationDirLocation.toString() + "\n");
		}
	}
 
Example 5
private void generate() throws IOException, ClassNotFoundException {

        File binaryFile = new File(binaryFileLocation);
        if (!binaryFile.exists()) {
            exitError("Invalid input binary file specified: " + binaryFileLocation);
        }

        byte[] bytes = Files.readBytes(new File(binaryFile.toURI()));
        String binary = new String(bytes);

        File absFile = new File(absFileLocation);
        if (!absFile.exists() || !absFile.canRead()) {
            exitError("Invalid input ABI file specified: " + absFileLocation);
        }
        String fileName = absFile.getName();
        String contractName = getFileNameNoExtension(fileName);
        bytes = Files.readBytes(new File(absFile.toURI()));
        String abi = new String(bytes);

        List<AbiDefinition> functionDefinitions = loadContractDefinition(absFile);

        if (functionDefinitions.isEmpty()) {
            exitError("Unable to parse input ABI file");
        } else {
            String className = Strings.capitaliseFirstLetter(contractName);
            System.out.printf("Generating " + basePackageName + "." + className + " ... ");
            new SolidityFunctionWrapper(useJavaNativeTypes).generateJavaFiles(
                    contractName, binary, abi, destinationDirLocation.toString(), basePackageName);
            System.out.println("File written to " + destinationDirLocation.toString() + "\n");
        }
    }
 
Example 6
Source Project: web3j   Source File: SolidityFunctionWrapperGenerator.java    License: Apache License 2.0 5 votes vote down vote up
public final void generate() throws IOException, ClassNotFoundException {
    String binary = Contract.BIN_NOT_PROVIDED;
    if (binFile != null) {
        byte[] bytes = Files.readBytes(binFile);
        binary = new String(bytes);
    }
    List<AbiDefinition> functionDefinitions = loadContractDefinition(abiFile);

    if (functionDefinitions.isEmpty()) {
        exitError("Unable to parse input ABI file");
    } else {
        String className = Strings.capitaliseFirstLetter(contractName);
        System.out.print("Generating " + basePackageName + "." + className + " ... ");

        new SolidityFunctionWrapper(
                        useJavaNativeTypes,
                        useJavaPrimitiveTypes,
                        generateSendTxForCalls,
                        addressLength)
                .generateJavaFiles(
                        contractClass,
                        contractName,
                        binary,
                        functionDefinitions,
                        destinationDirLocation.toString(),
                        basePackageName,
                        null);

        System.out.println("File written to " + destinationDirLocation.toString() + "\n");
    }
}