forked from phoedos/pmd
Replace IOUtils with IOUtil, Fix compile errors
This commit is contained in:
@ -6,8 +6,7 @@ package net.sourceforge.pmd.cpd.internal;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.apache.commons.io.input.CharSequenceReader;
|
||||
import java.io.StringReader;
|
||||
|
||||
import net.sourceforge.pmd.cpd.SourceCode;
|
||||
import net.sourceforge.pmd.cpd.TokenEntry;
|
||||
@ -26,7 +25,7 @@ public abstract class JavaCCTokenizer implements Tokenizer {
|
||||
|
||||
@SuppressWarnings("PMD.CloseResource")
|
||||
protected TokenManager<JavaccToken> getLexerForSource(SourceCode sourceCode) throws IOException {
|
||||
Reader reader = IOUtil.skipBOM(new CharSequenceReader(sourceCode.getCodeBuffer()));
|
||||
Reader reader = IOUtil.skipBOM(new StringReader(sourceCode.getCodeBuffer().toString()));
|
||||
return makeLexerImpl(makeCharStream(reader));
|
||||
}
|
||||
|
||||
|
@ -8,9 +8,8 @@ import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.CharStream;
|
||||
import net.sourceforge.pmd.util.IOUtil;
|
||||
|
||||
public final class CharStreamFactory {
|
||||
|
||||
@ -58,7 +57,7 @@ public final class CharStreamFactory {
|
||||
@Deprecated
|
||||
public static String toString(Reader dstream) {
|
||||
try (Reader r = dstream) {
|
||||
return IOUtils.toString(r);
|
||||
return IOUtil.readToString(r);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -12,9 +12,7 @@ import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.commons.io.ByteOrderMark;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.io.input.BOMInputStream;
|
||||
import net.sourceforge.pmd.util.IOUtil;
|
||||
|
||||
/**
|
||||
* Represents a source file to be analyzed. Different implementations can get
|
||||
@ -59,10 +57,10 @@ public interface DataSource extends Closeable {
|
||||
String fullSource;
|
||||
try (InputStream stream = dataSource.getInputStream();
|
||||
// Skips the byte-order mark
|
||||
BOMInputStream bomIs = new BOMInputStream(stream, ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE);
|
||||
IOUtil.BomAwareInputStream bomIs = new IOUtil.BomAwareInputStream(stream);
|
||||
Reader reader = new InputStreamReader(bomIs, sourceEncoding)) {
|
||||
|
||||
fullSource = IOUtils.toString(reader); // this already buffers properly
|
||||
fullSource = IOUtil.readToString(reader); // this already buffers properly
|
||||
}
|
||||
return fullSource;
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
|
||||
import net.sourceforge.pmd.annotation.Experimental;
|
||||
@ -32,6 +31,7 @@ import net.sourceforge.pmd.lang.ast.SemanticErrorReporter;
|
||||
import net.sourceforge.pmd.lang.rule.xpath.Attribute;
|
||||
import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.properties.PropertySource;
|
||||
import net.sourceforge.pmd.util.IOUtil;
|
||||
|
||||
import com.beust.jcommander.DynamicParameter;
|
||||
import com.beust.jcommander.JCommander;
|
||||
@ -200,7 +200,7 @@ public class TreeExportCli {
|
||||
Slf4jSimpleConfiguration.disableLogging(Attribute.class);
|
||||
|
||||
try {
|
||||
String fullSource = IOUtils.toString(source);
|
||||
String fullSource = IOUtil.readToString(source);
|
||||
ParserTask task = new ParserTask(langVersion, fileName, fullSource, SemanticErrorReporter.noop());
|
||||
RootNode root = parser.parse(task);
|
||||
|
||||
|
@ -22,7 +22,6 @@ import org.junit.contrib.java.lang.system.RestoreSystemProperties;
|
||||
import org.junit.rules.TestRule;
|
||||
|
||||
import net.sourceforge.pmd.internal.Slf4jSimpleConfiguration;
|
||||
|
||||
import net.sourceforge.pmd.util.IOUtil;
|
||||
|
||||
public class PMDTaskTest {
|
||||
|
@ -12,9 +12,10 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.util.IOUtil;
|
||||
|
||||
/**
|
||||
* @author Philippe T'Seyen
|
||||
*/
|
||||
@ -56,7 +57,7 @@ public class FileReporterTest {
|
||||
|
||||
private String readFile(File file) throws IOException {
|
||||
try (Reader reader = new FileReader(file)) {
|
||||
String text = IOUtils.toString(reader);
|
||||
String text = IOUtil.readToString(reader);
|
||||
return text.replaceAll("\\R", "\n");
|
||||
}
|
||||
}
|
||||
|
@ -19,5 +19,4 @@ public final class HtmlParser implements net.sourceforge.pmd.lang.ast.Parser {
|
||||
HtmlTreeBuilder builder = new HtmlTreeBuilder();
|
||||
return builder.build(doc, data, task, new HashMap<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsStringIgnoringCase;
|
||||
import static org.hamcrest.Matchers.emptyString;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -17,7 +18,6 @@ import java.util.logging.Handler;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.StreamHandler;
|
||||
|
||||
import org.apache.commons.io.output.ByteArrayOutputStream;
|
||||
import org.junit.contrib.java.lang.system.SystemErrRule;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
@ -121,7 +121,7 @@ public class JavaUtilLoggingRule implements TestRule {
|
||||
*/
|
||||
public String getLog() {
|
||||
customLogHandler.flush();
|
||||
return stream.toString(StandardCharsets.UTF_8);
|
||||
return new String(stream.toByteArray(), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user