private static void deauthorize()

in src/main/java/org/apache/creadur/tentacles/Deauthorize.java [104:155]


	private static void deauthorize(final File dir, final IOSystem io)
			throws IOException {
		for (final File file : new FileSystem().collect(dir, ".*\\.java")) {

			if (not(file.canRead(), "File not readable: %s",
					file.getAbsolutePath())) {
				continue;
			}

			final String text = io.slurp(file);

			// You really can't trust text to be in the native line ending
			final String eol = text.contains("\r\n") ? "\r\n" : "\n";
			final String startComment = eol + "/*";
			final String endComment = "*/" + eol;

			final InputStream baseIn = new ByteArrayInputStream(text.getBytes());

			// Yank author tags
			InputStream in = new ExcludeFilterInputStream(baseIn, " * @author",
					eol);

			// Clean "empty" comments
			in = new DelimitedTokenReplacementInputStream(in, startComment,
					endComment, new StringTokenHandler() {
						@Override
						public String handleToken(final String commentBlock) {

							// Yank if empty
							if (commentBlock.replaceAll("[\\s*]", "").isEmpty()) {
								return eol;
							}

							// Keep otherwise
							return startComment + commentBlock + endComment;
						}
					});

			final byte[] content = io.read(in);

			if (content.length != file.length()) {

				if (not(file.canWrite(), "File not writable: %s",
						file.getAbsolutePath())) {
					continue;
				}

				io.copy(content, file);
			}
		}

	}