Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final Charset UTF8 = Charset.forName("UTF-8");
- private static final Pattern HEADER_PATTERN =
- Pattern.compile("<tag>\s<meta [^>]*>\s</tag>", Pattern.MULTILINE);
- FileInputStream input = new FileInputStream(inputFile);
- FileChannel channel = input.getChannel();
- ByteBuffer bbuf = channel.map(FileChannel.MapMode.READ_ONLY,
- 0, (int) channel.size());
- CharBuffer cbuf = UTF8.newDecoder().decode(bbuf);
- Matcher matcher = HEADER_PATTERN.matcher(cbuf);
- StringBuffer sb = new StringBuffer();
- while (matcher.find()) {
- matcher.appendReplacement(sb, "Some replacement text");
- }
- matcher.appendTail(sb);
- IOUtils.closeQuietly(input);
- IOUtils.write(sb, new FileOutputStream(inputFile), UTF8);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement