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


Java BufferedInputStream.mark方法代码示例

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


在下文中一共展示了BufferedInputStream.mark方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractRequestEntity

import java.io.BufferedInputStream; //导入方法依赖的package包/类
static String extractRequestEntity(ContainerRequestContext request) {
    if (request.hasEntity()) {
        InputStream inputStreamOriginal = request.getEntityStream();
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStreamOriginal, MAX_ENTITY_READ);
        bufferedInputStream.mark(MAX_ENTITY_READ);
        byte[] bytes = new byte[MAX_ENTITY_READ];
        int read;
        try {
            read = bufferedInputStream.read(bytes, 0, MAX_ENTITY_READ);
            bufferedInputStream.reset();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        request.setEntityStream(bufferedInputStream);

        return new String(bytes, Charsets.UTF_8);
    }
    return null;
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:20,代码来源:ServerLogFilter.java

示例2: decodeBitmap

import java.io.BufferedInputStream; //导入方法依赖的package包/类
private static Bitmap decodeBitmap(InputStream inputStream, Rect rect) {

        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
        BitmapFactory.Options options = new BitmapFactory.Options();

        options.inPreferredConfig = Bitmap.Config.RGB_565;

        if (rect != null) {
            options.inJustDecodeBounds = true;
            bufferedInputStream.mark(MARK_POSITION);
            BitmapFactory.decodeStream(bufferedInputStream, null, options);
            try {
                bufferedInputStream.reset();
            } catch (IOException e) {
                Debug.e(e);
            }
            options.inJustDecodeBounds = false;
            options.inSampleSize = AbstractImageLoader.getSampleSize(options.outWidth, options.outHeight, rect.width(), rect.height());
        }

        return BitmapFactory.decodeStream(bufferedInputStream, null, options);
    }
 
开发者ID:nichbar,项目名称:Aequorea,代码行数:23,代码来源:BitmapWrapper.java

示例3: load

import java.io.BufferedInputStream; //导入方法依赖的package包/类
public void load(TGSongLoaderHandle handle) throws TGFileFormatException{
	try{
		BufferedInputStream stream = new BufferedInputStream(handle.getInputStream());
		
		stream.mark(1);
		Iterator<TGInputStreamBase> it = TGFileFormatManager.getInstance(this.context).getInputStreams();
		while(it.hasNext() && handle.getSong() == null){
			TGInputStreamBase reader = (TGInputStreamBase)it.next();
			reader.init(handle.getFactory(),stream);
			if( reader.isSupportedVersion() ){
				handle.setSong(reader.readSong());
				handle.setFormat(reader.getFileFormat());
				return;
			}
			stream.reset();
		}
		stream.close();
	} catch(Throwable throwable) {
		throw new TGFileFormatException(throwable);
	}
	throw new TGFileFormatException("Unsupported file format");
}
 
开发者ID:axlecho,项目名称:tuxguitar,代码行数:23,代码来源:TGSongLoaderHelper.java

示例4: testNegative

import java.io.BufferedInputStream; //导入方法依赖的package包/类
private void testNegative(final int readLimit) throws IOException {
    byte[] bytes = new byte[100];
    for (int i=0; i < bytes.length; i++)
        bytes[i] = (byte)i;
    // buffer of 10 bytes
    BufferedInputStream bis =
        new BufferedInputStream(new ByteArrayInputStream(bytes), 10);
    // skip 10 bytes
    bis.skip(10);
    bis.mark(readLimit);   // 1 byte short in buffer size
    // read 30 bytes in total, with internal buffer incread to 20
    bis.read(new byte[20]);
    try {
        bis.reset();
        fail();
    } catch(IOException ex) {
        assertEquals("Resetting to invalid mark", ex.getMessage());
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:20,代码来源:BufferedInputStreamResetTest.java

示例5: loadImage

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream, boolean, boolean, int[])
 */
public ByteBuffer loadImage(InputStream is, boolean flipped, boolean forceAlpha, int[] transparent) throws IOException {
	CompositeIOException exception = new CompositeIOException();
	ByteBuffer buffer = null;
	
	BufferedInputStream in = new BufferedInputStream(is, is.available());
	in.mark(is.available());
	
	// cycle through our source until one of them works
	for (int i=0;i<sources.size();i++) {
		in.reset();
		try {
			LoadableImageData data = (LoadableImageData) sources.get(i);
			
			buffer = data.loadImage(in, flipped, forceAlpha, transparent);
			picked = data;
			break;
		} catch (Exception e) {
			Log.warn(sources.get(i).getClass()+" failed to read the data", e);
			exception.addException(e);
		}
	}
	
	if (picked == null) {
		throw exception;
	}
	
	return buffer;
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:32,代码来源:CompositeImageData.java

示例6: loadXml

import java.io.BufferedInputStream; //导入方法依赖的package包/类
@ApiMethod
public static Document loadXml(InputStream stream)
{
   String docText = null;
   try
   {
      int buffSize = 2048;
      BufferedInputStream buff = new BufferedInputStream(stream, buffSize);
      byte[] debug = new byte[buffSize];
      buff.mark(buffSize);

      buff.read(debug);
      docText = new String(debug);
      docText = docText.trim();
      buff.reset();
      stream = buff;

      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc = db.parse(stream);
      doc.getDocumentElement().normalize();

      return doc;
   }
   catch (Exception ex)
   {
      String msg = "Unable to parse document: " + ex.getMessage();
      if (docText != null)
         msg += "\r\n" + docText;

      throw new RuntimeException(msg);
   }
}
 
开发者ID:wellsb1,项目名称:fort_j,代码行数:34,代码来源:Xml.java

示例7: Gpx2Fit

import java.io.BufferedInputStream; //导入方法依赖的package包/类
public Gpx2Fit(String name, InputStream in, Gpx2FitOptions options) throws Exception {
    mGpx2FitOptions = options;
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XmlPullParser parser = factory.newPullParser();
    //parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
    courseName = name;
    BufferedInputStream inputStream = new BufferedInputStream(in);
    inputStream.mark(64000);

    //FileInputStream in = new FileInputStream(file);

    try {
        parser.setInput(inputStream, null);
        parser.nextTag();
        readGPX(parser);
        inputStream.close();
        return;
    } catch (Exception e) {
        ns = HTTP_WWW_TOPOGRAFIX_COM_GPX_1_0;
        Log.debug("Ex {}", e);
    }

    inputStream.reset();

    try {
        parser.setInput(inputStream, null);
        parser.nextTag();
        readGPX(parser);
    } finally {
        inputStream.close();
    }
}
 
开发者ID:gimportexportdevs,项目名称:gexporter,代码行数:34,代码来源:Gpx2Fit.java

示例8: maybeDecompress

import java.io.BufferedInputStream; //导入方法依赖的package包/类
private static InputStream maybeDecompress(InputStream input) throws IOException {
    // Due to a bug, Jira sometimes returns double-compressed responses. See JRA-37608
    BufferedInputStream buffered = new BufferedInputStream(input, 2);
    buffered.mark(2);
    int[] buf = new int[2];
    buf[0] = buffered.read();
    buf[1] = buffered.read();
    buffered.reset();
    int header = (buf[1] << 8) | buf[0];
    if (header == GZIPInputStream.GZIP_MAGIC) {
        return new GZIPInputStream(buffered);
    } else {
        return buffered;
    }
}
 
开发者ID:pascalgn,项目名称:jiracli,代码行数:16,代码来源:HttpClient.java

示例9: accept

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * Accept a connection. This method will block until the connection
 * is made and four bytes can be read from the input stream.
 * If the first four bytes are "POST", then an HttpReceiveSocket is
 * returned, which will handle the HTTP protocol wrapping.
 * Otherwise, a WrappedSocket is returned.  The input stream will be
 * reset to the beginning of the transmission.
 * In either case, a BufferedInputStream will already be on top of
 * the underlying socket's input stream.
 * @exception IOException IO error when waiting for the connection.
 */
public Socket accept() throws IOException
{
    Socket socket = super.accept();
    BufferedInputStream in =
        new BufferedInputStream(socket.getInputStream());

    RMIMasterSocketFactory.proxyLog.log(Log.BRIEF,
        "socket accepted (checking for POST)");

    in.mark(4);
    boolean isHttp = (in.read() == 'P') &&
                     (in.read() == 'O') &&
                     (in.read() == 'S') &&
                     (in.read() == 'T');
    in.reset();

    if (RMIMasterSocketFactory.proxyLog.isLoggable(Log.BRIEF)) {
        RMIMasterSocketFactory.proxyLog.log(Log.BRIEF,
            (isHttp ? "POST found, HTTP socket returned" :
                      "POST not found, direct socket returned"));
    }

    if (isHttp)
        return new HttpReceiveSocket(socket, in, null);
    else
        return new WrappedSocket(socket, in, null);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:HttpAwareServerSocket.java

示例10: readMagic

import java.io.BufferedInputStream; //导入方法依赖的package包/类
static byte[] readMagic(BufferedInputStream in) throws IOException {
    in.mark(4);
    byte[] magic = new byte[4];
    for (int i = 0; i < magic.length; i++) {
        // read 1 byte at a time, so we always get 4
        if (1 != in.read(magic, i, 1))
            break;
    }
    in.reset();
    return magic;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:Utils.java

示例11: JavaSoundAudioClip

import java.io.BufferedInputStream; //导入方法依赖的package包/类
public JavaSoundAudioClip(InputStream in) throws IOException {
    if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.<init>");

    BufferedInputStream bis = new BufferedInputStream(in, STREAM_BUFFER_SIZE);
    bis.mark(STREAM_BUFFER_SIZE);
    boolean success = false;
    try {
        AudioInputStream as = AudioSystem.getAudioInputStream(bis);
        // load the stream data into memory
        success = loadAudioData(as);

        if (success) {
            success = false;
            if (loadedAudioByteLength < CLIP_THRESHOLD) {
                success = createClip();
            }
            if (!success) {
                success = createSourceDataLine();
            }
        }
    } catch (UnsupportedAudioFileException e) {
        // not an audio file
        try {
            MidiFileFormat mff = MidiSystem.getMidiFileFormat(bis);
            success = createSequencer(bis);
        } catch (InvalidMidiDataException e1) {
            success = false;
        }
    }
    if (!success) {
        throw new IOException("Unable to create AudioClip from input stream");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:JavaSoundAudioClip.java

示例12: getFirstLine

import java.io.BufferedInputStream; //导入方法依赖的package包/类
private static String getFirstLine(BufferedInputStream in) throws IOException {
	byte[] first = new byte[512];
	in.mark(first.length - 1);
	in.read(first);
	in.reset();

	int lineBreak = first.length;
	for (int i = 0; i < lineBreak; i++) {
		if (first[i] == '\n') {
			lineBreak = i;
		}
	}
	return new String(first, 0, lineBreak, "UTF-8");
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:15,代码来源:LogisimFile.java

示例13: optimizeBitmap

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * optimize bitmap
 * @param bitmap
 * @return
 */
public static Bitmap optimizeBitmap(@NonNull Bitmap bitmap, int size) {
    if (!bitmap.isRecycled()) {
        // convert bitmap into inputStream
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        // bitmap compress
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        // bytes into array
        InputStream is = new ByteArrayInputStream(stream.toByteArray());
        BufferedInputStream imageFileStream = new BufferedInputStream(is);
        try {
            // Phase 1: Get a reduced size image. In this part we will do a rough scale down
            int sampleSize = 1;
            if (size > 0 && size > 0) {
                final BitmapFactory.Options decodeBoundsOptions = new BitmapFactory.Options();
                decodeBoundsOptions.inJustDecodeBounds = true;
                imageFileStream.mark(64 * 1024);
                BitmapFactory.decodeStream(imageFileStream, null, decodeBoundsOptions);
                imageFileStream.reset();
                final int originalWidth = decodeBoundsOptions.outWidth;
                final int originalHeight = decodeBoundsOptions.outHeight;
                // inSampleSize prefers multiples of 2, but we prefer to prioritize memory savings
                sampleSize = Math.max(1, Math.max(originalWidth / size, originalHeight / size));
            }
            BitmapFactory.Options decodeBitmapOptions = new BitmapFactory.Options();
            decodeBitmapOptions.inSampleSize = sampleSize;
            //decodeBitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; // Uses 2-bytes instead of default 4 per pixel

            // Get the roughly scaled-down image
            Bitmap bmp = BitmapFactory.decodeStream(imageFileStream, null, decodeBitmapOptions);

            // Phase 2: Get an exact-size image - no dimension will exceed the desired value
            float ratio = Math.min((float) size / (float) bmp.getWidth(), (float) size / (float) bmp.getHeight());
            int w = (int) ((float) bmp.getWidth() * ratio);
            int h = (int) ((float) bmp.getHeight() * ratio);

            // finally scaled bitmap
            return Bitmap.createScaledBitmap(bmp, w, h, true);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                imageFileStream.close();
            } catch (IOException ignored) {
            }
        }
        return null;
    } else {
        return null;
    }

}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:58,代码来源:ArtworkUtils.java

示例14: getCharset

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * 判断文件编码
 *
 * @param file 文件
 * @return 编码:GBK,UTF-8,UTF-16LE
 */
public String getCharset(File file) {
    String charset = "GBK";
    byte[] first3Bytes = new byte[3];
    try {
        boolean checked = false;
        BufferedInputStream bis = new BufferedInputStream(
                new FileInputStream(file));
        bis.mark(0);
        int read = bis.read(first3Bytes, 0, 3);
        if (read == -1)
            return charset;
        if (first3Bytes[0] == (byte) 0xFF && first3Bytes[1] == (byte) 0xFE) {
            charset = "UTF-16LE";
            checked = true;
        } else if (first3Bytes[0] == (byte) 0xFE
                && first3Bytes[1] == (byte) 0xFF) {
            charset = "UTF-16BE";
            checked = true;
        } else if (first3Bytes[0] == (byte) 0xEF
                && first3Bytes[1] == (byte) 0xBB
                && first3Bytes[2] == (byte) 0xBF) {
            charset = "UTF-8";
            checked = true;
        }
        bis.reset();
        if (!checked) {
            int loc = 0;
            while ((read = bis.read()) != -1) {
                loc++;
                if (read >= 0xF0)
                    break;
                if (0x80 <= read && read <= 0xBF)
                    break;
                if (0xC0 <= read && read <= 0xDF) {
                    read = bis.read();
                    if (0x80 <= read && read <= 0xBF)
                        continue;
                    else
                        break;
                } else if (0xE0 <= read && read <= 0xEF) {
                    read = bis.read();
                    if (0x80 <= read && read <= 0xBF) {
                        read = bis.read();
                        if (0x80 <= read && read <= 0xBF) {
                            charset = "UTF-8";
                            break;
                        } else
                            break;
                    } else
                        break;
                }
            }
        }
        bis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return charset;
}
 
开发者ID:iPanelkegy,项目名称:MobileMedia,代码行数:66,代码来源:LyricUtils.java

示例15: InputStreamByteStream

import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
 * Construct a new InputStreamByteStream wrapping an InputStream.
 *
 * @param input the input stream to wrap
 */
public InputStreamByteStream(final InputStream input) {
    _inputStream = new BufferedInputStream(input, BUFFER_SIZE);
    _inputStream.mark(Integer.MAX_VALUE);
}
 
开发者ID:NCSC-NL,项目名称:PEF,代码行数:10,代码来源:InputStreamByteStream.java


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