This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note this method uses Consumer rather than Function since it only mutates the notebook and does not return anything. | |
public Workbook workbook(Consumer<Workbook> block) { | |
Workbook wb = new HSSFWorkbook(); | |
block.accept(wb); | |
return wb; | |
} | |
// We can call the method like this: | |
public void tryItOut() { | |
workbook((Workbook wb) -> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Sheet.merge(firstRow: Int, lastRow: Int,firstCol: Int, lastCol: Int) { | |
addMergedRegion(CellRangeAddress(firstRow, lastRow, firstCol, lastCol)) | |
} | |
sheet.merge( | |
1, //first row (0-based) | |
1, //last row (0-based) | |
1, //first column (0-based) | |
2 //last column (0-based) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sheet.addMergedRegion(new CellRangeAddress( | |
1, //first row (0-based) | |
1, //last row (0-based) | |
1, //first column (0-based) | |
2 //last column (0-based) | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val wb = workbook { | |
sheet("new sheet") { | |
row(2) { | |
cell(1.1) | |
cell(date1) | |
cell(calendar1) | |
cell("a string") | |
cell(true) | |
cell(5) { | |
cellType = ERROR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Workbook wb = new HSSFWorkbook(); | |
Sheet sheet = wb.createSheet("new sheet"); | |
Row row = sheet.createRow(2); | |
row.createCell(0).setCellValue(1.1); | |
row.createCell(1).setCellValue(date1); | |
row.createCell(2).setCellValue(calendar1); | |
row.createCell(3).setCellValue("a string"); | |
row.createCell(4).setCellValue(true); | |
row.createCell(5).setCellType(CellType.ERROR); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"title": "Introduction to Spring Reactor", | |
"thumbnailUrl": "/wp-content/themes/baeldung/icon/logo.svg", | |
"description": "The canonical reference for building a production grade API with Spring." | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UrlHandler(private val urlDecoder: URLDecoder) { | |
val charSet = StandardCharsets.UTF_8.toString() | |
val client = WebClient.create("") | |
fun unfurl(request: ServerRequest): Mono<ServerResponse> { | |
val url = URLDecoder.decode(request.pathVariable("url"), charSet) | |
val response = client.get().uri(url).retrieve().bodyToMono(String::class.java) | |
.map { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun routes(urlHandler: UrlHandler) = router { | |
GET("/unfurl/{url}", urlHandler::unfurl) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val app = application { | |
bean<UrlHandler>() | |
bean<URLDecoder>() | |
logging { | |
level(LogLevel.INFO) | |
logback { | |
consoleAppender() | |
} | |
} | |
webflux { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun CharIterator.readWhile(predicate: (Char) -> Boolean): Result<String, Exception> { | |
return Result.of<String, Exception> { | |
val readString = StringBuilder() | |
while (predicate.invoke(this.peek())) { | |
readString.append(this.next()) | |
} | |
readString.toString() | |
}.mapError { | |
DecodeException("Failed reading based on given predicate", it) | |
} |