String s = "Привет";
String encoded = URLEncoder.encode(s, StandardCharsets.UTF_8); // получится %D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82
String encoded = URLEncoder.encode(s, StandardCharsets.UTF_8).replace("+", "%20");
@GetMapping("/dl")
@ResponseBody
public ResponseEntity<Mono<Resource>> download() throws IOException {
String text = """
aaa,
bbb,
яяя
""";
byte[] bytes = text.getBytes();
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(bytes);
out.close();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
Mono<ByteArrayInputStream> file = Mono.just(in);
String filename = "1.txt";
return ResponseEntity
.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE)
.body(file
.flatMap(x -> Mono.just(new InputStreamResource(x)))
)
;
}
class MyFactory{
private final String type;
public MyFactory(String type) {
this.type = type;
}
public <T extends A> T getObject(){
return switch (type){
case "B" -> new B(); // ОШИБКА: Bad type in switch expression: B cannot be converted to T
case "C" -> new C();
default -> throw new IllegalStateException("Unexpected value: " + type);
};
}
}
public Object getObject(){...}