Skip to content

Commit

Permalink
fix can not read resource bugf
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangke committed Nov 12, 2018
1 parent c1810ad commit 74463ad
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
Binary file modified gorepomaker-intellij-plugin.jar
Binary file not shown.
26 changes: 10 additions & 16 deletions src/com/godaner/gorepomaker_intellij_plugin/repomaker/Util.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
package com.godaner.gorepomaker_intellij_plugin.repomaker;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.*;


public class Util {
public static String file2Str(String filePathName)
public static String inputStream2Str(InputStream inputStream)
{
String fileContent = "";
try {
File f = new File(filePathName);
if (f.isFile() && f.exists()) {
InputStreamReader read = new InputStreamReader(new FileInputStream(f), "UTF-8");
BufferedReader reader = new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null) {
fileContent += (line+"\n");
}
read.close();
InputStreamReader read = new InputStreamReader(inputStream, "UTF-8");
BufferedReader reader = new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null) {
fileContent += (line+"\n");
}
read.close();
} catch (Exception e) {
System.out.println("读取文件内容操作出错");
e.printStackTrace();
}
return fileContent;
}

public static String makeTemplate2RepoStr(Entity entity, String templatePathName) {
public static String makeTemplate2RepoStr(Entity entity, InputStream inputStream) {

String text=Util.file2Str(templatePathName);
String text=Util.inputStream2Str(inputStream);
try {
text=text.replace(placeholder(Const.ENTITY_MONGO_REPO_NAME),entity.getMongoRepoName());
} catch (Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import com.godaner.gorepomaker_intellij_plugin.repomaker.AbstractGoRepoMaker;
import com.godaner.gorepomaker_intellij_plugin.repomaker.Entity;
import com.godaner.gorepomaker_intellij_plugin.repomaker.Util;
import com.godaner.gorepomaker_intellij_plugin.repomaker.maker.mongo.RepoMongoImpl;

public class RepoInterface extends AbstractGoRepoMaker {
@Override
public String makeRepo(Entity entity) {
String filePathName = RepoInterface.class.getClassLoader().getResource("repotemplates/inf_repo.txt").getPath();
return Util.makeTemplate2RepoStr(entity,filePathName);
return Util.makeTemplate2RepoStr(entity,RepoMongoImpl.class.getClassLoader().getResourceAsStream("repotemplates/inf_repo.txt"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
import com.godaner.gorepomaker_intellij_plugin.repomaker.AbstractGoRepoMaker;
import com.godaner.gorepomaker_intellij_plugin.repomaker.Entity;
import com.godaner.gorepomaker_intellij_plugin.repomaker.Util;
import com.godaner.gorepomaker_intellij_plugin.repomaker.maker.inf.RepoInterface;

import java.io.File;

public class RepoMongoImpl extends AbstractGoRepoMaker {
@Override
public String makeRepo(Entity entity) {
String filePathName = RepoInterface.class.getClassLoader().getResource("repotemplates/impl_mgo_repo.txt").getPath();
return Util.makeTemplate2RepoStr(entity,filePathName);

return Util.makeTemplate2RepoStr(entity,RepoMongoImpl.class.getClassLoader().getResourceAsStream("repotemplates/impl_mgo_repo.txt"));
}

@Override
public int sortNum() {
return 0;
}

}
}

0 comments on commit 74463ad

Please sign in to comment.