功能简介 ByteArrayInputStream 和 ByteArrayOutputStream 提供了针对于字符数组 byte [] 的标准的IO操作方式 ? ByteArrayInputStream将会给一个byte buf[] 提供标准的IO操作方式 ByteArrayOutputStream则是将数据写入到内部的字节数组中 ByteArrayInputStream 详解 功能: 从提供的字节数组中,以IO的行为方式工作,进行读取数据 ByteArrayInputStream字段 protected byte[] buf 用于保存由该流的创建者提供的 byte 数组也就是构造方法传入 protected int count 个数 protected int mark 流中当前的标记位置构造时默认将 ByteArrayInputStream 对象标记在位置零处通过 构造方法 public ByteArrayInputStream(byte[] buf) 需要传入byte buf[] 字节数组作为他的缓冲区当前起始下标 pos 为0count为数组长度mark位置为
ByteArrayOutputStream流用来字节数组输出流在内存中创建一个字节数组缓冲区,所有发送到输出流的数据保存在该字节数组缓冲区中,默认初始化大小32个字节 ByteArrayInputStream ByteArrayOutputStream(1); try { bot.write(10); bot.write(11); bot.write(12); InputStream iot = new ByteArrayInputStream
代金券、腾讯视频VIP、QQ音乐VIP、QB、公仔等奖励等你来拿!
byteArrayInputStream = null; CSVParser parser = null; try { byteArrayInputStream = new ByteArrayInputStream (bytes); inputStreamReader = new InputStreamReader(byteArrayInputStream); //reader = new UnicodeReader (byteArrayInputStream,"utf-8"); //bufferedReader = new BufferedReader(reader); bufferedReader byteArrayInputStream = null; BOMInputStream bomInputStream = null; CSVParser parser = null; try { byteArrayInputStream = new ByteArrayInputStream(bytes); //使用BOMInputStream兼容bom头csv文件 bomInputStream
byteArrayInputStream = new ByteArrayInputStream("12312312312".getBytes()); 业务操作 } byteArrayInputStream.close(); } } 结果: ? 构建ByteArrayInputStream时: public ByteArrayInputStream(byte buf[]) { this.buf = buf; this.pos = ByteArrayInputStream对象时,指定了初始位置,那么mark属性也会随之改变: public ByteArrayInputStream(byte buf[], int offset, int byteArrayInputStream = new ByteArrayInputStream("12312312312".getBytes()); byte
byteArrayInputStream = null; 20 private byte[] result; 21 22 23 24 @Test 25 public void = new ByteArrayInputStream(result); 50 inputStream = new ObjectInputStream(byteArrayInputStream = null) byteArrayInputStream.close(); 59 if (inputStream ! = new ByteArrayInputStream(bytes); 41 inputStream = new ObjectInputStream(byteArrayInputStream = null) byteArrayInputStream.close(); 50 if (inputStream !
ByteArrayInputStream 1.1.1. 构造函数 1.1.2. 常用的方法 1.1.3. 实例 1.2. ByteArrayOutputStream 1.2.1. ByteArrayInputStream ByteArrayInputStream 包含一个内部缓冲区,该缓冲区包含从流中读取的字节。内部计数器跟踪read方法要提供的下一个字节。 关闭 ByteArrayInputStream无效。此类中的方法在关闭此流后仍可被调用,而不会产生任何 IOException。 主要的功能是从缓冲区读取字节 构造函数 ByteArrayInputStream(byte[] buf) 创建一个 ByteArrayInputStream,使用 buf 作为其缓冲区数组。 ByteArrayInputStream(byte[] buf, int offset, int length) 创建 ByteArrayInputStream,使用 buf 作为其缓冲区数组。
{ return body; } @Override public ServletInputStream getInputStream() throws IOException { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body); return new ServletInputStream() { @Override public int read() throws IOException { return byteArrayInputStream.read(); } @Override
javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; import java.io.ByteArrayInputStream ServletInputStream getInputStream() throws IOException { byte[] bytes = new byte[0]; ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); ServletInputStream servletInputStream @Override public int read() throws IOException { return byteArrayInputStream.read @Override public boolean isFinished() { return byteArrayInputStream.read
参考链接: Java Reader类 1、String –> InputStream InputStrem is = new ByteArrayInputStream(str.getBytes()) ; 或者 ByteArrayInputStream stream= new ByteArrayInputStream(str.getBytes()); 2、InputStream–>String
接口并重写 Object 类中的 clone() 方法; 实现 Serializable 接口,通过对象的序列化和反序列化实现克隆,可以实现真正的深度克隆,代码如下: import java.io.ByteArrayInputStream ObjectOutputStream oos = new ObjectOutputStream(bout); oos.writeObject(obj); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); ObjectInputStream ois = new ObjectInputStream (bin); return (T) ois.readObject(); // 说明:调用 ByteArrayInputStream 或 ByteArrayOutputStream
重置baos即清空baos image.compress(Bitmap.CompressFormat.JPEG, options, baos);//PNG 压缩options% } // 压缩尺寸 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); BitmapFactory.Options opts = new BitmapFactory.Options 即清空baos image.compress(Bitmap.CompressFormat.JPEG, options, baos);// 这里压缩options%,把压缩后的数据存放到baos中 } ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());// 把压缩后的数据baos存放到ByteArrayInputStream中 Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);// 把ByteArrayInputStream数据生成图片 return bitmap; } /** *
byteArrayInputStream = new ByteArrayInputStream(DESUtility.a(DESUtility.a(open, open.available()), DESUtility.a new WebResourceResponse("text/css", "UTF-8", byteArrayInputStream) : str.endsWith(".js") ? new WebResourceResponse("text/js", "UTF-8", byteArrayInputStream) : null; } else { byteArrayInputStream = new ByteArrayInputStream(DESUtility.a(DESUtility.a(open, open.available()), DESUtility.a new WebResourceResponse("text/css", "UTF-8", byteArrayInputStream) : str.endsWith(".js") ?
package com.serialize.utils; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream @param bytes * @return */ public static Object unserialize(byte[] bytes) { ByteArrayInputStream ObjectInputStream ois = null; try { // 反序列化 bais = new ByteArrayInputStream
2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=\n" + "</Signature>\n" + "</License>"; InputStream inputStream = new ByteArrayInputStream Exception e) { e.printStackTrace(); } return result; } // outputStream转inputStream public static ByteArrayInputStream ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos = (ByteArrayOutputStream) out; ByteArrayInputStream swapStream = new ByteArrayInputStream(baos.toByteArray()); return swapStream; }
byte[] bytes = IOUtils.toByteArray(url.openStream()); ByteArrayInputStream bis = new ByteArrayInputStream(bytes); BufferedImage img = javax.imageio.ImageIO.read int picWidth = picHeight * width/height; //下次读取该ByteArrayInputStream XWPFDocument.PICTURE_TYPE_JPEG, url.getFile(), Units.toEMU(picWidth), Units.toEMU(picHeight)); 好了,上面就是通过ByteArrayInputStream
org.apache.http.message.BasicHeader; import org.apache.http.protocol.HTTP; import org.apache.http.util.EntityUtils; import java.io.ByteArrayInputStream byte[] pureResult; try { pureResult = encode.getBytes("UTF-8"); ByteArrayInputStream inputStream = new ByteArrayInputStream(pureResult); ByteArrayOutputStream pureResult.length); GZIPInputStream inStream = new GZIPInputStream ( new ByteArrayInputStream
xmlConverter = new BpmnXMLConverter(); byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel); ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes); //IOUtils.copy(in, response.getOutputStream()); String xmlConverter = new BpmnXMLConverter(); byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel); ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes); InputStreamReader isr = new InputStreamReader(in,"utf-
Object deserialization(byte[] binaryByte) { ObjectInputStream objectInputStream = null; ByteArrayInputStream byteArrayInputStream = null; byteArrayInputStream = new ByteArrayInputStream(binaryByte); try { objectInputStream = new ObjectInputStream(byteArrayInputStream); return
然后,我写了个测试程序: import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException is = new ByteArrayInputStream(by); Hessian2Input hi = new Hessian2Input(is); return hi.readObject import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException ); kryo.setReferences(false); kryo.register(clazz, new JavaSerializer()); ByteArrayInputStream bais = new ByteArrayInputStream( new Base64().decode(obj)); Input input = new
Byte数组,则输出流为ByteArrayOutputStream即可; 执行完后,只需要toByteArray()就能得到byte[]; 五、byte[] ------>BufferedImage ByteArrayInputStream in = new ByteArrayInputStream(byte[]b); //将b作为输入流; BufferedImage image = ImageIO.read(InputStream in); //将in作为输入流,读取图片存入image中,而这里in可以为ByteArrayInputStream(); 六、显示BufferedImage public void paint import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); image = ImageIO.read(bin)
校园优惠套餐升级,云服务器1核2G10元/月起购
扫码关注腾讯云开发者
领取腾讯云代金券