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


Java ByteArrayInputStream类代码示例

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


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

示例1: decompress

import java.io.ByteArrayInputStream; //导入依赖的package包/类
public static String decompress(byte[] compressed) {
    if(compressed==null) return null;
    ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
    try {
        GZIPInputStream gis = new GZIPInputStream(bis);
        BufferedReader br = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
        StringBuilder sb = new StringBuilder();
        String line;
        while((line = br.readLine()) != null) {
            sb.append(line);
        }
        br.close();
        gis.close();
        bis.close();
        return sb.toString();
    }catch (IOException ex){
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:21,代码来源:BundleUtils.java

示例2: exportTemplate

import java.io.ByteArrayInputStream; //导入依赖的package包/类
/**
 * 导出当前网站当前的模版文件,包含模版页面,模版变量、栏目
 * @throws FileNotFoundException
 * @throws UnsupportedEncodingException
 */
@RequestMapping("exportTemplate")
public void exportTemplate(HttpServletRequest request, HttpServletResponse response) throws FileNotFoundException, UnsupportedEncodingException {
	BaseVO vo = templateService.exportTemplate(request);
	String fileName = "template"+DateUtil.currentDate("yyyyMMdd_HHmm")+".wscso".toString(); // 文件的默认保存名
	//读到流中
	InputStream inStream = new ByteArrayInputStream(vo.getInfo().getBytes("UTF-8"));  
	
	AliyunLog.addActionLog(getSiteId(), "导出当前网站当前的模版文件");
	
	// 设置输出的格式
	response.reset();
	response.setContentType("bin");
	response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
        // 循环取出流中的数据
	byte[] b = new byte[1000];
	int len;
	try {
	    while ((len = inStream.read(b)) > 0)
	        response.getOutputStream().write(b, 0, len);
	    inStream.close();
	} catch (IOException e) {
	    e.printStackTrace();
	}
}
 
开发者ID:xnx3,项目名称:wangmarket,代码行数:30,代码来源:TemplateController.java

示例3: getResizedMedia

import java.io.ByteArrayInputStream; //导入依赖的package包/类
public MediaStream getResizedMedia(@NonNull Context context,
                                   @NonNull MasterSecret masterSecret,
                                   @NonNull Attachment attachment)
    throws IOException
{
  if (!canResize(attachment)) {
    throw new UnsupportedOperationException("Cannot resize this content type");
  }

  try {
    // XXX - This is loading everything into memory! We want the send path to be stream-like.
    return new MediaStream(new ByteArrayInputStream(BitmapUtil.createScaledBytes(context, new DecryptableUri(masterSecret, attachment.getDataUri()), this)),
                           ContentType.IMAGE_JPEG);
  } catch (BitmapDecodingException e) {
    throw new IOException(e);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:18,代码来源:MediaConstraints.java

示例4: testLoadWithoutEncoding

import java.io.ByteArrayInputStream; //导入依赖的package包/类
/**
 * Test loadFromXML with a document that does not have an encoding declaration
 */
static void testLoadWithoutEncoding() throws IOException {
    System.out.println("testLoadWithoutEncoding");

    Properties expected = new Properties();
    expected.put("foo", "bar");

    String s = "<?xml version=\"1.0\"?>" +
               "<!DOCTYPE properties SYSTEM \"http://java.sun.com/dtd/properties.dtd\">" +
               "<properties>" +
               "<entry key=\"foo\">bar</entry>" +
               "</properties>";
    ByteArrayInputStream in = new ByteArrayInputStream(s.getBytes("UTF-8"));
    Properties props = new Properties();
    props.loadFromXML(in);

    if (!props.equals(expected)) {
        System.err.println("loaded: " + props + ", expected: " + expected);
        throw new RuntimeException("Test failed");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:LoadAndStoreXML.java

示例5: shouldSerializeCorrectly

import java.io.ByteArrayInputStream; //导入依赖的package包/类
@Test
public void shouldSerializeCorrectly() throws Exception {
    Transaction transaction = new Transaction("TRANSACTION_TOKEN", "RECOVERY_CODE", "OTP_SECRET");

    // save
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
    objectOutputStream.writeObject(transaction);
    objectOutputStream.close();
    outputStream.close();

    byte[] binaryData = outputStream.toByteArray();

    // restore
    ByteArrayInputStream inputStream = new ByteArrayInputStream(binaryData);
    ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
    Transaction restoredTransaction = (Transaction) objectInputStream.readObject();
    objectInputStream.close();
    inputStream.close();

    assertThat(restoredTransaction.getTransactionToken(), is(equalTo("TRANSACTION_TOKEN")));
    assertThat(restoredTransaction.getRecoveryCode(), is(equalTo("RECOVERY_CODE")));
}
 
开发者ID:auth0,项目名称:Guardian.java,代码行数:24,代码来源:TransactionTest.java

示例6: byteArrayToObject

import java.io.ByteArrayInputStream; //导入依赖的package包/类
/**
 * 
 * 功能描述:自己数组转换成对象 <br>
 * 〈功能详细描述〉
 * 
 * @param bytes
 *            bytes
 * @return object
 * @throws IOException
 *             ioexception
 * @see [相关类/方法](可选)
 * @since [产品/模块版本](可选)
 */
public static Object byteArrayToObject(byte[] bytes) throws IOException {
    if (bytes == null || bytes.length <= 0) {
        return null;
    }
    Object obj = null;
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(bis));
        obj = ois.readObject();
        bis.close();
        ois.close();
    } catch (ClassNotFoundException e) {
        logger.error(e.getMessage());
    }
    return obj;
}
 
开发者ID:ningyu1,项目名称:redis-client,代码行数:30,代码来源:CacheUtils.java

示例7: testSerialization

import java.io.ByteArrayInputStream; //导入依赖的package包/类
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {

    SignalRenderer r1 = new SignalRenderer();
    SignalRenderer r2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(r1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        r2 = (SignalRenderer) in.readObject();
        in.close();
    }
    catch (Exception e) {
        System.out.println(e.toString());
    }
    assertEquals(r1, r2);

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:25,代码来源:SignalRendererTests.java

示例8: newData

import java.io.ByteArrayInputStream; //导入依赖的package包/类
@Override
public void newData(byte[] bytes) {
	if(Dashboard.visionInitialized()){
		Mat m = CvProcessing.byteArray2Mat(bytes);
		Dashboard.setForVision(m);
	}
	if(mode == DisplayMode.Normal){
		ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        Iterator<?> readers = ImageIO.getImageReadersByFormatName("jpeg");
 
        ImageReader reader = (ImageReader) readers.next();
        Object source = bis; 
       
		try {
			ImageInputStream iis = ImageIO.createImageInputStream(source); 
		    reader.setInput(iis, true);
		    ImageReadParam param = reader.getDefaultReadParam();
		    BufferedImage image = reader.read(0, param); 
		    setImage(image);
		} catch (IOException e) {
		}
	}

}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:25,代码来源:CameraViewer.java

示例9: store

import java.io.ByteArrayInputStream; //导入依赖的package包/类
@Override
public void store(BuildCacheKey key, BuildCacheEntryWriter writer) {
  logger.info("Start storing cache entry '{}' in S3 bucket", key.getHashCode());
  ObjectMetadata meta = new ObjectMetadata();
  meta.setContentType(BUILD_CACHE_CONTENT_TYPE);

  try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
    writer.writeTo(os);
    meta.setContentLength(os.size());
    try (InputStream is = new ByteArrayInputStream(os.toByteArray())) {
        PutObjectRequest request = getPutObjectRequest(key, meta, is);
        if(this.reducedRedundancy) {
          request.withStorageClass(StorageClass.ReducedRedundancy);
        }
        s3.putObject(request);
    }
  } catch (IOException e) {
    throw new BuildCacheException("Error while storing cache object in S3 bucket", e);
  }
}
 
开发者ID:myniva,项目名称:gradle-s3-build-cache,代码行数:21,代码来源:AwsS3BuildCacheService.java

示例10: testSerialization

import java.io.ByteArrayInputStream; //导入依赖的package包/类
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    MyComparableObjectSeries s1 = new MyComparableObjectSeries("A");
    s1.add(new Integer(1), "ABC");
    MyComparableObjectSeries s2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(s1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        s2 = (MyComparableObjectSeries) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(s1, s2);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:24,代码来源:ComparableObjectSeriesTests.java

示例11: getTransferData

import java.io.ByteArrayInputStream; //导入依赖的package包/类
@Override
public Object getTransferData(DataFlavor flavor)
				throws UnsupportedFlavorException, IOException {
	if (flavor.equals(FLAVORS[0])) { // RTF
		return new ByteArrayInputStream(data==null ? new byte[0] : data);
	}
	else if (flavor.equals(FLAVORS[1])) { // stringFlavor
		return data==null ? "" : RtfToText.getPlainText(data);
	}
	else if (flavor.equals(FLAVORS[2])) { // plainTextFlavor (deprecated)
		String text = ""; // Valid if data==null
		if (data!=null) {
			text = RtfToText.getPlainText(data);
		}
		return new StringReader(text);
	}
	else {
		throw new UnsupportedFlavorException(flavor);
	}
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:21,代码来源:RtfTransferable.java

示例12: mergeFromJson

import java.io.ByteArrayInputStream; //导入依赖的package包/类
private void mergeFromJson(
    String json, boolean ignoringUnknownFields, Builder builder, Message... additionalTypes)
    throws IOException {
  MessageMarshaller.Builder marshallerBuilder =
      MessageMarshaller.builder()
          .register(builder.getDefaultInstanceForType())
          .ignoringUnknownFields(ignoringUnknownFields);
  for (Message prototype : additionalTypes) {
    marshallerBuilder.register(prototype);
  }
  MessageMarshaller marshaller = marshallerBuilder.build();
  marshaller.mergeValue(json, builder);

  Message.Builder builder2 = builder.build().newBuilderForType();
  marshaller.mergeValue(json.getBytes(StandardCharsets.UTF_8), builder2);
  assertThat(builder2.build()).isEqualTo(builder.build());

  Message.Builder builder3 = builder.build().newBuilderForType();
  try (ByteArrayInputStream bis =
      new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8))) {
    marshaller.mergeValue(bis, builder3);
  }
  assertThat(builder3.build()).isEqualTo(builder.build());
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:25,代码来源:MessageMarshallerTest.java

示例13: assertObjectWithType

import java.io.ByteArrayInputStream; //导入依赖的package包/类
<T> void assertObjectWithType(T data, Class<T> clazz) throws Exception {
    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeObject(data);
    objectOutput.flushBuffer();

    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
            byteArrayOutputStream.toByteArray());
    ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);

    assertEquals(data, (T) deserialize.readObject(clazz));

    try {
        deserialize.readObject(clazz);
        fail();
    } catch (IOException expected) {
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:18,代码来源:AbstractSerializationTest.java

示例14: createFileDeleteIfExists

import java.io.ByteArrayInputStream; //导入依赖的package包/类
/**
 * Create a file in a folder with the specified name and content
 * 
 * @param fullpath
 * @param filename
 * @param content
 * @throws CoreException
 * @throws InterruptedException
 */
public static IFile createFileDeleteIfExists(String fullpath, String filename, String content,
		IProgressMonitor monitor) throws CoreException, InterruptedException {
	SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
	subMonitor.setTaskName("Create file delete if it exists " + fullpath);
	IFile newFile;
	try {
		IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
		IContainer container = (IContainer) wroot.findMember(new Path(fullpath));
		newFile = container.getFile(new Path(filename));
		if (newFile.exists()) {
			JDTManager.rename(newFile, new NullProgressMonitor());
			newFile.delete(true, new NullProgressMonitor());
		}
		subMonitor.split(30);
		byte[] source = content.getBytes(Charset.forName("UTF-8"));
		newFile.create(new ByteArrayInputStream(source), true, new NullProgressMonitor());
		subMonitor.split(70);
	} finally {
		subMonitor.done();
	}
	return newFile;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:32,代码来源:ResourceManager.java

示例15: onSuccess

import java.io.ByteArrayInputStream; //导入依赖的package包/类
@Override
public void onSuccess(int code, ByteArrayInputStream is, Object[] args) {
    try {
        Result res = XmlUtils.toBean(ResultBean.class, is).getResult();
        if (res.OK()) {
            AppContext.showToastShort(R.string.delete_success);
            mAdapter.removeItem(args[0]);
            // setTweetCommentCount();
        } else {
            AppContext.showToastShort(res.getErrorMessage());
        }
    } catch (Exception e) {
        e.printStackTrace();
        onFailure(code, e.getMessage(), args);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:17,代码来源:TeamTweetDetailFragment.java


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