입력 스트림에서 토큰을 바꾸기 위해 Swizzle Stream 라이브러리를 사용해 보았습니다.Swizzle Stream을 사용하여 스트림에서 문자열 바꾸기
String RESOURCE_PATH = "FakePom.xml";
InputStream pomIS = JarFinderServlet.class.getClassLoader().getResourceAsStream(RESOURCE_PATH);
if(null == pomIS)
throw new MavenhoeException("Can't read fake pom template - getResourceAsStream(RESOURCE_PATH) == null");
Map map = ArrayUtils.toMap( new String[][]{
{"@[email protected]", artifactInfo.getGroup() },
{"@[email protected]", artifactInfo.getName() },
{"@[email protected]", artifactInfo.getVersion() },
{"@[email protected]", artifactInfo.getPackaging() },
{"@[email protected]", artifactInfo.getFileName() },
{"@[email protected]", req.getQueryString() },
});
// This does not replace anything, no idea why. //
ReplaceStringsInputStream replacingIS = new ReplaceStringsInputStream(pomIS, map);
ReplaceStringInputStream replacingIS2 = new ReplaceStringInputStream(pomIS, "@[email protected]", "0.0-AAAAA");
ReplaceStringInputStream replacingIS3 = new ReplaceStringInputStream(pomIS, "@", "#");
ServletOutputStream os = resp.getOutputStream();
IOUtils.copy(replacingIS, os);
replacingIS.close();
이것은 작동하지 않았습니다. 그것은 단지 대체하지 않습니다. 그래서 나는 "PHP 방식"에 의지했다. ...
String pomTemplate = IOUtils.toString(pomIS)
.replace("@[email protected]", artifactInfo.getGroup())
.replace("@[email protected]", artifactInfo.getName())
.replace("@[email protected]", artifactInfo.getVersion())
.replace("@[email protected]", artifactInfo.getPackaging())
.replace("@[email protected]", artifactInfo.getFileName())
.replace("@[email protected]", req.getQueryString());
ServletOutputStream os = resp.getOutputStream();
IOUtils.copy(new StringInputStream(pomTemplate), os);
os.close();
작동.
무엇이 잘못 되었나요?
코드는 괜찮습니다. 디버거를 사용하여 코드를 넣을 수 있습니다. – Ron