本文整理汇总了Java中org.eclipse.jgit.util.TemporaryBuffer类的典型用法代码示例。如果您正苦于以下问题:Java TemporaryBuffer类的具体用法?Java TemporaryBuffer怎么用?Java TemporaryBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TemporaryBuffer类属于org.eclipse.jgit.util包,在下文中一共展示了TemporaryBuffer类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replyJson
import org.eclipse.jgit.util.TemporaryBuffer; //导入依赖的package包/类
public static long replyJson(
@Nullable HttpServletRequest req,
HttpServletResponse res,
ListMultimap<String, String> config,
Object result)
throws IOException {
TemporaryBuffer.Heap buf = heap(HEAP_EST_SIZE, Integer.MAX_VALUE);
buf.write(JSON_MAGIC);
Writer w = new BufferedWriter(new OutputStreamWriter(buf, UTF_8));
Gson gson = newGson(config, req);
if (result instanceof JsonElement) {
gson.toJson((JsonElement) result, w);
} else {
gson.toJson(result, w);
}
w.write('\n');
w.flush();
return replyBinaryResult(
req, res, asBinaryResult(buf).setContentType(JSON_TYPE).setCharacterEncoding(UTF_8));
}
示例2: stackJsonString
import org.eclipse.jgit.util.TemporaryBuffer; //导入依赖的package包/类
private static BinaryResult stackJsonString(HttpServletResponse res, BinaryResult src)
throws IOException {
TemporaryBuffer.Heap buf = heap(HEAP_EST_SIZE, Integer.MAX_VALUE);
buf.write(JSON_MAGIC);
try (Writer w = new BufferedWriter(new OutputStreamWriter(buf, UTF_8));
JsonWriter json = new JsonWriter(w)) {
json.setLenient(true);
json.setHtmlSafe(true);
json.value(src.asString());
w.write('\n');
}
res.setHeader("X-FYI-Content-Encoding", "json");
res.setHeader("X-FYI-Content-Type", src.getContentType());
return asBinaryResult(buf).setContentType(JSON_TYPE).setCharacterEncoding(UTF_8);
}
示例3: base64
import org.eclipse.jgit.util.TemporaryBuffer; //导入依赖的package包/类
private static BinaryResult base64(BinaryResult bin) throws IOException {
int maxSize = base64MaxSize(bin.getContentLength());
int estSize = Math.min(base64MaxSize(HEAP_EST_SIZE), maxSize);
TemporaryBuffer.Heap buf = heap(estSize, maxSize);
try (OutputStream encoded =
BaseEncoding.base64().encodingStream(new OutputStreamWriter(buf, ISO_8859_1))) {
bin.writeTo(encoded);
}
return asBinaryResult(buf);
}
示例4: compress
import org.eclipse.jgit.util.TemporaryBuffer; //导入依赖的package包/类
private static BinaryResult compress(BinaryResult bin) throws IOException {
TemporaryBuffer.Heap buf = heap(HEAP_EST_SIZE, 20 << 20);
try (GZIPOutputStream gz = new GZIPOutputStream(buf)) {
bin.writeTo(gz);
}
return asBinaryResult(buf).setContentType(bin.getContentType());
}
示例5: asBinaryResult
import org.eclipse.jgit.util.TemporaryBuffer; //导入依赖的package包/类
@SuppressWarnings("resource")
private static BinaryResult asBinaryResult(TemporaryBuffer.Heap buf) {
return new BinaryResult() {
@Override
public void writeTo(OutputStream os) throws IOException {
buf.writeTo(os, null);
}
}.setContentLength(buf.length());
}
示例6: readPegdownCss
import org.eclipse.jgit.util.TemporaryBuffer; //导入依赖的package包/类
private static String readPegdownCss(AtomicBoolean file) throws IOException {
String name = "pegdown.css";
URL url = MarkdownFormatter.class.getResource(name);
if (url == null) {
throw new FileNotFoundException("Resource " + name);
}
file.set("file".equals(url.getProtocol()));
try (InputStream in = url.openStream();
TemporaryBuffer.Heap tmp = new TemporaryBuffer.Heap(128 * 1024)) {
tmp.copy(in);
return new String(tmp.toByteArray(), UTF_8);
}
}
示例7: heap
import org.eclipse.jgit.util.TemporaryBuffer; //导入依赖的package包/类
private static Heap heap(int est, int max) {
return new TemporaryBuffer.Heap(est, max);
}
示例8: setBuffer
import org.eclipse.jgit.util.TemporaryBuffer; //导入依赖的package包/类
public void setBuffer(TemporaryBuffer buffer) {
this.entity = new TemporaryBufferEntity(buffer);
}
示例9: setFixedLengthStreamingMode
import org.eclipse.jgit.util.TemporaryBuffer; //导入依赖的package包/类
public void setFixedLengthStreamingMode(int contentLength) {
if (entity != null)
throw new IllegalArgumentException();
entity = new TemporaryBufferEntity(new TemporaryBuffer.LocalFile(null));
entity.setContentLength(contentLength);
}
示例10: getOutputStream
import org.eclipse.jgit.util.TemporaryBuffer; //导入依赖的package包/类
public OutputStream getOutputStream() throws IOException {
if (entity == null)
entity = new TemporaryBufferEntity(new TemporaryBuffer.LocalFile(null));
return entity.getBuffer();
}
示例11: setChunkedStreamingMode
import org.eclipse.jgit.util.TemporaryBuffer; //导入依赖的package包/类
public void setChunkedStreamingMode(int chunklen) {
if (entity == null)
entity = new TemporaryBufferEntity(new TemporaryBuffer.LocalFile(null));
entity.setChunked(true);
}