【JavaSE】Java问题总结

使用BufferedInputStream时OutOfMemoryError异常

eclipse Luna安装subversion(SVN)

 

  •  使用BufferedInputStream时OutOfMemoryError异常。

为了InputStream可以重复读取,我们会把某个InputStream实例用BufferedInputStream装饰。

BufferedInputStream bis = new BufferedInputStream(is);

bis.mark(Integer.MAX_VALUE);

//while bis.read(...)

bis.reset

实际上是BufferedInputStream将mark之后的数据存起来,调用reset时恢复,因此,当InputStream数据过多时,就会出问题,尤其是我在手机上做Android开发时,当数据超过13K时,就可能出内存不足,即抛下下面的异常:

java.lang.RuntimeException: An error occured while executing doInBackground()

…………

Caused by: java.lang.OutOfMemoryError

    at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:156)

    at java.io.BufferedInputStream.read(BufferedInputStream.java:309)

    at java.io.InputStream.read(InputStream.java:163)

    at ……

因此,mark方法需要记录的字节数目上限尽量不要设置成Integer.MAX_VALUE。

 

  •  eclipse Luna安装subversion(SVN)

最新的eclipse的svn插件安装起来很奇怪,和以前不大一样,弄了好一会才好,第一步和以前一样,安装subversion插件:

打开http://www.eclipse.org/subversive/downloads.php,拖拽“install”到eclipse里面就会自己安装,但是和以前不一样的是,安装完成之后不能直接使用了,缺一个svn connector,第二步呢就是要安装svn的connector,打开http://www.polarion.com/products/svn/subversive/download.php?utm_source=eclipse.org&utm_medium=link&utm_campaign=subversive,根据指示找到链接(http://community.polarion.com/projects/subversive/download/eclipse/4.0/luna-site/),进入Eclipse->Help->Install New Software,把这个链接粘进去进行安装,安装完毕之后重启就可以了。

你可能感兴趣的:(JavaSE)