Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bbfe074

Browse files
committed
jar import를 위한 refactor 중
1 parent 61cf87e commit bbfe074

File tree

3 files changed

+67
-43
lines changed

3 files changed

+67
-43
lines changed

‎.idea/workspace.xml

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

‎src/com/inzapp/sql_to_json_parser/SqlToJsonParser.java

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,92 @@
77
import java.io.BufferedReader;
88
import java.io.FileOutputStream;
99
import java.io.FileReader;
10+
import java.nio.charset.StandardCharsets;
11+
import java.util.Base64;
1012

1113
public class SqlToJsonParser {
14+
// /**
15+
// * main method
16+
// * used for executable jar
17+
// *
18+
// * @param args [0] : specified input file name
19+
// * [1] : specified output file name
20+
// */
21+
// public static void main(String[] args) {
22+
// String inputFileName = Config.INPUT_FILE_NAME;
23+
// String outputFileName = Config.OUTPUT_FILE_NAME;
24+
// if (args != null && args.length == 2) {
25+
// inputFileName = args[0];
26+
// outputFileName = args[1];
27+
// }
28+
//
29+
// SqlToJsonParser sqlToJsonParser = new SqlToJsonParser();
30+
// Parser parser = new Parser();
31+
// try {
32+
// String sql = sqlToJsonParser.readSqlFromFile(inputFileName);
33+
// if (sql == null)
34+
// throw new Exception("input file does not exist");
35+
//
36+
// JSONObject json = parser.parse(sql);
37+
// if (json == null)
38+
// throw new Exception("sql syntax error");
39+
//
40+
// String jsonString = json.toString(4);
41+
// System.out.println("input sql\n\n" + sql);
42+
// System.out.println("output json\n\n" + jsonString);
43+
//
44+
// sqlToJsonParser.saveFile(jsonString, outputFileName);
45+
// System.out.println("parse success");
46+
// } catch (Exception e) {
47+
// sqlToJsonParser.saveFile(Config.SQL_SYNTAX_ERROR, outputFileName);
48+
// System.out.println(e.getMessage());
49+
// }
50+
// }
51+
1252
/**
13-
* main method
14-
* used for executable jar
53+
* used for java code
1554
*
16-
* @param args [0] : specified input file name
17-
* [1] : specified output file name
55+
* @param sql raw sql query encoded with base 64
56+
* @return parsed json string
57+
* return null if exception was caught
1858
*/
19-
public static void main(String[] args) {
20-
String inputFileName = Config.INPUT_FILE_NAME;
21-
String outputFileName = Config.OUTPUT_FILE_NAME;
22-
if (args != null && args.length == 2) {
23-
inputFileName = args[0];
24-
outputFileName = args[1];
25-
}
26-
27-
SqlToJsonParser sqlToJsonParser = new SqlToJsonParser();
28-
Parser parser = new Parser();
29-
try {
30-
String sql = sqlToJsonParser.readSqlFromFile(inputFileName);
31-
if (sql == null)
32-
throw new Exception("input file does not exist");
33-
34-
JSONObject json = parser.parse(sql);
35-
if (json == null)
36-
throw new Exception("sql syntax error");
37-
38-
String jsonString = json.toString(4);
39-
System.out.println("input sql\n\n" + sql);
40-
System.out.println("output json\n\n" + jsonString);
41-
42-
sqlToJsonParser.saveFile(jsonString, outputFileName);
43-
System.out.println("parse success");
44-
} catch (Exception e) {
45-
sqlToJsonParser.saveFile(Config.SQL_SYNTAX_ERROR, outputFileName);
46-
System.out.println(e.getMessage());
47-
}
59+
public String parse(String sql) {
60+
return parse(sql, true);
4861
}
4962

5063
/**
5164
* used for java code
5265
*
5366
* @param sql raw sql query
67+
* @param isEncoded64 true if encoded with base 64
5468
* @return parsed json string
5569
* return null if exception was caught
5670
*/
57-
public String parse(String sql) {
71+
public String parse(String sql, boolean isEncoded64) {
72+
if(isEncoded64)
73+
sql = decode64(sql);
74+
5875
try {
5976
return new Parser().parse(sql).toString(4);
6077
} catch (Exception e) {
6178
return null;
6279
}
6380
}
6481

82+
private String encode64(String raw) {
83+
byte[] bytes = raw.getBytes(StandardCharsets.UTF_8);
84+
Base64.Encoder encoder = Base64.getEncoder();
85+
byte[] encodedBytes = encoder.encode(bytes);
86+
return encoder.encodeToString(encodedBytes);
87+
}
88+
89+
private String decode64(String encoded64) {
90+
byte[] encodedBytes = encoded64.getBytes();
91+
Base64.Decoder decoder = Base64.getDecoder();
92+
byte[] decodedBytes = decoder.decode(encodedBytes);
93+
return new String(decodedBytes, StandardCharsets.UTF_8);
94+
}
95+
6596
/**
6697
* read sql from com.inzapp.SqlToJsonParser.config.Config.INPUT_FILE_NAME
6798
* used for executable jar

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /