Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ public boolean equals(Object obj) {
return cm.getImmutableGlobalProperties().equals(getImmutableGlobalProperties());
}

@Override
public int hashCode() {
return super.hashCode();
}

@Override
protected <T extends Configurable> ServablePropertySheet<T> createPropertySheet(T conf, ConfigurationManager cm, ConfigurationData rpd) {
return new ServablePropertySheet<>(conf,(JiniConfigurationManager)cm,rpd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ public ConfigurationEntry[] getEntries() {
return entries;
}

@Override
public boolean equals(Object other) {
return super.equals(other);
}

@Override
public int hashCode() {
return super.hashCode();
}

@Override
public synchronized T getOwner(ComponentListener<T> cl, boolean reuseComponent) {
if (!isInstantiated() || !reuseComponent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -41,6 +42,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -161,7 +163,7 @@ public CommandInterpreter(String inputFile) throws java.io.IOException {
if(inputFile == null) {
setupJLine();
} else {
in = new BufferedReader(new FileReader(inputFile));
in = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile), StandardCharsets.UTF_8));
inputIsFile = true;
}
out = System.out;
Expand Down Expand Up @@ -200,7 +202,7 @@ protected void setupJLine() {
consoleReader = lineBuilder.build();
} catch(IOException e) {
logger.info("Failed to load JLine, falling back to System.in");
in = new BufferedReader(new InputStreamReader(System.in));
in = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
}
}

Expand Down Expand Up @@ -1060,7 +1062,7 @@ public boolean load(String filename) {
}

public boolean load(File file) {
try (BufferedReader br = new BufferedReader(new FileReader(file))){
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))){
String inputLine;

while((inputLine = br.readLine()) != null) {
Expand All @@ -1085,7 +1087,7 @@ public boolean pload(String filename, int numThreads) {

public boolean pload(File file, int numThreads) {
ExecutorService exec = Executors.newFixedThreadPool(numThreads);
try (BufferedReader br = new BufferedReader(new FileReader(file))){
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))){
String inputLine;

while((inputLine = br.readLine()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1148,12 +1148,12 @@ public void overrideConfigurableProperty(String componentName, String propertyNa
public synchronized void close() { }

/**
* Get any unnamed arguments that weren't parsed into an {@link Options}
* Get a copy of any unnamed arguments that weren't parsed into an {@link Options}
* instance, or used to override a {@link Configurable} field.
* @return A string array of command line arguments.
*/
public String[] getUnnamedArguments() {
return unnamedArguments;
return Arrays.copyOf(unnamedArguments,unnamedArguments.length);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,11 @@ public static void writeExampleConfig(OutputStream stream, String fileFormat, Cl
FieldInfo fi = e.getValue();
switch (fi.type) {
case NORMAL:
case ENUM:
properties.put(e.getKey(),new SimpleProperty(generateDefaultValue(fi)));
break;
case LIST:
case ENUM_LIST:
properties.put(e.getKey(),new ListProperty(Collections.singletonList(new SimpleProperty(fi.className + "-instance"))));
break;
case MAP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -94,7 +96,7 @@ public enum FieldType {
private static final Class<?> configurableArrayClass = Configurable[].class;
private static final Class<?> enumClass = Enum.class;

private final Class<?>[] types;
private final List<Class<?>> types;

private final static Map<Class<?>,FieldType> m = new HashMap<>();

Expand All @@ -115,7 +117,7 @@ public enum FieldType {
public final static EnumSet<FieldType> configurableTypes = EnumSet.of(CONFIGURABLE,CONFIGURABLE_ARRAY);

FieldType(Class<?>... types) {
this.types = types;
this.types = Collections.unmodifiableList(Arrays.asList(types));
}

static {
Expand Down Expand Up @@ -143,7 +145,7 @@ public static FieldType getFieldType(Field f) {
return getFieldType(fieldClass);
}

public Class<?>[] getTypes() {
public List<Class<?>> getTypes() {
return types;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
Expand Down Expand Up @@ -270,8 +271,7 @@ public synchronized T getOwner(ComponentListener<T> cl, boolean reuseComponent)
if (serStream != null) {
try (ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(serStream, 1024 * 1024))) {
Object deser = ois.readObject();
owner = ownerClass.cast(deser);
return owner;
return ownerClass.cast(deser);
} catch (IOException ex) {
throw new PropertyException(ex, instanceName, null,
"Error reading serialized form from " + actualLocation);
Expand All @@ -285,6 +285,7 @@ public synchronized T getOwner(ComponentListener<T> cl, boolean reuseComponent)
}
);
if (obj != null) {
owner = obj;
return obj;
}
}
Expand Down Expand Up @@ -899,7 +900,7 @@ public Set<String> getRegisteredProperties() {
return Collections.unmodifiableSet(registeredProperties.keySet());
}

public void setCM(ConfigurationManager cm) {
public synchronized void setCM(ConfigurationManager cm) {
this.cm = cm;
}

Expand All @@ -917,6 +918,11 @@ public boolean equals(Object obj) {
return propValues.equals(ps.propValues);
}

@Override
public int hashCode() {
return Objects.hash(propValues);
}

public PropertySheet<T> copy() {
return new PropertySheet<>(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public String toString() {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!(o instanceof GlobalProperty)) return false;

GlobalProperty that = (GlobalProperty) o;
String tmpValue = getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ public String toString() {
return getValue();
}

@Override
public boolean equals(Object other) {
return super.equals(other);
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,6 @@ public void endElement(String uri, String localName, String qName)
rpd = null;
overriding = false;
break;
case PROPERTY:
// nothing to do
break;
case PROPERTYLIST:
if (rpd.contains(itemListName) && !overriding) {
throw new SAXParseException("Duplicate property: "
Expand Down Expand Up @@ -444,6 +441,9 @@ public void endElement(String uri, String localName, String qName)
entryMap = null;
}
break;
default:
// Nothing to do
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static String bytesToHexString(byte[] bytes) {
public static String hashList(HashType hashType, List<String> list) {
MessageDigest md = hashType.getDigest();
for (String curString : list) {
md.digest(curString.getBytes(StandardCharsets.UTF_8));
md.update(curString.getBytes(StandardCharsets.UTF_8));
}
return bytesToHexString(md.digest());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand All @@ -55,14 +56,20 @@ public static void deleteDirectory(File dir) {
return;
}
File[] fs = dir.listFiles();
for(File f : fs) {
if(f.isDirectory()) {
deleteDirectory(f);
} else {
f.delete();
if (fs != null) {
for (File f : fs) {
if (f.isDirectory()) {
deleteDirectory(f);
} else {
if (!f.delete()) {
logger.log(Level.INFO,"Failed to delete file: " + f.getName());
}
}
}
}
dir.delete();
if (!dir.delete()) {
logger.log(Level.INFO, "Failed to delete directory: " + dir.getName());
}
}

public static void dirCopier(File source, File target) throws IOException {
Expand All @@ -82,15 +89,17 @@ public static void dirCopier(File source, File target) throws IOException {

private static void copyDir(File sd, File td) throws java.io.IOException {
File[] files = sd.listFiles();
for(File f : files) {
File nt = new File(td, f.getName());
if(f.isDirectory()) {
if(!nt.mkdir()) {
throw new IOException("Failed to make dir " + nt.getName());
if (files != null) {
for (File f : files) {
File nt = new File(td, f.getName());
if (f.isDirectory()) {
if (!nt.mkdir()) {
throw new IOException("Failed to make dir " + nt.getName());
}
copyDir(f, nt);
} else {
copyFile(f, nt);
}
copyDir(f, nt);
} else {
copyFile(f, nt);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.io.PushbackInputStream;
import java.io.Serializable;
import java.io.UncheckedIOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -167,7 +168,7 @@ public static BufferedReader getReader(File file, String charSet) throws FileNot
* @throws IOException If an error occurred when opening the file.
*/
public static PrintWriter getPrintWriter(String filename, boolean zipped) throws FileNotFoundException, IOException {
return new PrintWriter(new OutputStreamWriter(innerGetOutputStream(filename,zipped)));
return new PrintWriter(new OutputStreamWriter(innerGetOutputStream(filename,zipped),StandardCharsets.UTF_8));
}

/**
Expand Down Expand Up @@ -373,7 +374,11 @@ public static PrintStream getPrintStream(File file, int bufferSize) throws FileN
file.getParentFile().mkdirs();
}
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file), bufferSize);
return new PrintStream(bos, false);
try {
return new PrintStream(bos, false, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("UTF-8 isn't supported. Not sure what's wrong with the world.",e);
}
}

public static OutputStream getOutputStream(String path) throws FileNotFoundException {
Expand Down
Loading