本文整理汇总了Java中com.fasterxml.jackson.core.io.IOContext.setEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java IOContext.setEncoding方法的具体用法?Java IOContext.setEncoding怎么用?Java IOContext.setEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.core.io.IOContext
的用法示例。
在下文中一共展示了IOContext.setEncoding方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createGenerator
import com.fasterxml.jackson.core.io.IOContext; //导入方法依赖的package包/类
public JsonGenerator createGenerator(File paramFile, JsonEncoding paramJsonEncoding)
{
Object localObject = new FileOutputStream(paramFile);
IOContext localIOContext = _createContext(localObject, true);
localIOContext.setEncoding(paramJsonEncoding);
if (paramJsonEncoding == JsonEncoding.UTF8)
{
if (this._outputDecorator != null)
localObject = this._outputDecorator.decorate(localIOContext, (OutputStream)localObject);
return _createUTF8Generator((OutputStream)localObject, localIOContext);
}
Writer localWriter = _createWriter((OutputStream)localObject, paramJsonEncoding, localIOContext);
if (this._outputDecorator != null)
localWriter = this._outputDecorator.decorate(localIOContext, localWriter);
return _createGenerator(localWriter, localIOContext);
}
示例2: testSimple
import com.fasterxml.jackson.core.io.IOContext; //导入方法依赖的package包/类
public void testSimple() throws Exception
{
BufferRecycler rec = new BufferRecycler();
IOContext ctxt = new IOContext(rec, null, false);
// bit complicated; must use recyclable buffer...
byte[] first = ctxt.allocReadIOBuffer();
System.arraycopy("ABCDE".getBytes("UTF-8"), 0, first, 99, 5);
byte[] second = "FGHIJ".getBytes("UTF-8");
assertNull(ctxt.getSourceReference());
assertFalse(ctxt.isResourceManaged());
ctxt.setEncoding(JsonEncoding.UTF8);
MergedStream ms = new MergedStream(ctxt, new ByteArrayInputStream(second),
first, 99, 99+5);
// Ok, first, should have 5 bytes from first buffer:
assertEquals(5, ms.available());
// not supported when there's buffered stuff...
assertFalse(ms.markSupported());
// so this won't work, but shouldn't throw exception
ms.mark(1);
assertEquals((byte) 'A', ms.read());
assertEquals(3, ms.skip(3));
byte[] buffer = new byte[5];
/* Ok, now, code is allowed to return anywhere between 1 and 3,
* but we now it will return 1...
*/
assertEquals(1, ms.read(buffer, 1, 3));
assertEquals((byte) 'E', buffer[1]);
// So let's read bit more
assertEquals(3, ms.read(buffer, 0, 3));
assertEquals((byte) 'F', buffer[0]);
assertEquals((byte) 'G', buffer[1]);
assertEquals((byte) 'H', buffer[2]);
assertEquals(2, ms.available());
// And then skip the reset
assertEquals(2, ms.skip(200));
ms.close();
}
示例3: newJsonGenerator
import com.fasterxml.jackson.core.io.IOContext; //导入方法依赖的package包/类
/**
* Creates a {@link UTF8JsonGenerator} for the outputstream with the supplied buf {@code outBuffer} to use.
*/
static UTF8JsonGenerator newJsonGenerator(OutputStream out, byte[] buf, int offset,
boolean bufferRecyclable, IOContext context)
{
context.setEncoding(JsonEncoding.UTF8);
return new UTF8JsonGenerator(context,
DEFAULT_JSON_FACTORY.getGeneratorFeatures(),
DEFAULT_JSON_FACTORY.getCodec(),
out,
buf,
offset,
bufferRecyclable);
}