This commit is contained in:
boy0001
2015-09-11 20:09:22 +10:00
parent 37a8861fa0
commit c386f33df8
380 changed files with 43490 additions and 33913 deletions

View File

@ -24,7 +24,8 @@ import com.intellectualcrafters.configuration.MemoryConfiguration;
* This is a base class for all File based implementations of {@link
* Configuration}
*/
public abstract class FileConfiguration extends MemoryConfiguration {
public abstract class FileConfiguration extends MemoryConfiguration
{
/**
* This value specified that the system default encoding should be
* completely ignored, as it cannot handle the ASCII character set, or it
@ -49,7 +50,8 @@ public abstract class FileConfiguration extends MemoryConfiguration {
*/
@Deprecated
public static final boolean SYSTEM_UTF;
static {
static
{
final byte[] testBytes = Base64Coder.decode("ICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVpbXF1eX2BhYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ent8fX4NCg==");
final String testString = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\r\n";
final Charset defaultCharset = Charset.defaultCharset();
@ -63,7 +65,8 @@ public abstract class FileConfiguration extends MemoryConfiguration {
/**
* Creates an empty {@link FileConfiguration} with no default values.
*/
public FileConfiguration() {
public FileConfiguration()
{
super();
}
@ -73,7 +76,8 @@ public abstract class FileConfiguration extends MemoryConfiguration {
*
* @param defaults Default value provider
*/
public FileConfiguration(Configuration defaults) {
public FileConfiguration(final Configuration defaults)
{
super(defaults);
}
@ -92,17 +96,21 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* any reason.
* @throws IllegalArgumentException Thrown when file is null.
*/
public void save(File file) throws IOException {
if (file == null) throw new NullPointerException("File cannot be null");
public void save(final File file) throws IOException
{
if (file == null) { throw new NullPointerException("File cannot be null"); }
file.getParentFile().mkdirs();
String data = saveToString();
final String data = saveToString();
Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF8_OVERRIDE && !UTF_BIG ? StandardCharsets.UTF_8 : Charset.defaultCharset());
final Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF8_OVERRIDE && !UTF_BIG ? StandardCharsets.UTF_8 : Charset.defaultCharset());
try {
try
{
writer.write(data);
} finally {
}
finally
{
writer.close();
}
}
@ -122,8 +130,9 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* any reason.
* @throws IllegalArgumentException Thrown when file is null.
*/
public void save(String file) throws IOException {
if (file == null) throw new NullPointerException("File cannot be null");
public void save(final String file) throws IOException
{
if (file == null) { throw new NullPointerException("File cannot be null"); }
save(new File(file));
}
@ -157,8 +166,9 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* a valid Configuration.
* @throws IllegalArgumentException Thrown when file is null.
*/
public void load(File file) throws IOException, InvalidConfigurationException {
if (file == null) throw new NullPointerException("File cannot be null");
public void load(final File file) throws IOException, InvalidConfigurationException
{
if (file == null) { throw new NullPointerException("File cannot be null"); }
final FileInputStream stream = new FileInputStream(file);
@ -184,8 +194,9 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* @see #load(Reader)
*/
@Deprecated
public void load(InputStream stream) throws IOException, InvalidConfigurationException {
if (stream == null) throw new NullPointerException("Stream cannot be null");
public void load(final InputStream stream) throws IOException, InvalidConfigurationException
{
if (stream == null) { throw new NullPointerException("Stream cannot be null"); }
load(new InputStreamReader(stream, UTF8_OVERRIDE ? StandardCharsets.UTF_8 : Charset.defaultCharset()));
}
@ -203,19 +214,24 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* represent a valid Configuration
* @throws IllegalArgumentException thrown when reader is null
*/
public void load(Reader reader) throws IOException, InvalidConfigurationException {
BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
public void load(final Reader reader) throws IOException, InvalidConfigurationException
{
final BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
StringBuilder builder = new StringBuilder();
final StringBuilder builder = new StringBuilder();
try {
try
{
String line;
while ((line = input.readLine()) != null) {
while ((line = input.readLine()) != null)
{
builder.append(line);
builder.append('\n');
}
} finally {
}
finally
{
input.close();
}
@ -240,8 +256,9 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* a valid Configuration.
* @throws IllegalArgumentException Thrown when file is null.
*/
public void load(String file) throws IOException, InvalidConfigurationException {
if (file == null) throw new NullPointerException("File cannot be null");
public void load(final String file) throws IOException, InvalidConfigurationException
{
if (file == null) { throw new NullPointerException("File cannot be null"); }
load(new File(file));
}
@ -261,7 +278,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
* invalid.
* @throws IllegalArgumentException Thrown if contents is null.
*/
public abstract void loadFromString(String contents) throws InvalidConfigurationException;
public abstract void loadFromString(final String contents) throws InvalidConfigurationException;
/**
* Compiles the header for this {@link FileConfiguration} and returns the
@ -276,11 +293,13 @@ public abstract class FileConfiguration extends MemoryConfiguration {
protected abstract String buildHeader();
@Override
public FileConfigurationOptions options() {
if (options == null) {
public FileConfigurationOptions options()
{
if (options == null)
{
options = new FileConfigurationOptions(this);
}
return (FileConfigurationOptions) options;
}
}
}