当前位置: 首页>>代码示例>>Java>>正文


Java InputStream.markSupported方法代码示例

本文整理汇总了Java中java.io.InputStream.markSupported方法的典型用法代码示例。如果您正苦于以下问题:Java InputStream.markSupported方法的具体用法?Java InputStream.markSupported怎么用?Java InputStream.markSupported使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.InputStream的用法示例。


在下文中一共展示了InputStream.markSupported方法的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;
}
 
开发者ID:yale8848,项目名称:CacheWebView,代码行数:18,代码来源:BytesEncodingDetect.java

示例2: readHeaderFromStream

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Reads up to maxHeaderLength bytes from is InputStream. If mark is supported by is, it is
 * used to restore content of the stream after appropriate amount of data is read.
 * Read bytes are stored in imageHeaderBytes, which should be capable of storing
 * maxHeaderLength bytes.
 * @param maxHeaderLength the maximum header length
 * @param is
 * @param imageHeaderBytes
 * @return number of bytes read from is
 * @throws IOException
 */
private static int readHeaderFromStream(
    int maxHeaderLength,
    final InputStream is,
    final byte[] imageHeaderBytes)
    throws IOException {
  Preconditions.checkNotNull(is);
  Preconditions.checkNotNull(imageHeaderBytes);
  Preconditions.checkArgument(imageHeaderBytes.length >= maxHeaderLength);

  // If mark is supported by the stream, use it to let the owner of the stream re-read the same
  // data. Otherwise, just consume some data.
  if (is.markSupported()) {
    try {
      is.mark(maxHeaderLength);
      return ByteStreams.read(is, imageHeaderBytes, 0, maxHeaderLength);
    } finally {
      is.reset();
    }
  } else {
    return ByteStreams.read(is, imageHeaderBytes, 0, maxHeaderLength);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:ImageFormatChecker.java

示例3: fromInputStream

import java.io.InputStream; //导入方法依赖的package包/类
public static DexBackedDexFile fromInputStream(@Nonnull Opcodes opcodes, @Nonnull InputStream is)
        throws IOException {
    if (!is.markSupported()) {
        throw new IllegalArgumentException("InputStream must support mark");
    }
    is.mark(44);
    byte[] partialHeader = new byte[44];
    try {
        ByteStreams.readFully(is, partialHeader);
    } catch (EOFException ex) {
        throw new NotADexFile("File is too short");
    } finally {
        is.reset();
    }

    verifyMagicAndByteOrder(partialHeader, 0);

    byte[] buf = ByteStreams.toByteArray(is);
    return new DexBackedDexFile(opcodes, buf, 0, false);
}
 
开发者ID:CvvT,项目名称:andbg,代码行数:21,代码来源:DexBackedDexFile.java

示例4: 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;
}
 
开发者ID:nekocode,项目名称:Hubs,代码行数:26,代码来源:Globals.java

示例5: hasEmptyMessageBody

import java.io.InputStream; //导入方法依赖的package包/类
public boolean hasEmptyMessageBody() throws IOException {
    InputStream body = super.getInputStream();
    if (body == null) {
        return true;
    } else if (body.markSupported()) {
        body.mark(1);
        if (body.read() == -1) {
            return true;
        } else {
            body.reset();
            return false;
        }
    } else {
        this.pushbackInputStream = new PushbackServletInputStream(body);
        int b = this.pushbackInputStream.read();
        if (b == -1) {
            return true;
        } else {
            this.pushbackInputStream.unread(b);
            return false;
        }
    }
}
 
开发者ID:devefx,项目名称:validator-web,代码行数:24,代码来源:HttpServletRequestWrapper.java

示例6: 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 ignored) {
		}
	}
	IoUtils.closeSilently(imageStream);
	return getImageStream(decodingInfo);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:BaseImageDecoder.java

示例7: checkStream

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Checks for the constraints of this class.
 *
 * @param stream stream to test.
 * @throws IllegalArgumentException If stream does not meet the requirements.
 */
