…little Java stuff worth to write down…

Java little stuff

the String:

String.format("(%f, %f)", x,y); 

String.format("Zone: id: %s, usage: %s, geometry: %s", id, usage, polyLine.toString()); 

shebang support

#!/usr/bin/java --source 11
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hallo Java shebang");

find files

File directory = new File("rschumm/");

Optional<Path> foundFile = Files.find(
        (path, basicFileAttributes) -> path.toFile().getName().matches("blabla.*.yml")

quick File as String:

String s = Files.lines(Paths.get("")).collect(Collectors.joining()); 

very quick and dirty templating find- and replace

String template = Files.lines(Paths.get("../nfs/pv-nfs.yml")).collect(Collectors.joining("\n")); 
String out = template.replaceAll("0001", ""+i).replaceAll("general", "general/"+i); 	
Files.write(Paths.get("pv"+i+".yml"), out.getBytes(), StandardOpenOption.CREATE); 

Java Stream stuff

Collect To List:

List<Stuff> stuffInCar = -> car.contains(d)).collect(Collectors.toList()); 
List<Stuff> stuffInCar =; 

Mapping stuff:

List<Room> roomsWithin =; 
// ==> terminating map; 

Collect to Array:

Coordinate[] coordinates = -> new Coordinate(p.x , p.y)).toArray(Coordinate[]::new);


Coordinate[] coordinates = new Coordinate[] {
    new Coordinate(1.0 , 1.0), 
    new Coordinate(1.0 , 100.0), 
    new Coordinate(100.0 , 100.0), 
    new Coordinate(100.0 , 1.0), 
    new Coordinate(1.0 , 1.0), 		                                            

Serializer- and Marshaller-Stuff

Jackson Json Object Mapper:

public static void writeJson(File f, MyModel i)
    throws JsonGenerationException, JsonMappingException, IOException {
  ObjectMapper mapper = new ObjectMapper();
  mapper.writeValue(f, i);

public static MyModel readJson(File f) throws JsonParseException, JsonMappingException, IOException {
  ObjectMapper mapper = new ObjectMapper();
  // TODO validate to Schema 
  return mapper.readValue(f, MyModel.class); 

JAXB Marshaller:

public void marshall(File file) throws Exception {
  JAXBContext context = JAXBContext.newInstance(MyModel.class);
    Marshaller mar= context.createMarshaller();
    mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    mar.marshal(getMyModel(), file); 

JAXB Schema Class Generator

    <!-- <outputDirectory>${basedir}/src/main/java</outputDirectory> -->

JAXB Dependencies


<!-- JAXB needs javax.activation module (jdk9) -->


Rest-Client UniRest - super easy Rest-Client
Rest-assured used by Quarkus
Database Migration flyway
Spark Java WebApp Framework
HTML Parser jsoup
Json Parsing: Jackson or Gson cf hier Yaml Parsing: Jackson, cf Studrepos Example
git access: cf ebenda.


Quick and dirty Json-Load:

 <script src=""



function load(){
    url: '/hallo/logbuch',
    type: 'GET',
    success: function (response) {
        var trHTML = '';
        $.each(response, function (i, item) {
            trHTML += '<tr><th scope="row">' + + '</th><td>' + item.text + '</td></tr>';



Quick and dirty Intercooler-Stuff:

<script src=""></script>


    <div class="input-group">
      <input type="text" class="form-control" placeholder="Nachricht an Rémy" aria-label="Input group example" aria-describedby="btnGroupAddon" name="textinput">
      <button type="submit" class="btn btn-primary btn-default" ic-post-to="/hallo/sali" ic-target="#nachricht" ic-on-success="load();">
        Click Me!

and Quarkus Backend

public String saliPost(@FormParam("textinput") String name) {
    Message message = new Message();
    message.text = name; =;
    return service.sagHallo(name);

zurück zum Seitenanfang