Я пытался использовать библиотеку 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[][]{
{"@GRP@", artifactInfo.getGroup() },
{"@ART@", artifactInfo.getName() },
{"@VER@", artifactInfo.getVersion() },
{"@PACK@", artifactInfo.getPackaging() },
{"@NAME@", artifactInfo.getFileName() },
{"@DESC@", req.getQueryString() },
} );
// This does not replace anything, no idea why. //
ReplaceStringsInputStream replacingIS = new ReplaceStringsInputStream(pomIS, map);
ReplaceStringInputStream replacingIS2 = new ReplaceStringInputStream(pomIS, "@VER@", "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("@GRP@", artifactInfo.getGroup() )
.replace("@ART@", artifactInfo.getName() )
.replace("@VER@", artifactInfo.getVersion() )
.replace("@PACK@", artifactInfo.getPackaging() )
.replace("@NAME@", artifactInfo.getFileName() )
.replace("@DESC@", req.getQueryString() );
ServletOutputStream os = resp.getOutputStream();
IOUtils.copy( new StringInputStream(pomTemplate), os );
os.close();
Работает.
Что не так?