Skip to content

Commit c1a820e

Browse files
committed
fixed compile
1 parent bd44c8d commit c1a820e

File tree

3 files changed

+13
-170
lines changed

3 files changed

+13
-170
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import java.util.regex.Matcher
22

33
apply plugin: 'java'
44

5-
sourceCompatibility = 1.5
6-
targetCompatibility = 1.5
5+
sourceCompatibility = 1.6
6+
targetCompatibility = 1.6
77
version = '1.0'
88
[compileJava,compileTestJava,javadoc]*.options*.encoding = 'UTF-8'
99

src/main/java/qiniu/ip17mon/Locator.java

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package qiniu.ip17mon;
22

3-
import java.io.File;
4-
import java.io.FileInputStream;
5-
import java.io.IOException;
6-
import java.io.InputStream;
3+
import java.io.*;
74
import java.net.HttpURLConnection;
85
import java.net.URL;
96
import java.nio.charset.Charset;
107
import java.util.InputMismatchException;
118

129
public final class Locator implements ILocator {
13-
public static final String VERSION = "0.1.1";
10+
public static final String VERSION = "0.1.2";
1411
private static final Charset Utf8 = Charset.forName("UTF-8");
1512
private final byte[] ipData;
1613
private final int textOffset;
@@ -154,29 +151,20 @@ public static Locator loadFromLocal(String filePath) throws IOException {
154151

155152
return loadBinary(b);
156153
}
157-
158-
public static Locator loadFromHDFS(String dfsPath) throws Exception {
159-
Configuration conf = new Configuration();
160-
FileSystem fs = FileSystem.get(conf);
161154

155+
public static Locator loadFromStream(InputStream in) throws Exception {
162156
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
157+
byte[] buffer = new byte[16 * 1024];
158+
while (in.read(buffer) != -1) {
159+
byteArrayOutputStream.write(buffer);
160+
}
163161

164-
Path filePath = new Path(dfsPath);
165-
166-
if(fs.exists(filePath)){
167-
FSDataInputStream in = fs.open(filePath);
168-
byte[] buffer = new byte[1];
162+
int n = 0;
169163

170-
while (in.read(buffer) != -1){
171-
byteArrayOutputStream.write(buffer);
172-
}
173-
} else {
174-
throw new Exception("File does not exists!");
164+
while ((n = in.read(buffer)) != -1) {
165+
byteArrayOutputStream.write(buffer, 0, n);
175166
}
176167

177-
// Using in Spark, don't close it.
178-
//fs.close();
179-
180168
return loadBinary(byteArrayOutputStream.toByteArray());
181169
}
182170

@@ -260,7 +248,7 @@ public void checkDb() throws IOException {
260248
find(addr);
261249
}
262250
} catch (Exception e) {
263-
throw new IOException(e);
251+
throw new IOException(e.getMessage());
264252
}
265253
}
266254
}

src/test/java/qiniu/ip17mon/AnotherLocator.java

Lines changed: 0 additions & 145 deletions
This file was deleted.

0 commit comments

Comments
 (0)