本文整理汇总了Java中java.io.InputStream.mark方法的典型用法代码示例。如果您正苦于以下问题:Java InputStream.mark方法的具体用法?Java InputStream.mark怎么用?Java InputStream.mark使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.InputStream
的用法示例。
在下文中一共展示了InputStream.mark方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLimit_skip
import java.io.InputStream; //导入方法依赖的package包/类
public void testLimit_skip() throws Exception {
byte[] big = newPreFilledByteArray(5);
InputStream bin = new ByteArrayInputStream(big);
InputStream lin = ByteStreams.limit(bin, 2);
// also test available
lin.mark(2);
assertEquals(2, lin.available());
lin.skip(1);
assertEquals(1, lin.available());
lin.reset();
assertEquals(2, lin.available());
lin.skip(3);
assertEquals(0, lin.available());
}
示例2: loadPrototype
import java.io.InputStream; //导入方法依赖的package包/类
/** Load lua source or lua binary from an input stream into a Prototype.
* The InputStream is either a binary lua chunk starting with the lua binary chunk signature,
* or a text input file. If it is a text input file, it is interpreted as a UTF-8 byte sequence.
* @param is Input stream containing a lua script or compiled lua"
* @param chunkname Name that will be used within the chunk as the source.
* @param mode String containing 'b' or 't' or both to control loading as binary or text or either.
*/
public Prototype loadPrototype(InputStream is, String chunkname, String mode) throws IOException {
if (mode.indexOf('b') >= 0) {
if (undumper == null)
error("No undumper.");
if (!is.markSupported())
is = new BufferedStream(is);
is.mark(4);
final Prototype p = undumper.undump(is, chunkname);
if (p != null)
return p;
is.reset();
}
if (mode.indexOf('t') >= 0) {
return compilePrototype(is, chunkname);
}
error("Failed to load prototype "+chunkname+" using mode '"+mode+"'");
return null;
}
示例3: testMarkAndReset
import java.io.InputStream; //导入方法依赖的package包/类
private void testMarkAndReset(TransferKind transferKind) throws IOException {
MockResponse response = new MockResponse();
transferKind.setBody(response, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1024);
server.enqueue(response);
server.enqueue(response);
InputStream in = urlFactory.open(server.url("/").url()).getInputStream();
assertFalse("This implementation claims to support mark().", in.markSupported());
in.mark(5);
assertEquals("ABCDE", readAscii(in, 5));
try {
in.reset();
fail();
} catch (IOException expected) {
}
assertEquals("FGHIJKLMNOPQRSTUVWXYZ", readAscii(in, Integer.MAX_VALUE));
in.close();
assertContent("ABCDEFGHIJKLMNOPQRSTUVWXYZ", urlFactory.open(server.url("/").url()));
}
示例4: fetchXmlUrl
import java.io.InputStream; //导入方法依赖的package包/类
/**
* Fetches the document at the given URL and returns it as a stream. Returns
* null if anything wrong happens.
*
* @param urlString The URL to load, as a string.
* @param monitor {@link ITaskMonitor} related to this URL.
* @param outException If non null, where to store any exception that
* happens during the fetch.
* @see UrlOpener UrlOpener, which handles all URL logic.
*/
private InputStream fetchXmlUrl(String urlString,
DownloadCache cache,
ITaskMonitor monitor,
Exception[] outException) {
try {
InputStream xml = cache.openCachedUrl(urlString, monitor);
if (xml != null) {
xml.mark(500000);
xml = new NonClosingInputStream(xml);
((NonClosingInputStream) xml).setCloseBehavior(CloseBehavior.RESET);
}
return xml;
} catch (Exception e) {
if (outException != null) {
outException[0] = e;
}
}
return null;
}
示例5: restoreWalletFromProtobufOrBase58
import java.io.InputStream; //导入方法依赖的package包/类
public static Wallet restoreWalletFromProtobufOrBase58(final InputStream is,
final NetworkParameters expectedNetworkParameters) throws IOException {
is.mark((int) Constants.BACKUP_MAX_CHARS);
try {
return restoreWalletFromProtobuf(is, expectedNetworkParameters);
} catch (final IOException x) {
try {
is.reset();
return restorePrivateKeysFromBase58(is, expectedNetworkParameters);
} catch (final IOException x2) {
throw new IOException(
"cannot read protobuf (" + x.getMessage() + ") or base58 (" + x2.getMessage() + ")", x);
}
}
}
示例6: readFrom
import java.io.InputStream; //导入方法依赖的package包/类
@Override
public void readFrom(InputStream in) throws IOException {
// Skip data type byte (we assume it's already read)
size = 1;
InputStream markInputStream = in.markSupported() ? in : new BufferedInputStream(in);
while (true) {
// Look for the 3-byte object end marker [0x00 0x00 0x09]
markInputStream.mark(3);
byte[] endMarker = new byte[3];
markInputStream.read(endMarker);
if (endMarker[0] == OBJECT_END_MARKER[0] && endMarker[1] == OBJECT_END_MARKER[1] && endMarker[2] == OBJECT_END_MARKER[2]) {
// End marker found
size += 3;
return;
} else {
// End marker not found; reset the stream to the marked position and read an AMF property
markInputStream.reset();
// Read the property key...
String key = AmfString.readStringFrom(in, true);
size += AmfString.sizeOf(key, true);
// ...and the property value
AmfData value = AmfDecoder.readFrom(markInputStream);
size += value.getSize();
properties.put(key, value);
}
}
}
示例7: getInputStream
import java.io.InputStream; //导入方法依赖的package包/类
private static InputStream getInputStream(URL jar) throws IOException {
// to fix offset caused by launch4j
try {
InputStream is = jar.openStream();
Log.debug("Scanning for jar...");
long offset = 0;
boolean found = false;
try {
while (true) {
if (getUnsignedInt(is) == 0x04034b50L) {
found = true;
break;
}
offset += 4;
}
} catch (IOException ignored) {
}
is.close();
InputStream finalIS = jar.openStream();
if (!found) {
Log.debug("Failed to find start");
} else {
Log.debug("Skipping " + offset + " bytes until start of jar [" + finalIS.skip(offset) + "]");
if (finalIS.markSupported())
finalIS.mark(Integer.MAX_VALUE);
}
return finalIS;
} catch (SSLException ssle) {
Log.error("SSL Exception", ssle);
}
}
示例8: getSoundbank
import java.io.InputStream; //导入方法依赖的package包/类
public Soundbank getSoundbank(InputStream stream)
throws InvalidMidiDataException, IOException {
try {
stream.mark(512);
return new DLSSoundbank(stream);
} catch (RIFFInvalidFormatException e) {
stream.reset();
return null;
}
}
示例9: getSoundbank
import java.io.InputStream; //导入方法依赖的package包/类
@Override
public Soundbank getSoundbank(InputStream stream)
throws InvalidMidiDataException, IOException {
try {
stream.mark(512);
return new SF2Soundbank(stream);
} catch (RIFFInvalidFormatException e) {
stream.reset();
return null;
}
}
示例10: readFrom
import java.io.InputStream; //导入方法依赖的package包/类
@Override
public void readFrom(InputStream in) throws IOException {
// Skip data type byte (we assume it's already read)
size = 1;
InputStream markInputStream = in.markSupported() ? in : new BufferedInputStream(in);
while (true) {
// Look for the 3-byte object end marker [0x00 0x00 0x09]
markInputStream.mark(3);
byte[] endMarker = new byte[3];
markInputStream.read(endMarker);
if (endMarker[0] == OBJECT_END_MARKER[0] && endMarker[1] == OBJECT_END_MARKER[1] && endMarker[2] == OBJECT_END_MARKER[2]) {
// End marker found
size += 3;
return;
} else {
// End marker not found; reset the stream to the marked position and read an AMF property
markInputStream.reset();
// Read the property key...
String key = AmfString.readStringFrom(in, true);
size += AmfString.sizeOf(key, true);
// ...and the property value
AmfData value = AmfDecoder.readFrom(markInputStream);
size += value.getSize();
properties.put(key, value);
}
}
}
示例11: ReadOnceInputEvent
import java.io.InputStream; //导入方法依赖的package包/类
public ReadOnceInputEvent(String appName, String route, String requestUrl, String method, InputStream body, Headers headers, QueryParameters parameters) {
this.appName = Objects.requireNonNull(appName);
this.route = Objects.requireNonNull(route);
this.requestUrl = Objects.requireNonNull(requestUrl);
this.method = Objects.requireNonNull(method).toUpperCase();
this.body = new BufferedInputStream(Objects.requireNonNull(body));
this.headers = Objects.requireNonNull(headers);
this.queryParameters = Objects.requireNonNull(parameters);
body.mark(Integer.MAX_VALUE);
}
示例12: getSoundbank
import java.io.InputStream; //导入方法依赖的package包/类
@Override
public Soundbank getSoundbank(InputStream stream)
throws InvalidMidiDataException, IOException {
try {
stream.mark(512);
return new DLSSoundbank(stream);
} catch (RIFFInvalidFormatException e) {
stream.reset();
return null;
}
}
示例13: xContentType
import java.io.InputStream; //导入方法依赖的package包/类
/**
* Guesses the content type based on the provided input stream without consuming it.
*
* @deprecated the content type should not be guessed except for few cases where we effectively don't know the content type.
* The REST layer should move to reading the Content-Type header instead. There are other places where auto-detection may be needed.
* This method is deprecated to prevent usages of it from spreading further without specific reasons.
*/
@Deprecated
public static XContentType xContentType(InputStream si) throws IOException {
if (si.markSupported() == false) {
throw new IllegalArgumentException("Cannot guess the xcontent type without mark/reset support on " + si.getClass());
}
si.mark(GUESS_HEADER_LENGTH);
try {
final byte[] firstBytes = new byte[GUESS_HEADER_LENGTH];
final int read = Streams.readFully(si, firstBytes);
return xContentType(new BytesArray(firstBytes, 0, read));
} finally {
si.reset();
}
}
示例14: parse
import java.io.InputStream; //导入方法依赖的package包/类
public void parse(InputStream stream,
ContentHandler handler, Metadata metadata,
ParseContext parseContext) throws IOException, SAXException,
TikaException
{
byte[] initial4 = new byte[4];
InputStream wrapped;
// Preserve TikaInputStreams as TikaInputStreams as they require less memory to process
if (stream.markSupported())
{
stream.mark(initial4.length);
IOUtils.readFully(stream, initial4);
stream.reset();
wrapped = stream;
}
else
{
PushbackInputStream inp = new PushbackInputStream(stream, 4);
IOUtils.readFully(inp, initial4);
inp.unread(initial4);
wrapped = inp;
}
// Which is it?
if(initial4[0] == POIFSConstants.OOXML_FILE_HEADER[0] &&
initial4[1] == POIFSConstants.OOXML_FILE_HEADER[1] &&
initial4[2] == POIFSConstants.OOXML_FILE_HEADER[2] &&
initial4[3] == POIFSConstants.OOXML_FILE_HEADER[3])
{
ooxmlParser.parse(wrapped, handler, metadata, parseContext);
}
else
{
ole2Parser.parse(wrapped, handler, metadata, parseContext);
}
}
示例15: calculateContentHash
import java.io.InputStream; //导入方法依赖的package包/类
/**
* Calculate the hash of the request's payload. Subclass could override this
* method to provide different values for "x-amz-content-sha256" header or
* do any other necessary set-ups on the request headers. (e.g. aws-chunked
* uses a pre-defined header value, and needs to change some headers
* relating to content-encoding and content-length.)
*/
protected String calculateContentHash(Aws4SignerRequestParams signerRequestParams,
SdkHttpFullRequest.Builder requestBuilder) {
SdkHttpFullRequest.Builder requestToSign = signerRequestParams.httpRequest();
InputStream payloadStream = getBinaryRequestPayloadStream(requestToSign.content());
payloadStream.mark(getReadLimit(signerRequestParams));
String contentSha256 = BinaryUtils.toHex(hash(payloadStream));
try {
payloadStream.reset();
} catch (IOException e) {
throw new SdkClientException("Unable to reset stream after calculating AWS4 signature", e);
}
return contentSha256;
}