📄 base64com.java
字号:
/*
* com.twiek.Utils.Base64* package version 1.0, Base64 encoding/decoding utilities
* Copyright (C) 2003 Brent "Twiek" Crowe. All rights reserved.
*
* This file is part of the com.twiek.Utils.Base64* package
*
* The com.twiek.Utils.Base64* package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package com.twiek.Utils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
/**
*
* @version $Revision: 1.0 $
* @author Brent "Twiek" Crowe <Twiek@softhome.net>
*/
public final class Base64Com {
private Base64Com() {}
public static char menu() {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String buf = "";
char selection = ' ';
do {
System.out.println();
System.out.println("-----Choose-----");
System.out.println("E)ncode a string");
System.out.println("D)ecode a string");
System.out.println("Q)uit");
System.out.print("Selection: ");
try {
buf = in.readLine();
}
catch(IOException e) {}
buf = buf.toUpperCase();
selection = buf.charAt(0);
} while(selection != 'E' && selection != 'D' && selection != 'Q');
if(selection == 'Q') {
System.out.println("GoodBye!");
System.exit(0);
}
System.out.println();
return selection;
}
private static void usage() {
System.out.println();
System.out.println("Usage: [-e][-d] <String to encode/decode>");
System.out.println(" -e - Encode String");
System.out.println(" -d - Decode String");
System.out.println();
System.out.println("Without parameters, Base64Com will enter interactive mode");
}
private static void copyright() {
System.out.println("Base64Com v1.0, Copyright (C) 2003 Brent \"Twiek\" Crowe");
System.out.println("Base64Com comes with ABSOLUTELY NO WARRANTY; for details");
System.out.println("see LICENSE.txt. This is free software, and you are welcome");
System.out.println("to redistribute it under certain conditions; see LICENSE.txt");
System.out.println("for details.");
}
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String text,
encoded,
decoded;
char selection;
copyright();
if(args.length != 0) {
if(!(args[0].equals("-e") || args[0].equals("-d")) || args.length < 2) {
usage();
System.exit(0);
}
else if(args[0].equals("-e")) {
System.out.println("Encoding [" + args[1] + "]:");
System.out.println();
System.out.println(Base64.encode(args[1]));
}
else if(args[0].equals("-d")) {
System.out.println("Decoding [" + args[1] + "]:");
System.out.println();
System.out.println(Base64.decode(args[1]));
}
}
else {
for(;;) {
selection = menu();
if(selection == 'E') {
System.out.print("String to encode: ");
text = in.readLine();
System.out.println(Base64.encode(text));
}
else {
System.out.print("String to decode: ");
text = in.readLine();
System.out.println(Base64.decode(text));
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -