Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ private void loadJavaSource(String strPath, JavaProjectBuilder builder) {
* @param builder builder
*/
public void loadJarJavaSource(String path, JavaProjectBuilder builder) {
OutputStream out;
if (!path.endsWith(".jar")) {
return;
}
Expand All @@ -293,18 +292,17 @@ public void loadJarJavaSource(String path, JavaProjectBuilder builder) {
while (entryEnumeration.hasMoreElements()) {
JarEntry entry = entryEnumeration.nextElement();
if (entry.getName().endsWith(".java")) {
InputStream is = jarFile.getInputStream(entry);
File file = new File(DocGlobalConstants.JAR_TEMP + entry.getName());
if (!file.exists()) {
file.getParentFile().mkdirs();
}
out = Files.newOutputStream(file.toPath());
int len;
while ((len = is.read()) != -1) {
out.write(len);
try (InputStream is = jarFile.getInputStream(entry);
OutputStream out = Files.newOutputStream(file.toPath())) {
int len;
while ((len = is.read()) != -1) {
out.write(len);
}
}
is.close();
out.close();
}
}
File file = new File(DocGlobalConstants.JAR_TEMP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public Map<String, Object> buildPaths(ApiConfig apiConfig, ApiSchema<ApiDoc> api
}
}
}
for (Map.Entry<String, TagDoc> docEntry : DocMapping.TAG_DOC.entrySet()) {
for (Map.Entry<String, TagDoc> docEntry : DocMapping.getTagDocMap().entrySet()) {
tags.addAll(docEntry.getValue()
.getClazzDocs()
.stream()
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/io/github/smartdoc/model/DocMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DocMapping {
/**
* key:tag value:ApiDoc
*/
public static Map<String, TagDoc> TAG_DOC = new ConcurrentHashMap<>(64);
private static final Map<String, TagDoc> TAG_DOC = new ConcurrentHashMap<>(64);

public static void tagDocPut(String tag, ApiDoc apiDoc, ApiMethodDoc methodDoc) {
if (StringUtils.isBlank(tag)) {
Expand All @@ -55,7 +55,11 @@ public static void tagDocPut(String tag, ApiDoc apiDoc, ApiMethodDoc methodDoc)
}

public static void init() {
TAG_DOC = new ConcurrentHashMap<>(64);
TAG_DOC.clear();
}

public static Map<String, TagDoc> getTagDocMap() {
return TAG_DOC;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ private static void writeFile(DependencyTree instance) {
}

private static String readFile(File configFile) {
try {
BufferedReader reader = new BufferedReader(new FileReader(configFile));
try (BufferedReader reader = new BufferedReader(new FileReader(configFile))) {
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,13 @@ public StreamGobbler(InputStream inputStream, Consumer<String> consumer) {

@Override
public void run() {
new BufferedReader(new InputStreamReader(inputStream)).lines().forEach(consumer);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
Stream<String> lines = reader.lines()) {
lines.forEach(consumer);
}
catch (IOException e) {
// ignore: the process stream is no longer readable once the process exits
}
}

}
Expand Down
52 changes: 26 additions & 26 deletions src/main/java/io/github/smartdoc/utils/DocUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import java.util.Stack;
import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -288,12 +289,12 @@ private DocUtil() {
/**
* Cache the regex and its pattern object
*/
private static final Map<String, Pattern> PATTERN_CACHE = new HashMap<>();
private static final Map<String, Pattern> PATTERN_CACHE = new ConcurrentHashMap<>();

/**
* "packageFilters" cache
*/
private static final Map<String, Set<String>> FILTER_METHOD_CACHE = new HashMap<>();
private static final Map<String, Set<String>> FILTER_METHOD_CACHE = new ConcurrentHashMap<>();

/**
* Generate a random value based on java type name.
Expand Down Expand Up @@ -1882,33 +1883,32 @@ public static void copyAndReplaceDocx(String content, String docxOutputPath, Str
InputStream resourceAsStream = WordDocBuilder.class.getClassLoader().getResourceAsStream(templateDocx);
Objects.requireNonNull(resourceAsStream, "word template docx is not found");

ZipInputStream zipInputStream = new ZipInputStream(resourceAsStream);
ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(Paths.get(docxOutputPath)));
// Traverse the files in the compressed package
ZipEntry entry;
while ((entry = zipInputStream.getNextEntry()) != null) {
String entryName = entry.getName();
// copy fix the bug: invalid entry compressed size
zipOutputStream.putNextEntry(new ZipEntry(entryName));
if ("word/document.xml".equals(entryName)) {
byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
zipOutputStream.write(bytes, 0, bytes.length);
}
else {
// copy
byte[] buffer = new byte[1024];
int len;
while ((len = zipInputStream.read(buffer)) > 0) {
zipOutputStream.write(buffer, 0, len);
try (ZipInputStream zipInputStream = new ZipInputStream(resourceAsStream);
ZipOutputStream zipOutputStream = new ZipOutputStream(
Files.newOutputStream(Paths.get(docxOutputPath)))) {
// Traverse the files in the compressed package
ZipEntry entry;
while ((entry = zipInputStream.getNextEntry()) != null) {
String entryName = entry.getName();
// copy fix the bug: invalid entry compressed size
zipOutputStream.putNextEntry(new ZipEntry(entryName));
if ("word/document.xml".equals(entryName)) {
byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
zipOutputStream.write(bytes, 0, bytes.length);
}
else {
// copy
byte[] buffer = new byte[1024];
int len;
while ((len = zipInputStream.read(buffer)) > 0) {
zipOutputStream.write(buffer, 0, len);
}
}
}

zipOutputStream.closeEntry();
zipInputStream.closeEntry();
zipOutputStream.closeEntry();
zipInputStream.closeEntry();
}
}

zipInputStream.close();
zipOutputStream.close();
}

}
Loading