Java tutorial
/******************************************************************************* * (C) Copyright 2009 Molisys Solutions Co., Ltd. , All rights reserved * * * * This source code and any compilation or derivative thereof is the sole * * property of Molisys Solutions Co., Ltd. and is provided pursuant to a * * Software License Agreement. This code is the proprietary information * * of Molisys Solutions Co., Ltd and is confidential in nature. Its use and * * dissemination by any party other than Molisys Solutions Co., Ltd is * * strictly limited by the confidential information provisions of the * * Agreement referenced above. * ******************************************************************************/ package com.kscs.server.web.source; import java.io.File; import java.io.IOException; import java.util.Scanner; import org.apache.commons.codec.binary.Base64; /** * @author sinhlk * */ public class JavaSourceCode { private static String BEAN = "LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICogIChDKSBDb3B5cmlnaHQgMjAwOSBNb2xpc3lzIFNvbHV0aW9ucyBDby4sIEx0ZC4gLCBBbGwgcmlnaHRzIHJlc2VydmVkICAgICAgICoKICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoKICogIFRoaXMgc291cmNlIGNvZGUgYW5kIGFueSBjb21waWxhdGlvbiBvciBkZXJpdmF0aXZlIHRoZXJlb2YgaXMgdGhlIHNvbGUgICAgICoKICogIHByb3BlcnR5IG9mIE1vbGlzeXMgU29sdXRpb25zIENvLiwgTHRkLiBhbmQgaXMgcHJvdmlkZWQgcHVyc3VhbnQgdG8gYSAgICAgICoKICogIFNvZnR3YXJlIExpY2Vuc2UgQWdyZWVtZW50LiAgVGhpcyBjb2RlIGlzIHRoZSBwcm9wcmlldGFyeSBpbmZvcm1hdGlvbiAgICAgICoKICogIG9mIE1vbGlzeXMgU29sdXRpb25zIENvLiwgTHRkIGFuZCBpcyBjb25maWRlbnRpYWwgaW4gbmF0dXJlLiAgSXRzIHVzZSBhbmQgICoKICogIGRpc3NlbWluYXRpb24gYnkgYW55IHBhcnR5IG90aGVyIHRoYW4gTW9saXN5cyBTb2x1dGlvbnMgQ28uLCBMdGQgaXMgICAgICAgICoKICogIHN0cmljdGx5IGxpbWl0ZWQgYnkgdGhlIGNvbmZpZGVudGlhbCBpbmZvcm1hdGlvbiBwcm92aXNpb25zIG9mIHRoZSAgICAgICAgICoKICogIEFncmVlbWVudCByZWZlcmVuY2VkIGFib3ZlLiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KcGFja2FnZSA8UEFDS0FHRT47CgovKioKICogQGF1dGhvciBzaW5obGsKICoKICovCnB1YmxpYyBjbGFzcyA8QkVBTl9OQU1FPiB7CiAgICA8Qk9EWT4KfQo="; private static String INTERFACE_DAO = "LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICogIChDKSBDb3B5cmlnaHQgMjAwOSBNb2xpc3lzIFNvbHV0aW9ucyBDby4sIEx0ZC4gLCBBbGwgcmlnaHRzIHJlc2VydmVkICAgICAgICoKICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoKICogIFRoaXMgc291cmNlIGNvZGUgYW5kIGFueSBjb21waWxhdGlvbiBvciBkZXJpdmF0aXZlIHRoZXJlb2YgaXMgdGhlIHNvbGUgICAgICoKICogIHByb3BlcnR5IG9mIE1vbGlzeXMgU29sdXRpb25zIENvLiwgTHRkLiBhbmQgaXMgcHJvdmlkZWQgcHVyc3VhbnQgdG8gYSAgICAgICoKICogIFNvZnR3YXJlIExpY2Vuc2UgQWdyZWVtZW50LiAgVGhpcyBjb2RlIGlzIHRoZSBwcm9wcmlldGFyeSBpbmZvcm1hdGlvbiAgICAgICoKICogIG9mIE1vbGlzeXMgU29sdXRpb25zIENvLiwgTHRkIGFuZCBpcyBjb25maWRlbnRpYWwgaW4gbmF0dXJlLiAgSXRzIHVzZSBhbmQgICoKICogIGRpc3NlbWluYXRpb24gYnkgYW55IHBhcnR5IG90aGVyIHRoYW4gTW9saXN5cyBTb2x1dGlvbnMgQ28uLCBMdGQgaXMgICAgICAgICoKICogIHN0cmljdGx5IGxpbWl0ZWQgYnkgdGhlIGNvbmZpZGVudGlhbCBpbmZvcm1hdGlvbiBwcm92aXNpb25zIG9mIHRoZSAgICAgICAgICoKICogIEFncmVlbWVudCByZWZlcmVuY2VkIGFib3ZlLiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KcGFja2FnZSA8UEFDS0FHRT47CgppbXBvcnQgY29tLm1vbGlzeXMuZnJhbWV3b3JrLmJhc2UuQmFzZURhbzsKCi8qKgogKiBAYXV0aG9yIHNpbmhsawogKgogKi8KcHVibGljIGludGVyZmFjZSA8QkVBTl9OQU1FPkRhbyBleHRlbmRzIEJhc2VEYW88PEJFQU5fTkFNRT4+IHsKCn0K"; private static String INTERFACE_SERVICE = "LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICogIChDKSBDb3B5cmlnaHQgMjAwOSBNb2xpc3lzIFNvbHV0aW9ucyBDby4sIEx0ZC4gLCBBbGwgcmlnaHRzIHJlc2VydmVkICAgICAgICoKICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoKICogIFRoaXMgc291cmNlIGNvZGUgYW5kIGFueSBjb21waWxhdGlvbiBvciBkZXJpdmF0aXZlIHRoZXJlb2YgaXMgdGhlIHNvbGUgICAgICoKICogIHByb3BlcnR5IG9mIE1vbGlzeXMgU29sdXRpb25zIENvLiwgTHRkLiBhbmQgaXMgcHJvdmlkZWQgcHVyc3VhbnQgdG8gYSAgICAgICoKICogIFNvZnR3YXJlIExpY2Vuc2UgQWdyZWVtZW50LiAgVGhpcyBjb2RlIGlzIHRoZSBwcm9wcmlldGFyeSBpbmZvcm1hdGlvbiAgICAgICoKICogIG9mIE1vbGlzeXMgU29sdXRpb25zIENvLiwgTHRkIGFuZCBpcyBjb25maWRlbnRpYWwgaW4gbmF0dXJlLiAgSXRzIHVzZSBhbmQgICoKICogIGRpc3NlbWluYXRpb24gYnkgYW55IHBhcnR5IG90aGVyIHRoYW4gTW9saXN5cyBTb2x1dGlvbnMgQ28uLCBMdGQgaXMgICAgICAgICoKICogIHN0cmljdGx5IGxpbWl0ZWQgYnkgdGhlIGNvbmZpZGVudGlhbCBpbmZvcm1hdGlvbiBwcm92aXNpb25zIG9mIHRoZSAgICAgICAgICoKICogIEFncmVlbWVudCByZWZlcmVuY2VkIGFib3ZlLiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KcGFja2FnZSA8UEFDS0FHRT47CgppbXBvcnQgY29tLm1vbGlzeXMuZnJhbWV3b3JrLmJhc2UuQmFzZVNlcnZpY2U7CgovKioKICogQGF1dGhvciBzaW5obGsKICoKICovCnB1YmxpYyBpbnRlcmZhY2UgPEJFQU5fTkFNRT5TZXJ2aWNlIGV4dGVuZHMgQmFzZVNlcnZpY2U8PEJFQU5fTkFNRT4+IHsKCn0K"; private static String IMPL_DAO = "LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICogIChDKSBDb3B5cmlnaHQgMjAwOSBNb2xpc3lzIFNvbHV0aW9ucyBDby4sIEx0ZC4gLCBBbGwgcmlnaHRzIHJlc2VydmVkICAgICAgICoKICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoKICogIFRoaXMgc291cmNlIGNvZGUgYW5kIGFueSBjb21waWxhdGlvbiBvciBkZXJpdmF0aXZlIHRoZXJlb2YgaXMgdGhlIHNvbGUgICAgICoKICogIHByb3BlcnR5IG9mIE1vbGlzeXMgU29sdXRpb25zIENvLiwgTHRkLiBhbmQgaXMgcHJvdmlkZWQgcHVyc3VhbnQgdG8gYSAgICAgICoKICogIFNvZnR3YXJlIExpY2Vuc2UgQWdyZWVtZW50LiAgVGhpcyBjb2RlIGlzIHRoZSBwcm9wcmlldGFyeSBpbmZvcm1hdGlvbiAgICAgICoKICogIG9mIE1vbGlzeXMgU29sdXRpb25zIENvLiwgTHRkIGFuZCBpcyBjb25maWRlbnRpYWwgaW4gbmF0dXJlLiAgSXRzIHVzZSBhbmQgICoKICogIGRpc3NlbWluYXRpb24gYnkgYW55IHBhcnR5IG90aGVyIHRoYW4gTW9saXN5cyBTb2x1dGlvbnMgQ28uLCBMdGQgaXMgICAgICAgICoKICogIHN0cmljdGx5IGxpbWl0ZWQgYnkgdGhlIGNvbmZpZGVudGlhbCBpbmZvcm1hdGlvbiBwcm92aXNpb25zIG9mIHRoZSAgICAgICAgICoKICogIEFncmVlbWVudCByZWZlcmVuY2VkIGFib3ZlLiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KcGFja2FnZSA8UEFDS0FHRT47CgppbXBvcnQgY29tLm1vbGlzeXMuZnJhbWV3b3JrLmJhc2UuQmFzZURhb0ltcGw7CgovKioKICogQGF1dGhvciBzaW5obGsKICoKICovCnB1YmxpYyBjbGFzcyA8QkVBTl9OQU1FPkRhb0ltcGwgZXh0ZW5kcyBCYXNlRGFvSW1wbDw8QkVBTl9OQU1FPj4gaW1wbGVtZW50cwogICAgICAgIDxCRUFOX05BTUU+RGFvIHsKCn0K"; private static String IMPL_SERVICE = "LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKICogIChDKSBDb3B5cmlnaHQgMjAwOSBNb2xpc3lzIFNvbHV0aW9ucyBDby4sIEx0ZC4gLCBBbGwgcmlnaHRzIHJlc2VydmVkICAgICAgICoKICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoKICogIFRoaXMgc291cmNlIGNvZGUgYW5kIGFueSBjb21waWxhdGlvbiBvciBkZXJpdmF0aXZlIHRoZXJlb2YgaXMgdGhlIHNvbGUgICAgICoKICogIHByb3BlcnR5IG9mIE1vbGlzeXMgU29sdXRpb25zIENvLiwgTHRkLiBhbmQgaXMgcHJvdmlkZWQgcHVyc3VhbnQgdG8gYSAgICAgICoKICogIFNvZnR3YXJlIExpY2Vuc2UgQWdyZWVtZW50LiAgVGhpcyBjb2RlIGlzIHRoZSBwcm9wcmlldGFyeSBpbmZvcm1hdGlvbiAgICAgICoKICogIG9mIE1vbGlzeXMgU29sdXRpb25zIENvLiwgTHRkIGFuZCBpcyBjb25maWRlbnRpYWwgaW4gbmF0dXJlLiAgSXRzIHVzZSBhbmQgICoKICogIGRpc3NlbWluYXRpb24gYnkgYW55IHBhcnR5IG90aGVyIHRoYW4gTW9saXN5cyBTb2x1dGlvbnMgQ28uLCBMdGQgaXMgICAgICAgICoKICogIHN0cmljdGx5IGxpbWl0ZWQgYnkgdGhlIGNvbmZpZGVudGlhbCBpbmZvcm1hdGlvbiBwcm92aXNpb25zIG9mIHRoZSAgICAgICAgICoKICogIEFncmVlbWVudCByZWZlcmVuY2VkIGFib3ZlLiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICoKICoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KcGFja2FnZSA8UEFDS0FHRT47CgppbXBvcnQgY29tLm1vbGlzeXMuZnJhbWV3b3JrLmJhc2UuQmFzZVNlcnZpY2VJbXBsOwoKLyoqCiAqIEBhdXRob3Igc2luaGxrCiAqCiAqLwpwdWJsaWMgY2xhc3MgPEJFQU5fTkFNRT5TZXJ2aWNlSW1wbCBleHRlbmRzIEJhc2VTZXJ2aWNlSW1wbDw8QkVBTl9OQU1FPj4gaW1wbGVtZW50cwogICAgICAgIDxCRUFOX05BTUU+U2VydmljZSB7CiAgICBwcml2YXRlIDxCRUFOX05BTUU+RGFvIDxCRUFOX05BTUVfTk9NQUw+RGFvOwoKICAgIC8qKgogICAgICogQHJldHVybiB0aGUgPEJFQU5fTkFNRV9OT01BTD5EYW8KICAgICAqLwogICAgcHVibGljIDxCRUFOX05BTUU+RGFvIGdldDxCRUFOX05BTUU+RGFvKCkgewogICAgICAgIHJldHVybiA8QkVBTl9OQU1FX05PTUFMPkRhbzsKICAgIH0KCiAgICAvKioKICAgICAqIEBwYXJhbSA8QkVBTl9OQU1FX05PTUFMPkRhbwogICAgICogICAgICAgICAgICB0aGUgPEJFQU5fTkFNRV9OT01BTD5EYW8gdG8gc2V0CiAgICAgKi8KICAgIHB1YmxpYyB2b2lkIHNldDxCRUFOX05BTUU+RGFvKDxCRUFOX05BTUU+RGFvIDxCRUFOX05BTUVfTk9NQUw+RGFvKSB7CiAgICAgICAgdGhpcy48QkVBTl9OQU1FX05PTUFMPkRhbyA9IDxCRUFOX05BTUVfTk9NQUw+RGFvOwogICAgICAgIHRoaXMuYmFzZURhbyA9IDxCRUFOX05BTUVfTk9NQUw+RGFvOwogICAgfQp9Cg=="; private static String GET_STATEMENT = "ICAgIC8qKgogICAgICogQHJldHVybiB0aGUgPE5BTUU+CiAgICAgKi8KICAgIHB1YmxpYyA8VFlQRT4gZ2V0PE5BTUVfVVBDQVNFPigpIHsKICAgICAgICByZXR1cm4gPE5BTUU+OwogICAgfQo="; private static String SET_STATEMENT = "ICAgIC8qKgogICAgICogQHBhcmFtIDxOQU1FPgogICAgICogICAgICAgICAgICB0aGUgPE5BTUU+IHRvIHNldAogICAgICovCiAgICBwdWJsaWMgdm9pZCBzZXQ8TkFNRV9VUENBU0U+KDxUWVBFPiA8TkFNRT4pIHsKICAgICAgICB0aGlzLjxOQU1FPiA9IDxOQU1FPjsKICAgIH0K"; public static String getDaoInterfaceSource() { return new String(Base64.decodeBase64(INTERFACE_DAO.getBytes())); } public static String getServiceInterfaceSource() { return new String(Base64.decodeBase64(INTERFACE_SERVICE.getBytes())); } public static String getDaoImplSource() { return new String(Base64.decodeBase64(IMPL_DAO.getBytes())); } public static String getServiceImplSource() { return new String(Base64.decodeBase64(IMPL_SERVICE.getBytes())); } public static String getBeanSource() { return new String(Base64.decodeBase64(BEAN.getBytes())); } public static String getStatement() { return new String(Base64.decodeBase64(GET_STATEMENT.getBytes())); } public static String setStatement() { return new String(Base64.decodeBase64(SET_STATEMENT.getBytes())); } public String readfile(String filename) { File file = new File("/home/sinhlk/myspace/tool/src/main/resources/" + filename); StringBuilder result = new StringBuilder(""); try { Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { String line = scanner.nextLine(); result.append(line).append("\n"); } scanner.close(); } catch (IOException e) { e.printStackTrace(); } String sourceFile = result.toString(); return sourceFile; } public static void main(String[] args) { JavaSourceCode sourceCode = new JavaSourceCode(); System.out.println("Hello"); // System.out.println(sourceCode.readfile("bean.txt")); Base64 base64 = new Base64(); System.out.println(new String(base64.encode(sourceCode.readfile("bean.txt").getBytes()))); System.out.println(new String(base64.decode(base64.encode(sourceCode.readfile("bean.txt").getBytes())))); } }