Open a file stored in S3 with Java

I have this java code to run it with Apache Flink

private static Boolean GeoAlarm(Float longitud, Float latitud) {

try {

// create a point

Geometry point = new GeometryFactory().createPoint(new Coordinate(longitud, latitud));

//File inFile = new File("C:\\Users\\...\\Desktop\\...\\...\\file.geojson");

File inFile = new File("s3://.../file.geojson");

Map params = new HashMap<>();

params.put(GeoJSONDataStoreFactory.URLP.key, URLs.fileToUrl(inFile));

DataStore newDataStore = DataStoreFinder.getDataStore(params);

FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();

SimpleFeatureSource featureSource = newDataStore.getFeatureSource(newDataStore.getTypeNames()[0]);

Filter f = ff.contains(ff.property(featureSource.getSchema().getGeometryDescriptor().getLocalName()),

ff.literal(point));

SimpleFeatureCollection collection = featureSource.getFeatures(f);

<...>

}

When I run it locally I can access to the file (also stored locally) but when I run it in Kinesis Data Analytics obviously I can not access, so I had to upload...

Read More »

By: StackOverFlow - 6 days ago

Related Posts

  • Older News
  • Trouble getting PDF document from context in Java: StackOverFlow (Today) - Inside a java application, I am trying to get a PDF file that lives in the project's folder structure. Like this:File pdfGuy = new File(Thread.currentThread().getContextClassLoader().getResource("map.pdf").toURI());FileUtils.copyFile(pdfGuy, new File("C:\\Users\\thalerBoi\\Downloads\\map.pdf"));I'm just copying it...