Advertisement
Guest User

Untitled

a guest
Mar 26th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. private static final Charset UTF8 = Charset.forName("UTF-8");
  2. private static final Pattern HEADER_PATTERN =
  3. Pattern.compile("<tag>\s<meta [^>]*>\s</tag>", Pattern.MULTILINE);
  4.  
  5. FileInputStream input = new FileInputStream(inputFile);
  6. FileChannel channel = input.getChannel();
  7. ByteBuffer bbuf = channel.map(FileChannel.MapMode.READ_ONLY,
  8. 0, (int) channel.size());
  9. CharBuffer cbuf = UTF8.newDecoder().decode(bbuf);
  10. Matcher matcher = HEADER_PATTERN.matcher(cbuf);
  11. StringBuffer sb = new StringBuffer();
  12. while (matcher.find()) {
  13. matcher.appendReplacement(sb, "Some replacement text");
  14. }
  15. matcher.appendTail(sb);
  16. IOUtils.closeQuietly(input);
  17. IOUtils.write(sb, new FileOutputStream(inputFile), UTF8);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement