當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。