Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert tabs to spaces tools folder #899

Closed
wants to merge 1 commit into from
Closed
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
194 changes: 97 additions & 97 deletions src/freenet/tools/AddRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,108 +20,108 @@

public class AddRef {

/**
* Connects to a FCP server and adds a reference
* @param args
*/
public static void main(String[] args) {
if(args.length < 1){
System.err.println("Please provide a file name as the first argument.");
System.exit(-1);
}

final File reference = new File(args[0]);
if((reference == null) || !(reference.isFile()) || !(reference.canRead())){
System.err.println("Please provide a file name as the first argument.");
System.exit(-1);
}

new AddRef(reference);
}

AddRef(File reference){
Socket fcpSocket = null;

FCPMessage fcpm;
SimpleFieldSet sfs = new SimpleFieldSet(true);

try{
fcpSocket = new Socket("127.0.0.1", FCPServer.DEFAULT_FCP_PORT);
fcpSocket.setSoTimeout(2000);

InputStream is = fcpSocket.getInputStream();
LineReadingInputStream lis = new LineReadingInputStream(is);
OutputStream os = fcpSocket.getOutputStream();

try{
sfs.putSingle("Name", "AddRef");
sfs.putSingle("ExpectedVersion", "2.0");
fcpm = FCPMessage.create("ClientHello", sfs);
fcpm.send(os);
os.flush();

String messageName = lis.readLine(128, 128, true);
sfs = getMessage(lis);
fcpm = FCPMessage.create(messageName, sfs);
if((fcpm == null) || !(fcpm instanceof NodeHelloMessage)){
System.err.println("Not a valid FRED node!");
System.exit(1);
}
} catch(MessageInvalidException me){
me.printStackTrace();
}
try{
sfs = SimpleFieldSet.readFrom(reference, false, true);
fcpm = FCPMessage.create(AddPeer.NAME, sfs);
fcpm.send(os);
os.flush();

// TODO: We ought to do stricter checking!
// FIXME: some checks even
} catch(MessageInvalidException me){
System.err.println("Invalid reference file!"+me);
me.printStackTrace();
}

lis.close();
is.close();
os.close();
fcpSocket.close();
System.out.println("That reference has been added");
}catch (SocketException se){
System.err.println(se);
se.printStackTrace();
System.exit(1);
}catch (IOException ioe){
System.err.println(ioe);
ioe.printStackTrace();
System.exit(2);
}finally {
try{
Thread.sleep(3000);
}catch (InterruptedException e) {}
}
}
/**
* Connects to a FCP server and adds a reference
* @param args
*/
public static void main(String[] args) {
if(args.length < 1){
System.err.println("Please provide a file name as the first argument.");
System.exit(-1);
}

final File reference = new File(args[0]);
if((reference == null) || !(reference.isFile()) || !(reference.canRead())){
System.err.println("Please provide a file name as the first argument.");
System.exit(-1);
}

new AddRef(reference);
}

AddRef(File reference){
Socket fcpSocket = null;

FCPMessage fcpm;
SimpleFieldSet sfs = new SimpleFieldSet(true);

try{
fcpSocket = new Socket("127.0.0.1", FCPServer.DEFAULT_FCP_PORT);
fcpSocket.setSoTimeout(2000);

InputStream is = fcpSocket.getInputStream();
LineReadingInputStream lis = new LineReadingInputStream(is);
OutputStream os = fcpSocket.getOutputStream();

try{
sfs.putSingle("Name", "AddRef");
sfs.putSingle("ExpectedVersion", "2.0");
fcpm = FCPMessage.create("ClientHello", sfs);
fcpm.send(os);
os.flush();

String messageName = lis.readLine(128, 128, true);
sfs = getMessage(lis);
fcpm = FCPMessage.create(messageName, sfs);
if((fcpm == null) || !(fcpm instanceof NodeHelloMessage)){
System.err.println("Not a valid FRED node!");
System.exit(1);
}
} catch(MessageInvalidException me){
me.printStackTrace();
}
try{
sfs = SimpleFieldSet.readFrom(reference, false, true);
fcpm = FCPMessage.create(AddPeer.NAME, sfs);
fcpm.send(os);
os.flush();

// TODO: We ought to do stricter checking!
// FIXME: some checks even
} catch(MessageInvalidException me){
System.err.println("Invalid reference file!"+me);
me.printStackTrace();
}

lis.close();
is.close();
os.close();
fcpSocket.close();
System.out.println("That reference has been added");
}catch (SocketException se){
System.err.println(se);
se.printStackTrace();
System.exit(1);
}catch (IOException ioe){
System.err.println(ioe);
ioe.printStackTrace();
System.exit(2);
}finally {
try{
Thread.sleep(3000);
}catch (InterruptedException e) {}
}
}

/**
*
* @param lis
* @return
*/
protected SimpleFieldSet getMessage(LineReadingInputStream lis){
SimpleFieldSet sfs = new SimpleFieldSet(true);
try {
while(lis.available()>0){
String line = lis.readLine(128, 128, true);
int index = line.indexOf('=');
if(index == -1 || line.startsWith("End")) return sfs;
sfs.putSingle(line.substring(0, index), line.substring(index+1));
}
}catch(IOException e){
return sfs;
}

return sfs;
}
SimpleFieldSet sfs = new SimpleFieldSet(true);
try {
while(lis.available()>0){
String line = lis.readLine(128, 128, true);
int index = line.indexOf('=');
if(index == -1 || line.startsWith("End")) return sfs;
sfs.putSingle(line.substring(0, index), line.substring(index+1));
}
}catch(IOException e){
return sfs;
}

return sfs;
}
}
126 changes: 63 additions & 63 deletions src/freenet/tools/CleanupTranslations.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,68 @@

