本文整理汇总了Java中java.io.InputStream.reset方法的典型用法代码示例。如果您正苦于以下问题:Java InputStream.reset方法的具体用法?Java InputStream.reset怎么用?Java InputStream.reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.InputStream
的用法示例。
在下文中一共展示了InputStream.reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: detectEncodingStr
import java.io.InputStream; //导入方法依赖的package包/类
public String detectEncodingStr(InputStream inputStream){
String strEnc ="UTF-8";
inputStream.mark(0);
int enc = detectEncoding(inputStream);
try {
if (inputStream.markSupported()){
inputStream.reset();
}
} catch (IOException e) {
e.printStackTrace();
}
if (enc!=-1){
return Encoding.htmlname[enc];
}
return strEnc;
}
示例2: getEncodingName
import java.io.InputStream; //导入方法依赖的package包/类
/**
* XMLEntityManager cares about endian-ness, since it creates its own optimized
* readers. Since we're just using generic Java readers for now, we're not caring
* about endian-ness. If this changes, even more code needs to be copied from
* XMLEntity manager. -- PJM
*/
protected String getEncodingName(InputStream stream) throws IOException {
final byte[] b4 = new byte[4];
String encoding = null;
// this has the potential to throw an exception
// it will be fixed when we ensure the stream is rewindable (see note above)
stream.mark(4);
int count = stream.read(b4, 0, 4);
stream.reset();
if (count == 4) {
encoding = getEncodingName(b4);
}
return encoding;
}
示例3: getBinaryRequestPayloadWithoutQueryParams
import java.io.InputStream; //导入方法依赖的package包/类
/**
* Returns the request's payload contents as binary data, without processing
* any query string params (i.e. no form encoding for query params).
*
* @param request
* The request
* @return The request's payload contents as binary data, not including any
* form encoding of query string params.
*/
protected byte[] getBinaryRequestPayloadWithoutQueryParams(SignableRequest<?> request) {
InputStream content = getBinaryRequestPayloadStreamWithoutQueryParams(request);
try {
ReadLimitInfo info = request.getReadLimitInfo();
content.mark(info == null ? -1 : info.getReadLimit());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024 * 5];
while (true) {
int bytesRead = content.read(buffer);
if (bytesRead == -1) break;
byteArrayOutputStream.write(buffer, 0, bytesRead);
}
byteArrayOutputStream.close();
content.reset();
return byteArrayOutputStream.toByteArray();
} catch (Exception e) {
throw new SdkClientException("Unable to read request payload to sign request: " + e.getMessage(), e);
}
}
示例4: parse
import java.io.InputStream; //导入方法依赖的package包/类
/**
* parse the given inputStream with a new Parser
* @param inputStream
* @return the document parsed from the input Stream
*/
public static Document parse(InputStream inputStream) throws SAXException,IOException {
DocumentBuilder db=newParser();
try {
Document doc=db.parse(inputStream);
return doc;
} catch (java.net.MalformedURLException mue) {
if (EXCEPTION_DEBUG) {
String msg=mue.getMessage();
if (msg!=null) {
System.err.println(msg);
}
InputStream is=inputStream;
is.reset();
String content=parseISToString(is);
System.err.println(content);
}
throw mue;
}
}
示例5: testLimit_mark
import java.io.InputStream; //导入方法依赖的package包/类
public void testLimit_mark() throws Exception {
byte[] big = newPreFilledByteArray(5);
InputStream bin = new ByteArrayInputStream(big);
InputStream lin = ByteStreams.limit(bin, 2);
int read = lin.read();
assertEquals(big[0], read);
lin.mark(2);
read = lin.read();
assertEquals(big[1], read);
read = lin.read();
assertEquals(-1, read);
lin.reset();
read = lin.read();
assertEquals(big[1], read);
read = lin.read();
assertEquals(-1, read);
}
示例6: decodeStream
import java.io.InputStream; //导入方法依赖的package包/类
private static Bitmap decodeStream(InputStream is, BitmapFactory.Options options,
DecodeCallbacks callbacks) throws IOException {
if (options.inJustDecodeBounds) {
is.mark(MARK_POSITION);
} else {
// Once we've read the image header, we no longer need to allow the buffer to expand in
// size. To avoid unnecessary allocations reading image data, we fix the mark limit so that it
// is no larger than our current buffer size here. We need to do so immediately before
// decoding the full image to avoid having our mark limit overridden by other calls to
// markand reset. See issue #225.
callbacks.onObtainBounds();
}
// BitmapFactory.Options out* variables are reset by most calls to decodeStream, successful or
// otherwise, so capture here in case we log below.
int sourceWidth = options.outWidth;
int sourceHeight = options.outHeight;
String outMimeType = options.outMimeType;
final Bitmap result;
TransformationUtils.getBitmapDrawableLock().lock();
try {
result = BitmapFactory.decodeStream(is, null, options);
} catch (IllegalArgumentException e) {
throw newIoExceptionForInBitmapAssertion(e, sourceWidth, sourceHeight, outMimeType, options);
} finally {
TransformationUtils.getBitmapDrawableLock().unlock();
}
if (options.inJustDecodeBounds) {
is.reset();
}
return result;
}
示例7: 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;
}
示例8: getAudioFileFormat
import java.io.InputStream; //导入方法依赖的package包/类
public AudioFileFormat getAudioFileFormat(InputStream stream)
throws UnsupportedAudioFileException, IOException {
stream.mark(200);
AudioFileFormat format;
try {
format = internal_getAudioFileFormat(stream);
} finally {
stream.reset();
}
return format;
}
示例9: resetRequestInputStream
import java.io.InputStream; //导入方法依赖的package包/类
/**
* Reset the input stream of the request before a retry.
*
* @throws ResetException If Input Stream can't be reset which means the request can't be retried.
*/
private static void resetRequestInputStream(InputStream inputStream) throws ResetException {
if (inputStream.markSupported()) {
try {
inputStream.reset();
} catch (IOException ex) {
throw new ResetException("Failed to reset the request input stream", ex);
}
}
}
示例10: testMRMaxLine
import java.io.InputStream; //导入方法依赖的package包/类
@Test (timeout=5000)
public void testMRMaxLine() throws Exception {
final int MAXPOS = 1024 * 1024;
final int MAXLINE = 10 * 1024;
final int BUF = 64 * 1024;
final InputStream infNull = new InputStream() {
int position = 0;
final int MAXPOSBUF = 1024 * 1024 + BUF; // max LRR pos + LineReader buf
@Override
public int read() {
++position;
return 0;
}
@Override
public int read(byte[] b) {
assertTrue("Read too many bytes from the stream", position < MAXPOSBUF);
Arrays.fill(b, (byte) 0);
position += b.length;
return b.length;
}
public void reset() {
position=0;
}
};
final LongWritable key = new LongWritable();
final Text val = new Text();
LOG.info("Reading a line from /dev/null");
final Configuration conf = new Configuration(false);
conf.setInt(org.apache.hadoop.mapreduce.lib.input.
LineRecordReader.MAX_LINE_LENGTH, MAXLINE);
conf.setInt("io.file.buffer.size", BUF); // used by LRR
// test another constructor
LineRecordReader lrr = new LineRecordReader(infNull, 0, MAXPOS, conf);
assertFalse("Read a line from null", lrr.next(key, val));
infNull.reset();
lrr = new LineRecordReader(infNull, 0L, MAXLINE, MAXPOS);
assertFalse("Read a line from null", lrr.next(key, val));
}
示例11: resetStream
import java.io.InputStream; //导入方法依赖的package包/类
protected InputStream resetStream(InputStream imageStream, ImageDecodingInfo decodingInfo) throws IOException {
try {
imageStream.reset();
return imageStream;
} catch (IOException e) {
IoUtils.closeSilently(imageStream);
return getImageStream(decodingInfo);
}
}
示例12: resetStream
import java.io.InputStream; //导入方法依赖的package包/类
protected InputStream resetStream(InputStream imageStream, ImageDecodingInfo decodingInfo)
throws IOException {
if (imageStream.markSupported()) {
try {
imageStream.reset();
return imageStream;
} catch (IOException e) {
}
}
IoUtils.closeSilently(imageStream);
return getImageStream(decodingInfo);
}
示例13: get8bitCharacterProportion
import java.io.InputStream; //导入方法依赖的package包/类
@Override
public float get8bitCharacterProportion() {
if (eightBitCharProportion != UNCOUNTED) {
return eightBitCharProportion;
}
int eightBitCharCount = 0;
InputStream inputStream = getStream();
if (!inputStream.markSupported()) {
// if we can't examine the stream non-destructively,
// assume it has some 8 bit characters, but not enough
// to require encoding the body as base64
eightBitCharProportion = DEFAULT_8BIT_PROPORTION;
return eightBitCharProportion;
}
inputStream.mark(READ_LIMIT);
try {
int c, bytesRead = 0;
while (bytesRead < READ_LIMIT && (c = inputStream.read()) != -1) {
if (0 != (c & 0x80)) {
eightBitCharCount++;
}
bytesRead++;
}
inputStream.reset();
eightBitCharProportion = 1.0F * eightBitCharCount / bytesRead;
} catch (IOException e) {
throw new RuntimeException(e);
}
return eightBitCharProportion;
}
示例14: getFileFullReports
import java.io.InputStream; //导入方法依赖的package包/类
private static synchronized List<EnvFileFullReport> getFileFullReports(CharSequence charSequence) {
List<EnvFileFullReport> fileReports = new ArrayList<>();
try {
InputStream virtualFile = IOUtils.toInputStream(charSequence, "UTF-8");
String md5Hash = ByteSource.wrap(ByteStreams.toByteArray(virtualFile)).hash(Hashing.md5()).toString();
fileReports = fileReportCache.getIfPresent(md5Hash);
virtualFile.reset();
if (fileReports == null && JNomadInspection.jnomad != null) { //no cache; load file from disk
fileReports = new ArrayList<>();
QueryLiteralExtractor.isDisabled = false;
SourceCodeExtract extract = JNomadInspection.jnomad.scanSingleFile(virtualFile);
if (extract.getQueryLiteralExtractor().getQueryFound()) {
List<SourceCodeExtract> scanList = Collections.singletonList(extract);
queryParser.run(scanList);
for (JNomadPluginConfiguration.DBEnvironment env : pluginConfiguration.getEnvironmentList()) {
for (JNomadPluginConfiguration.DBConnection conn : env.getConnectionList()) {
EnvFileFullReport envReport = new EnvFileFullReport(null, JNomadInspection.jnomad, conn.getDataType(), queryParser.getAliasMap(), scanList, conn.toConnection());
envReport.setEnvironment(env);
fileReports.add(envReport);
}
}
fileReportCache.put(md5Hash, fileReports);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return fileReports;
}
示例15: decodeStream
import java.io.InputStream; //导入方法依赖的package包/类
private static Bitmap decodeStream(InputStream is, BitmapFactory.Options options,
DecodeCallbacks callbacks, BitmapPool bitmapPool) throws IOException {
if (options.inJustDecodeBounds) {
is.mark(MARK_POSITION);
} else {
// Once we've read the image header, we no longer need to allow the buffer to expand in
// size. To avoid unnecessary allocations reading image data, we fix the mark limit so that it
// is no larger than our current buffer size here. We need to do so immediately before
// decoding the full image to avoid having our mark limit overridden by other calls to
// mark and reset. See issue #225.
callbacks.onObtainBounds();
}
// BitmapFactory.Options out* variables are reset by most calls to decodeStream, successful or
// otherwise, so capture here in case we log below.
int sourceWidth = options.outWidth;
int sourceHeight = options.outHeight;
String outMimeType = options.outMimeType;
final Bitmap result;
TransformationUtils.getBitmapDrawableLock().lock();
try {
result = BitmapFactory.decodeStream(is, null, options);
} catch (IllegalArgumentException e) {
IOException bitmapAssertionException =
newIoExceptionForInBitmapAssertion(e, sourceWidth, sourceHeight, outMimeType, options);
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Failed to decode with inBitmap, trying again without Bitmap re-use",
bitmapAssertionException);
}
if (options.inBitmap != null) {
try {
is.reset();
bitmapPool.put(options.inBitmap);
options.inBitmap = null;
return decodeStream(is, options, callbacks, bitmapPool);
} catch (IOException resetException) {
throw bitmapAssertionException;
}
}
throw bitmapAssertionException;
} finally {
TransformationUtils.getBitmapDrawableLock().unlock();
}
if (options.inJustDecodeBounds) {
is.reset();
}
return result;
}