Browse Source

modify some codes

master
xiaowuler 3 years ago
parent
commit
5f7a18392b
  1. 19
      04.系统编码/03.radar-resolver/radar-core/src/main/java/com/xiaowuler/radar/core/custom/impl/CustomRadarInputStream.java
  2. 9
      04.系统编码/03.radar-resolver/radar-core/src/main/java/com/xiaowuler/radar/core/weather/domain/RadialBlock.java
  3. 2
      04.系统编码/03.radar-resolver/radar-test/src/test/java/com/xiaowuler/radartest/RadarTestApplicationTests.java

19
04.系统编码/03.radar-resolver/radar-core/src/main/java/com/xiaowuler/radar/core/custom/impl/CustomRadarInputStream.java

@ -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;
}
}

9
04.系统编码/03.radar-resolver/radar-core/src/main/java/com/xiaowuler/radar/core/weather/domain/RadialBlock.java

@ -1,5 +1,6 @@
package com.xiaowuler.radar.core.weather.domain;
import java.io.EOFException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -19,8 +20,12 @@ public class RadialBlock {
public RadialBlock(ICustomInputStream ICustomInputStream) throws IOException {
this.radials = new ArrayList<>();
while (ICustomInputStream.available() > 0){
this.radials.add(new Radial(ICustomInputStream));
try{
while (true){
this.radials.add(new Radial(ICustomInputStream));
}
}catch (EOFException e){
}
}
}

2
04.系统编码/03.radar-resolver/radar-test/src/test/java/com/xiaowuler/radartest/RadarTestApplicationTests.java

@ -11,7 +11,7 @@ class RadarTestApplicationTests {
@Test
void contextLoads() throws RadarReadException {
RadarReader radarReader = new RadarReader();
radarReader.read("C:\\SaveFile\\Source\\202203\\RADAR\\SAD\\CAP\\Z_RADR_I_Z9558_20220321065017_O_DOR_SAD_CAP_FMT.bin.bz2");
radarReader.read("C:\\Users\\xiaowuler\\Desktop\\test\\Z_RADR_I_Z9551_20210712000134_O_DOR_SA_CAP_FMT.bin.bz2");
System.out.println("");
}

Loading…
Cancel
Save