Libraryless. Click here for Pure Java version (253L/3K/8K).
1 | !629 |
2 | |
3 | import javax.imageio.*; |
4 | import java.awt.image.*; |
5 | import java.awt.*; |
6 | import java.security.NoSuchAlgorithmException; |
7 | import java.security.MessageDigest; |
8 | import java.lang.reflect.*; |
9 | import java.net.*; |
10 | import java.io.*; |
11 | import javax.swing.*; |
12 | import java.util.regex.*; |
13 | import java.util.List; |
14 | import java.util.zip.*; |
15 | import java.util.*; |
16 | |
17 | public class main { |
18 | public static void main(String[] args) throws Exception { |
19 | saveMainJava(addClassJavaX(loadMainJava())); |
20 | } |
21 | |
22 | static String loadMainJava() throws IOException { |
23 | return loadTextFile("input/main.java", ""); |
24 | } |
25 | |
26 | static void saveMainJava(String s) throws IOException { |
27 | saveTextFile("output/main.java", s); |
28 | } |
29 | |
30 | static String addClassJavaX(String s) throws IOException { |
31 | if (s.indexOf("_javax.") < 0) return s; |
32 | s = moveImportsUp(loadSnippet("#1000572") + "\n" + s); |
33 | return s; |
34 | } |
35 | |
36 | /** writes safely (to temp file, then rename) */ |
37 | public static void saveTextFile(String fileName, String contents) throws IOException { |
38 | File file = new File(fileName); |
39 | File parentFile = file.getParentFile(); |
40 | if (parentFile != null) |
41 | parentFile.mkdirs(); |
42 | String tempFileName = fileName + "_temp"; |
43 | FileOutputStream fileOutputStream = new FileOutputStream(tempFileName); |
44 | OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, "UTF-8"); |
45 | PrintWriter printWriter = new PrintWriter(outputStreamWriter); |
46 | printWriter.print(contents); |
47 | printWriter.close(); |
48 | if (file.exists() && !file.delete()) |
49 | throw new IOException("Can't delete " + fileName); |
50 | |
51 | if (!new File(tempFileName).renameTo(file)) |
52 | throw new IOException("Can't rename " + tempFileName + " to " + fileName); |
53 | } |
54 | |
55 | public static String loadTextFile(String fileName, String defaultContents) throws IOException { |
56 | if (!new File(fileName).exists()) |
57 | return defaultContents; |
58 | |
59 | FileInputStream fileInputStream = new FileInputStream(fileName); |
60 | InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8"); |
61 | return loadTextFile(inputStreamReader); |
62 | } |
63 | |
64 | public static String loadTextFile(Reader reader) throws IOException { |
65 | StringBuilder builder = new StringBuilder(); |
66 | try { |
67 | BufferedReader bufferedReader = new BufferedReader(reader); |
68 | String line; |
69 | while ((line = bufferedReader.readLine()) != null) |
70 | builder.append(line).append('\n'); |
71 | } finally { |
72 | reader.close(); |
73 | } |
74 | return builder.length() == 0 ? "" : builder.substring(0, builder.length()-1); |
75 | } |
76 | |
77 | public static List<String> toLines(String s) { |
78 | List<String> lines = new ArrayList<String>(); |
79 | int start = 0; |
80 | while (true) { |
81 | int i = toLines_nextLineBreak(s, start); |
82 | if (i < 0) { |
83 | if (s.length() > start) lines.add(s.substring(start)); |
84 | break; |
85 | } |
86 | |
87 | lines.add(s.substring(start, i)); |
88 | if (s.charAt(i) == '\r' && i+1 < s.length() && s.charAt(i+1) == '\n') |
89 | i += 2; |
90 | else |
91 | ++i; |
92 | |
93 | start = i; |
94 | } |
95 | return lines; |
96 | } |
97 | |
98 | private static int toLines_nextLineBreak(String s, int start) { |
99 | for (int i = start; i < s.length(); i++) { |
100 | char c = s.charAt(i); |
101 | if (c == '\r' || c == '\n') |
102 | return i; |
103 | } |
104 | return -1; |
105 | } |
106 | |
107 | public static String fromLines(List<String> lines) { |
108 | StringBuilder buf = new StringBuilder(); |
109 | for (String line : lines) { |
110 | buf.append(line).append('\n'); |
111 | } |
112 | return buf.toString(); |
113 | } |
114 | } |
download show line numbers debug dex old transpilations
Travelled to 20 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, dhtvkmknsjym, gwrvuhgaqvyk, ishqpsrjomds, jlatgrcjtklg, jtubtzbbkimh, liwcxgsjrgqn, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1000703 |
Snippet name: | Add class _javax if required in source (post processor) |
Eternal ID of this version: | #1000703/1 |
Text MD5: | 1e36d2787979a06883557e8a47afd773 |
Transpilation MD5: | ce478f28229bfab02a84d007527feeb5 |
Author: | stefan |
Category: | |
Type: | JavaX translator |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-08-23 14:57:17 |
Source code size: | 3568 bytes / 114 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 651 / 13979 |
Referenced in: | [show references] |