|
|
@ -22,13 +22,15 @@ import com.xiaowuler.radar.core.custom.ICustomInputStream; |
|
|
|
*/ |
|
|
|
public class CustomRadarInputStream implements ICustomInputStream, Closeable{ |
|
|
|
|
|
|
|
private long pos = 0; |
|
|
|
private long available = 0; |
|
|
|
private static final String BZIP_SUFFIX = "bz2"; |
|
|
|
private static final String BIN_SUFFIX = "bin"; |
|
|
|
|
|
|
|
private InputStream inputStream; |
|
|
|
private FileInputStream fileInputStream; |
|
|
|
|
|
|
|
public CustomRadarInputStream(String filepath) throws FileNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { |
|
|
|
public CustomRadarInputStream(String filepath) throws IOException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { |
|
|
|
String fileSuffix = filepath.substring(filepath.lastIndexOf(".") + 1).trim().toLowerCase(Locale.ROOT); |
|
|
|
|
|
|
|
switch (fileSuffix){ |
|
|
@ -43,13 +45,15 @@ public class CustomRadarInputStream implements ICustomInputStream, Closeable{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private <T extends InputStream> void customRadarInputStream(String filepath, Class<T> clazz) throws NoSuchMethodException, FileNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException { |
|
|
|
private <T extends InputStream> void customRadarInputStream(String filepath, Class<T> clazz) throws NoSuchMethodException, IOException, InvocationTargetException, InstantiationException, IllegalAccessException { |
|
|
|
fileInputStream = new FileInputStream(filepath); |
|
|
|
available = new File(filepath).length(); |
|
|
|
inputStream = clazz.getConstructor(InputStream.class).newInstance(fileInputStream); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int readInt() throws IOException { |
|
|
|
// addPos(4);
|
|
|
|
int ch1 = inputStream.read(); |
|
|
|
int ch2 = inputStream.read(); |
|
|
|
int ch3 = inputStream.read(); |
|
|
@ -70,12 +74,14 @@ public class CustomRadarInputStream implements ICustomInputStream, Closeable{ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public short readShort() throws IOException{ |
|
|
|
// addPos(2);
|
|
|
|
byte[] bytes = inputStream.readNBytes(2); |
|
|
|
return ByteUtils.bytes2Short(bytes); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public long readLong() throws IOException{ |
|
|
|
// addPos(8);
|
|
|
|
byte[] bytes = inputStream.readNBytes(8); |
|
|
|
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); |
|
|
|
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); |
|
|
@ -84,17 +90,20 @@ public class CustomRadarInputStream implements ICustomInputStream, Closeable{ |
|
|
|
|
|
|
|
@Override |
|
|
|
public float readFloat() throws IOException { |
|
|
|
// addPos(4);
|
|
|
|
return Float.intBitsToFloat(readInt()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public byte[] readNBytes(int len) throws IOException{ |
|
|
|
// addPos(len);
|
|
|
|
return inputStream.readNBytes(len); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int available() throws IOException { |
|
|
|
return inputStream.available(); |
|
|
|
return (int)(available - pos); |
|
|
|
// return fileInputStream.available();
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -115,4 +124,8 @@ public class CustomRadarInputStream implements ICustomInputStream, Closeable{ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private synchronized void addPos(int len){ |
|
|
|
pos += len; |
|
|
|
} |
|
|
|
} |
|
|
|