mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-11-15 10:20:47 +00:00
Fix risk of destruction/confusion from WriteTarget#getWriter
* WriteTarget.java, ReadSource.java
renamed Writer/Reader accessors to avoid bean-style 'get-' naming
improve comments
* ConfigFile.java, ConfigString.java, ScriptedProcessor.java, ScriptedDecideRule.java, SurtPrefixedDecideRule.java, TextSeedModule.java
reflect above change
This commit is contained in:
1 parent
e0d748cd3b
commit
ef0a9f89d4
8 files changed
+74
-15
No files matched your search
@@ -21,6 +21,17 @@ package org.archive.io;
|
||||
|
||||
import java.io.Reader;
|
||||
|
||||
/**
|
||||
* Interface for objects that can provide a Reader view of their
|
||||
* contents.
|
||||
*
|
||||
*/
|
||||
public interface ReadSource {
|
||||
Reader getReader();
|
||||
/**
|
||||
* Obtain a Reader. Not named 'getReader' so that it is not
|
||||
* considered a simple costless read-only property by
|
||||
* bean-convention introspection tools.
|
||||
* @return a Reader on this object
|
||||
*/
|
||||
Reader obtainReader();
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class ConfigFile extends ConfigPath implements ReadSource, WriteTarget {
|
||||
super(name, path);
|
||||
}
|
||||
|
||||
public Reader getReader() {
|
||||
public Reader obtainReader() {
|
||||
try {
|
||||
if(!getFile().exists()) {
|
||||
getFile().createNewFile();
|
||||
@@ -52,11 +52,11 @@ public class ConfigFile extends ConfigPath implements ReadSource, WriteTarget {
|
||||
}
|
||||
}
|
||||
|
||||
public Writer getWriter() {
|
||||
return getWriter(false);
|
||||
public Writer obtainWriter() {
|
||||
return obtainWriter(false);
|
||||
}
|
||||
|
||||
public Writer getWriter(boolean append) {
|
||||
public Writer obtainWriter(boolean append) {
|
||||
try {
|
||||
return new FileWriter(getFile(), append);
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -13,7 +13,7 @@ public class ConfigString implements ReadSource {
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
public Reader getReader() {
|
||||
public Reader obtainReader() {
|
||||
return new StringReader(value);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,56 @@
|
||||
/*
|
||||
* This file is part of the Heritrix web crawler (crawler.archive.org).
|
||||
*
|
||||
* Licensed to the Internet Archive (IA) by one or more individual
|
||||
* contributors.
|
||||
*
|
||||
* The IA licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.archive.spring;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Interface for objects that can provide a Writer for replacing or
|
||||
* appending to their textual contents.
|
||||
*
|
||||
*/
|
||||
public interface WriteTarget {
|
||||
Writer getWriter();
|
||||
Writer getWriter(boolean append);
|
||||
/**
|
||||
* Obtain a Writer for changing this object's contents. By default,
|
||||
* the Writer will replace the current contents.
|
||||
*
|
||||
* Note that the mere act of obtaining the Writer may (as in the
|
||||
* case of a backing file) truncate away all existing contents,
|
||||
* even before anything is written to the writer. Not named
|
||||
* 'getWriter' because of this potential destructiveness.
|
||||
*
|
||||
* @return a Writer for replacing the object's textual contents
|
||||
*/
|
||||
Writer obtainWriter();
|
||||
/**
|
||||
* Obtain a Writer for changing this object's contents. Whether
|
||||
* written text replaces or appends existing contents is controlled
|
||||
* by the 'append' parameter.
|
||||
*
|
||||
* Note that the mere act of obtaining the Writer may (as in the
|
||||
* case of a backing file) truncate away all existing contents,
|
||||
* even before anything is written to the writer. Not named
|
||||
* 'getWriter' because of this potential destructiveness.
|
||||
*
|
||||
* @param append if true, anything written will be appended to current contents
|
||||
* @return a Writer for replacing the object's textual contents
|
||||
*/
|
||||
Writer obtainWriter(boolean append);
|
||||
}
|
||||
Reference in new issue
Block a user