Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rtemplate binary cache for static strings and optimized encoding of v…
…ariables
- Loading branch information
Showing
4 changed files
with
92 additions
and
40 deletions.
There are no files selected for viewing
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
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
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/jeroenreijn/examples/view/StringCache.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.jeroenreijn.examples.view; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class StringCache { | ||
private Map<String, byte[]> stringRendered=new HashMap<>(); | ||
|
||
public void write(OutputStream os, String s) throws IOException { | ||
byte[] data=stringRendered.get(s); | ||
if(data==null) | ||
{ | ||
data=s.getBytes(StandardCharsets.UTF_8); | ||
stringRendered.put(s, data); | ||
} | ||
os.write(data); | ||
} | ||
} |