Java Code Examples for org.web3j.utils.Files#readBytes()

The following examples show how to use org.web3j.utils.Files#readBytes() . 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 File: SolidityFunctionWrapperGenerator.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
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 2
Source File: WasmFunctionWrapperGenerator.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
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 3
Source File: SolidityFunctionWrapperGenerator.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: SolidityFunctionWrapperGenerator.java    From web3j with 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");
    }
}