public class CleanupTranslations {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException, LoggerHook.InvalidThresholdException {
Logger.setupStdoutLogging(Logger.LogLevel.ERROR, "");
File engFile = new File("src/freenet/l10n/freenet.l10n.en.properties");
SimpleFieldSet english = SimpleFieldSet.readFrom(engFile, false, true);
File[] translations = new File("src/freenet/l10n").listFiles();
for(File f : translations) {
String name = f.getName();
if(!name.startsWith("freenet.l10n.")) continue;
if(name.equals("freenet.1l0n.en.properties")) continue;
FileInputStream fis = new FileInputStream(f);
InputStreamReader isr = new InputStreamReader(new BufferedInputStream(fis), StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(isr);
StringWriter sw = new StringWriter();
boolean changed = false;
while(true) {
String line = br.readLine();
if(line == null) {
System.err.println("File does not end in End: "+f);
System.exit(4);
}
int idx = line.indexOf('=');
if(idx == -1) {
// Last line
if(!line.equals("End")) {
System.err.println("Line with no equals (file does not end in End???): "+f+" - \""+line+"\"");
System.exit(1);
}
sw.append(line+"\n");
line = br.readLine();
if(line != null) {
System.err.println("Content after End: \""+line+"\"");
System.exit(2);
}
break;
}
String before = line.substring(0, idx);
//String after = line.substring(idx+1);
String s = english.get(before);
if(s == null) {
System.err.println("Orphaned string: \""+before+"\" in "+f);
changed = true;
continue;
}
sw.append(line+"\n");
}
Closer.close(fis);
Closer.close(isr);
Closer.close(br);
if(!changed) continue;
FileOutputStream fos = new FileOutputStream(f);
OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
try {
osw.write(sw.toString());
} finally {
osw.close();
}
System.out.println("Rewritten "+f);
}
}
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException, LoggerHook.InvalidThresholdException {
Logger.setupStdoutLogging(Logger.LogLevel.ERROR, "");
File engFile = new File("src/freenet/l10n/freenet.l10n.en.properties");
SimpleFieldSet english = SimpleFieldSet.readFrom(engFile, false, true);
File[] translations = new File("src/freenet/l10n").listFiles();
for(File f : translations) {
String name = f.getName();
if(!name.startsWith("freenet.l10n.")) continue;
if(name.equals("freenet.1l0n.en.properties")) continue;
FileInputStream fis = new FileInputStream(f);
InputStreamReader isr = new InputStreamReader(new BufferedInputStream(fis), StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(isr);
StringWriter sw = new StringWriter();
boolean changed = false;
while(true) {
String line = br.readLine();
if(line == null) {
System.err.println("File does not end in End: "+f);
System.exit(4);
}
int idx = line.indexOf('=');
if(idx == -1) {
// Last line
if(!line.equals("End")) {
System.err.println("Line with no equals (file does not end in End???): "+f+" - \""+line+"\"");
System.exit(1);
}
sw.append(line+"\n");
line = br.readLine();
if(line != null) {
System.err.println("Content after End: \""+line+"\"");
System.exit(2);
}
break;
}
String before = line.substring(0, idx);
//String after = line.substring(idx+1);
String s = english.get(before);
if(s == null) {
System.err.println("Orphaned string: \""+before+"\" in "+f);
changed = true;
continue;
}
sw.append(line+"\n");
}
Closer.close(fis);
Closer.close(isr);
Closer.close(br);
if(!changed) continue;
FileOutputStream fos = new FileOutputStream(f);
OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
try {
osw.write(sw.toString());
} finally {
osw.close();
}
System.out.println("Rewritten "+f);
}
}

}
Loading
Loading