Java – Converting Cassandra ResultSet to Java 8 Stream

Statement stmt = QueryBuilder().select().all().from('table');
ResultSet rs = session.execute(stmt);

StreamSupport.stream(
    Spliterators.spliteratorUnknownSize(
                rs.iterator(), Spliterator.ORDERED), false)
.forEach(row -> {
   ...
});

As input stream is sorted by partition key and input order is important, the following example can be used.

Statement stmt = QueryBuilder().select().all().from('table');
ResultSet rs = session.execute(stmt);

StreamSupport.stream(
    Spliterators.spliteratorUnknownSize(
                rs.iterator(), Spliterator.ORDERED | Spliterator.SORTED), false)
.forEach(row -> {
   ...
});
Advertisements
Posted in cassandra, Java, Programming | Leave a comment

Angular – Proxy settings to avoid CORS

Create a proxy.config.json

{
  "/api": {
    "target": "http://localhost:8080",
    "secure": false
  }
}

run ng serve with a configuration file.

ng serve --proxy-config proxy.config.json
Posted in angular, Programming | Leave a comment

Java – Spring Boot 2.0 WebFlux configuration for static resources

    @Value("classpath:/static/index.html")
    private Resource indexHtml;

    @Bean
    RouterFunction<?> routerFunction() {
        RouterFunction router = RouterFunctions.resources("/**", new ClassPathResource("static/"))
                // workaround solution for forwarding / to /index.html
                .andRoute(GET("/"), request -> {
                    return ServerResponse.ok().contentType(TEXT_HTML).syncBody(indexHtml);
                });
        return router;
    }
Posted in Java, Programming | Leave a comment

Java – Read CSV file from a stream

try (final CSVReader reader = new CSVReader(new BufferedReader(new InputStreamReader(inputStream)))) {
    String[] line = null;

    while ((line = reader.readNext()) != null) {
              
    }

} catch (Exception e) {
...
}

Posted in Java, Programming | Leave a comment

Java – Bean validation 2.0 (JSR-380) with Spring boot

http://www.baeldung.com/javax-validation

http://andreinc.net/2017/10/02/writing-an-unified-validation-mechanism-for-rest-apis-using-spring-boot-and-jsr-380/

https://github.com/nomemory/java-bean-validation-extension

Posted in Java, Programming | Leave a comment

Java – ForkJoinPool

Good explanation on ForkJoinPool in Java

http://www.baeldung.com/java-fork-join

Posted in Java, Programming | Leave a comment

Java – logging components and explanation

LOGGERS: loggers are responsible for capturing events and passing them to the appropriate appender.

APPENDERS: also known as handlers, appenders are responsible for recording log events to a destination. appenders use layouts to format events before sending them to an output.

LAYOUTS: also known as formatters, layouts are responsible for converting and formatting the data in a log event. layouts determine how the data looks when it appears in a log entry.

Posted in Java, Programming | Leave a comment