mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
fix Decompiler jdk7 support . #1711
This commit is contained in:
@@ -113,7 +113,8 @@ public class Decompiler {
|
||||
String emptyStr = " ";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String[] lines = src.split("\\R");
|
||||
|
||||
List<String> lines = StringUtils.toLines(src);
|
||||
|
||||
if (maxLineNumber >= 100) {
|
||||
formatStr = "/*%3d*/ ";
|
||||
@@ -122,14 +123,17 @@ public class Decompiler {
|
||||
formatStr = "/*%4d*/ ";
|
||||
emptyStr = " ";
|
||||
}
|
||||
for (int i = 0; i < lines.length; ++i) {
|
||||
Integer srcLineNumber = lineMapping.get(i + 1);
|
||||
|
||||
int index = 0;
|
||||
for (String line : lines) {
|
||||
Integer srcLineNumber = lineMapping.get(index + 1);
|
||||
if (srcLineNumber != null) {
|
||||
sb.append(String.format(formatStr, srcLineNumber));
|
||||
} else {
|
||||
sb.append(emptyStr);
|
||||
}
|
||||
sb.append(lines[i]).append("\n");
|
||||
sb.append(line).append("\n");
|
||||
index++;
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.taobao.arthas.core.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
@@ -885,4 +889,27 @@ public abstract class StringUtils {
|
||||
: bytes < 0xfffccccccccccccL ? String.format("%.1f PiB", (bytes >> 10) / 0x1p40)
|
||||
: String.format("%.1f EiB", (bytes >> 20) / 0x1p40);
|
||||
}
|
||||
|
||||
public static List<String> toLines(String text) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
BufferedReader reader = new BufferedReader(new StringReader(text));
|
||||
try {
|
||||
String line = reader.readLine();
|
||||
while (line != null) {
|
||||
result.add(line);
|
||||
line = reader.readLine();
|
||||
}
|
||||
} catch (IOException exc) {
|
||||
// quit
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user