protected void checkStream(final InputStream stream)
        throws IllegalArgumentException {
    if (this.hasFailingReaders && !stream.markSupported()) {
        throw new IllegalArgumentException(
                "Stream has to support mark/reset.");
    }
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:14,代码来源:ChunkContainerReader.java

示例8: resetRequestInputStream

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Reset the input stream of the request before a retry.
 *
 * @param request Request containing input stream to reset
 * @throws ResetException If Input Stream can't be reset which means the request can't be
 *                        retried
 */
private void resetRequestInputStream(final Request<?> request) throws ResetException {
    InputStream requestInputStream = request.getContent();
    if (requestInputStream != null) {
        if (requestInputStream.markSupported()) {
            try {
                requestInputStream.reset();
            } catch (IOException ex) {
                throw new ResetException("Failed to reset the request input stream", ex);
            }
        }
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:20,代码来源:AmazonHttpClient.java

示例9: 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;
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:41,代码来源:InputStreamMessageContent.java

示例10: main

import java.io.InputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    try
    {
        setUp();

        for (int i = 0; i < 8; i++) {
            ModelByteBuffer buff;
            if(i % 2 == 0)
                buff = new ModelByteBuffer(test_file);
            else
                buff = new ModelByteBuffer(test_byte_array);
            if((i / 2) == 1)
                buff.subbuffer(5);
            if((i / 2) == 2)
                buff.subbuffer(5,500);
            if((i / 2) == 3)
                buff.subbuffer(5,600,true);

            long capacity = buff.capacity();
            InputStream is = buff.getInputStream();
            try
            {
                if(!is.markSupported())
                    throw new RuntimeException("InputStream doesn't support mark/reset!");
            }
            finally
            {
                is.close();
            }
            if(buff.capacity() != capacity)
                throw new RuntimeException("Capacity variable should not change!");
        }
    }
    finally
    {
        tearDown();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:MarkSupported.java

示例11: 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);
        }
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:15,代码来源:RetryableStage.java

示例12: buffer

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Buffer input stream if possible.
 *
 * @param content Input stream to buffer
 * @return SdkBufferedInputStream if possible, otherwise original input stream.
 */
private InputStream buffer(InputStream content) {
    if (!content.markSupported()) {
        content = new SdkBufferedInputStream(content);
    }
    return content;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:13,代码来源:AmazonHttpClient.java

示例13: resetStream

import java.io.InputStream; //导入方法依赖的package包/类
protected InputStream resetStream(InputStream imageStream, String url) throws IOException {
    if (imageStream.markSupported()) {
        try {
            imageStream.reset();
            return imageStream;
        } catch (IOException ignored) {
        }
    }
    closeSilently(imageStream);
    return getImageStream(url);
}
 
开发者ID:shenhuanet,项目名称:Sendroid,代码行数:12,代码来源:ImageDecorder.java

示例14: getVersion

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Get the UTrie version from an InputStream containing the serialized form
 * of either a Trie (version 1) or a Trie2 (version 2).
 *
 * @param is   an InputStream containing the serialized form
 *             of a UTrie, version 1 or 2.  The stream must support mark() and reset().
 *             The position of the input stream will be left unchanged.
 * @param littleEndianOk If FALSE, only big-endian (Java native) serialized forms are recognized.
 *                    If TRUE, little-endian serialized forms are recognized as well.
 * @return     the Trie version of the serialized form, or 0 if it is not
 *             recognized as a serialized UTrie
 * @throws     IOException on errors in reading from the input stream.
 */
public static int getVersion(InputStream is, boolean littleEndianOk) throws IOException {
    if (! is.markSupported()) {
        throw new IllegalArgumentException("Input stream must support mark().");
        }
    is.mark(4);
    byte sig[] = new byte[4];
    int read = is.read(sig);
    is.reset();

    if (read != sig.length) {
        return 0;
    }

    if (sig[0]=='T' && sig[1]=='r' && sig[2]=='i' && sig[3]=='e') {
        return 1;
    }
    if (sig[0]=='T' && sig[1]=='r' && sig[2]=='i' && sig[3]=='2') {
        return 2;
    }
    if (littleEndianOk) {
        if (sig[0]=='e' && sig[1]=='i' && sig[2]=='r' && sig[3]=='T') {
            return 1;
        }
        if (sig[0]=='2' && sig[1]=='i' && sig[2]=='r' && sig[3]=='T') {
            return 2;
        }
    }
    return 0;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:43,代码来源:Trie2.java

示例15: parseRequest

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Handles retrieving the boundary and setting the input stream
 */
protected void parseRequest() throws IOException
{
    //get the content-type header, which contains the boundary used for separating multipart elements
    getContentTypeOfRequest();
    //get the content-length header, used to prevent denial of service attacks and for detecting
    //whether a file size is over the limit before the client sends the file
    this.contentLength = this.request.getContentLength();
    //parse the boundary from the content-type header's value
    getBoundaryFromContentType();
    //don't let the stream read past the content length
    this.inputStream.setMaxLength(this.contentLength+1);
    //just stop now if the content length is bigger than the maximum allowed size
    if ((this.maxSize > -1) && (this.contentLength > this.maxSize))
    {
        this.maxLengthExceeded = true;
    }
    else
    {
        InputStream requestInputStream = this.request.getInputStream();
        //mark the input stream to allow multiple reads
        if (requestInputStream.markSupported())
        {
            requestInputStream.mark(contentLength+1);
        }
        this.inputStream.setBoundary(this.boundary);
        this.inputStream.setInputStream(requestInputStream);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:MultipartIterator.java


注:本文中的java.io.InputStream.markSupported方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。