use of com.revolsys.spring.resource.InputStreamResource in project com.revolsys.open by revolsys.
the class UsgsGriddedElevationReader method getChannel.
protected ReadableByteChannel getChannel() {
final String fileExtension = this.resource.getFileNameExtension();
try {
if (fileExtension.equals("zip")) {
final ZipInputStream in = this.resource.newBufferedInputStream(ZipInputStream::new);
final String fileName = this.resource.getBaseName();
final String baseName = FileUtil.getBaseName(fileName);
final String projName = baseName + ".prj";
for (ZipEntry zipEntry = in.getNextEntry(); zipEntry != null; zipEntry = in.getNextEntry()) {
final String name = zipEntry.getName();
if (name.equals(projName)) {
final String wkt = FileUtil.getString(new InputStreamReader(in, StandardCharsets.UTF_8), false);
final GeometryFactory geometryFactory = GeometryFactory.floating3d(wkt);
if (geometryFactory.isHasCoordinateSystem()) {
this.geometryFactory = geometryFactory;
}
} else if (name.equals(fileName)) {
return new InputStreamResource(in).newReadableByteChannel();
}
}
throw new IllegalArgumentException("Cannot find " + fileName + " in " + this.resource);
} else if (fileExtension.equals("gz")) {
final String baseName = this.resource.getBaseName();
setGeometryFactory(this.resource.getParent().newChildResource(baseName));
final InputStream in = this.resource.newBufferedInputStream();
final GZIPInputStream gzIn = new GZIPInputStream(in);
return new InputStreamResource(gzIn).newReadableByteChannel();
} else {
setGeometryFactory(this.resource);
return this.resource.newReadableByteChannel();
}
} catch (final IOException e) {
throw Exceptions.wrap("Unable to open: " + this.resource, e);
}
}
use of com.revolsys.spring.resource.InputStreamResource in project com.revolsys.open by revolsys.
the class RecordReaderHttpMessageConverter method read.
@Override
public RecordReader read(final Class<? extends RecordReader> clazz, final HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
try {
final HttpHeaders headers = inputMessage.getHeaders();
final MediaType mediaType = headers.getContentType();
Charset charset = mediaType.getCharSet();
if (charset == null) {
charset = StandardCharsets.UTF_8;
}
final InputStream body = inputMessage.getBody();
final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
final RecordReaderFactory readerFactory = IoFactory.factoryByMediaType(RecordReaderFactory.class, mediaTypeString);
if (readerFactory == null) {
throw new HttpMessageNotReadableException("Cannot read data in format" + mediaType);
} else {
final Reader<Record> reader = readerFactory.newRecordReader(new InputStreamResource("recordInput", body));
GeometryFactory factory = this.geometryFactory;
final ServletWebRequest requestAttributes = (ServletWebRequest) RequestContextHolder.getRequestAttributes();
final String srid = requestAttributes.getParameter("srid");
if (srid != null && srid.trim().length() > 0) {
factory = GeometryFactory.floating3d(Integer.parseInt(srid));
}
reader.setProperty(IoConstants.GEOMETRY_FACTORY, factory);
return (RecordReader) reader;
}
} catch (final IOException e) {
throw new HttpMessageNotReadableException("Error reading data", e);
}
}
use of com.revolsys.spring.resource.InputStreamResource in project com.revolsys.open by revolsys.
the class GeometryHttpMessageConverter method read.
@Override
public Geometry read(final Class<? extends Geometry> clazz, final HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
final HttpHeaders headers = inputMessage.getHeaders();
final MediaType mediaType = headers.getContentType();
try {
Charset charset = mediaType.getCharSet();
if (charset == null) {
charset = StandardCharsets.UTF_8;
}
final InputStream body = inputMessage.getBody();
final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
final GeometryReaderFactory readerFactory = IoFactory.factoryByMediaType(GeometryReaderFactory.class, mediaTypeString);
if (readerFactory == null) {
throw new HttpMessageNotReadableException("Cannot read data in format" + mediaType);
} else {
final Reader<Geometry> reader = readerFactory.newGeometryReader(new InputStreamResource("geometryUpload", body));
GeometryFactory factory = this.geometryFactory;
final ServletWebRequest requestAttributes = (ServletWebRequest) RequestContextHolder.getRequestAttributes();
final String srid = requestAttributes.getParameter("srid");
if (srid != null && srid.trim().length() > 0) {
factory = GeometryFactory.floating3d(Integer.parseInt(srid));
}
reader.setProperty(IoConstants.GEOMETRY_FACTORY, factory);
for (final Geometry geometry : reader) {
if (clazz.isAssignableFrom(geometry.getClass())) {
return geometry;
}
}
return null;
}
} catch (final Throwable e) {
Logs.error(this, "Error reading data using " + mediaType, e);
throw new HttpMessageNotReadableException("Error reading data using" + mediaType);
}
}
use of com.revolsys.spring.resource.InputStreamResource in project com.revolsys.open by revolsys.
the class GeometryReaderHttpMessageConverter method read.
@Override
public GeometryReader read(final Class<? extends GeometryReader> clazz, final HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
try {
final HttpHeaders headers = inputMessage.getHeaders();
final MediaType mediaType = headers.getContentType();
Charset charset = mediaType.getCharSet();
if (charset == null) {
charset = StandardCharsets.UTF_8;
}
final InputStream body = inputMessage.getBody();
final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
final GeometryReaderFactory readerFactory = IoFactory.factoryByMediaType(GeometryReaderFactory.class, mediaTypeString);
if (readerFactory == null) {
throw new HttpMessageNotReadableException("Cannot read data in format" + mediaType);
} else {
final InputStreamResource resource = new InputStreamResource("geometryInput", body);
final GeometryReader reader = readerFactory.newGeometryReader(resource);
GeometryFactory factory = this.geometryFactory;
final ServletWebRequest requestAttributes = (ServletWebRequest) RequestContextHolder.getRequestAttributes();
final String srid = requestAttributes.getParameter("srid");
if (srid != null && srid.trim().length() > 0) {
factory = GeometryFactory.floating3d(Integer.parseInt(srid));
}
reader.setProperty(IoConstants.GEOMETRY_FACTORY, factory);
return reader;
}
} catch (final IOException e) {
throw new HttpMessageNotReadableException("Error reading data", e);
}
}
Aggregations