Browse files

small optimization

  • Loading branch information...
1 parent 492471e commit 6298021a6a82430fe16d7b4db89593d3cfb4406c pod2g committed May 7, 2012
Showing with 8 additions and 4 deletions.
  1. +8 −4 tiny-shell-client/Main.java
View
12 tiny-shell-client/Main.java
@@ -5,6 +5,7 @@
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
public class Main {
private String host;
@@ -41,6 +42,7 @@ public void upload(String lpath, String rpath, int mods) throws IOException {
writeString(rpath);
writeUInt32(mods);
File f = new File(lpath);
+ if (!f.exists()) throw new FileNotFoundException("File does not exists: " + f.getAbsolutePath());
writeUInt32((int) f.length()); // sorry, I know casting from long to int sucks...
byte[] buf = new byte[1024];
int c;
@@ -57,10 +59,12 @@ public void upload(String lpath, String rpath, int mods) throws IOException {
}
private void writeUInt32(int i) throws IOException {
- this.out.write((byte) ((i) & 0xff));
- this.out.write((byte) ((i >> 8) & 0xff));
- this.out.write((byte) ((i >> 16) & 0xff));
- this.out.write((byte) ((i >> 24) & 0xff));
+ byte[] b = new byte[4];
+ b[0] = (byte) ((i) & 0xff);
+ b[1] = (byte) ((i >> 8) & 0xff);
+ b[2] = (byte) ((i >> 16) & 0xff);
+ b[3] = (byte) ((i >> 24) & 0xff);
+ this.out.write(b);
}
private void writeString(String s) throws IOException {

0 comments on commit 6298021

Please sign in to comment.