本文整理汇总了Java中org.apache.commons.io.IOUtils.toByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.toByteArray方法的具体用法?Java IOUtils.toByteArray怎么用?Java IOUtils.toByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.IOUtils
的用法示例。
在下文中一共展示了IOUtils.toByteArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public static final byte[] get(String url, Map<String, String> headers) {
try {
URLConnection conn = new URL(url).openConnection();
if (headers != null) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
conn.setRequestProperty(entry.getKey(), entry.getValue());
}
}
InputStream is = conn.getInputStream();
byte[] result = IOUtils.toByteArray(is);
is.close();
List<String> header = conn.getHeaderFields().get("Content-Disposition");
if (header != null && header.size() > 0) {
headers.put("Content-Disposition", header.get(0));
}
return result;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例2: openFile
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void openFile(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String name=req.getParameter("name");
name=decode(name);
ProcessProvider targetProvider=ProcessProviderUtils.getProcessProvider(name);
if(targetProvider==null){
throw new RuntimeException("Unsupport file : "+name);
}
InputStream inputStream=targetProvider.loadProcess(name);
try{
byte[] bytes=IOUtils.toByteArray(inputStream);
ProcessDefinition process=ProcessParser.parseProcess(bytes, 0, true);
writeObjectToJson(resp, process);
}catch(Exception ex){
throw new RuntimeException(ex);
}finally{
IOUtils.closeQuietly(inputStream);
}
}
示例3: getProcessInstanceImage
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@RequestMapping(value = "/process-instance/{processInstanceId}/image", method = RequestMethod.GET, name="流程实例流程图")
public ResponseEntity<byte[]> getProcessInstanceImage(@PathVariable String processInstanceId) {
ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
ProcessDefinition pde = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
if (pde != null && pde.hasGraphicalNotation()) {
BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
InputStream resource = diagramGenerator.generateDiagram(bpmnModel,"png", runtimeService.getActiveActivityIds(processInstance.getId()),
Collections.<String> emptyList(),
processEngineConfiguration.getActivityFontName(),
processEngineConfiguration.getLabelFontName(),
processEngineConfiguration.getAnnotationFontName(),
processEngineConfiguration.getClassLoader(), 1.0);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.IMAGE_PNG);
try {
return new ResponseEntity<byte[]>(IOUtils.toByteArray(resource), responseHeaders,HttpStatus.OK);
} catch (Exception e) {
throw new FlowableIllegalArgumentException("Error exporting diagram", e);
}
} else {
throw new FlowableIllegalArgumentException("Process instance with id '" + processInstance.getId()+ "' has no graphical notation defined.");
}
}
示例4: getContent
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
protected String getContent(String charset, HttpResponse response) throws IOException {
if(charset == null) {
long contentLength = response.getEntity().getContentLength();
if(response.getFirstHeader("Content-Type") != null
&& !response.getFirstHeader("Content-Type").getValue().toLowerCase().contains("text/html"))
throw new IllegalArgumentException("此链接为非html内容,不下载,内容类型:" + response.getFirstHeader("Content-Type"));
else if(contentLength>value.getMaxDownloadLength())
throw new IllegalArgumentException("网页内容长度超过最大限制,要求最大长度:" + value.getMaxDownloadLength() + ",实际长度:" + contentLength);
byte[] contentBytes = IOUtils.toByteArray(response.getEntity().getContent());
String htmlCharset = UrlUtils.getCharset(response.getEntity().getContentType().getValue());
if (htmlCharset != null) {
return new String(contentBytes, htmlCharset);
} else {
LOG.warn("自动探测字符集失败, 使用 {} 作为字符集。请在Site.setCharset()指定字符集", Charset.defaultCharset());
return new String(contentBytes);
}
} else
return IOUtils.toString(response.getEntity().getContent(), charset);
}
示例5: UniformFuzzyHash
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* Builds a Uniform Fuzzy Hash from an input stream of data and a factor.
*
* @param data Input stream of data.
* @param factor Relation between data length and the hash mean number of blocks.
* Must be greater than 2 and must be odd.
* @throws IOException If an IOException occurs reading the input stream of data.
*/
public UniformFuzzyHash(
InputStream data,
int factor)
throws IOException {
this();
if (data == null) {
throw new NullPointerException("Data is null.");
}
byte[] byteArray = IOUtils.toByteArray(data);
computeUniformFuzzyHash(byteArray, factor);
}
示例6: getFlowContent
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public synchronized byte[] getFlowContent(final String bucketId, final String flowId, final int version) throws FlowPersistenceException {
final File snapshotFile = getSnapshotFile(bucketId, flowId, version);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Retrieving snapshot with filename {}", new Object[] {snapshotFile.getAbsolutePath()});
}
if (!snapshotFile.exists()) {
return null;
}
try (final InputStream in = new FileInputStream(snapshotFile)){
return IOUtils.toByteArray(in);
} catch (IOException e) {
throw new FlowPersistenceException("Error reading snapshot file: " + snapshotFile.getAbsolutePath(), e);
}
}
示例7: getReproguardMapping
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public Map<String, String> getReproguardMapping(String jarPath) {
Map<String, String> renameMap = new HashMap<>();
try {
JarFile file = new JarFile(new File(jarPath));
Enumeration<JarEntry> enumeration = file.entries();
while (enumeration.hasMoreElements()) {
JarEntry jarEntry = enumeration.nextElement();
InputStream inputStream = file.getInputStream(jarEntry);
String entryName = jarEntry.getName();
String className;
byte[] sourceClassBytes = IOUtils.toByteArray(inputStream);
if (entryName.endsWith(".class")) {
className = Utils.path2Classname(entryName);
String newClassname = getReproguardClassname(className);
TextFileWritter.getDefaultWritter().println(className + (newClassname != null ? " -> " + newClassname : ""));
// analyzeClassNames(className, sourceClassBytes);
}
}
} catch (IOException e) {
e.printStackTrace();
}
TextFileWritter.getDefaultWritter().close();
return renameMap;
}
示例8: getSSL
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public static void getSSL(String url, AsyncHttpResponseHandler responseHandler) {
try {
URL page = new URL(url); // Process the URL far enough to find the right handler
HttpURLConnection urlConnection = (HttpURLConnection) page.openConnection();
String token = Utility.loadData("token", String.class);
if (token != null) {
urlConnection.setRequestProperty("Authorization", token);
}
urlConnection.setUseCaches(false); // Don't look at possibly cached data
// Read it all and print it out
InputStream stream = urlConnection.getInputStream();
byte[] bytes = IOUtils.toByteArray(stream);
int code = urlConnection.getResponseCode();
if (code >= 200 && code < 400) {
responseHandler.sendSuccessMessage(code, null, bytes);
} else {
responseHandler.sendFailureMessage(code, null, bytes, new IOException());
}
} catch (IOException e) {
e.printStackTrace();
responseHandler.sendFailureMessage(0, null, new byte[1], e);
}
}
示例9: shouldGetImageData
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void shouldGetImageData() throws IOException {
String url = "http://cdn-st4.rtr-vesti.ru/vh/pictures/bq/128/712/3.jpg";
// ImageDataResponse response = task.doInBackground(url);
// Assert.assertNotNull(response);
// Assert.assertEquals(url, response.getUrl());
try (InputStream resource = getClass().getClassLoader().getResourceAsStream("podcasts/image-1.jpg")) {
byte[] bytes = IOUtils.toByteArray(resource);
// Assert.assertArrayEquals(bytes, Base64.decodeBase64(response.getData()));
}
}
示例10: ExtClassLoader
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public ExtClassLoader() throws IOException {
super(Thread.currentThread().getContextClassLoader());
{
byte[] bytes;
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("kotlin/ResponseKotlin2.clazz");
bytes = IOUtils.toByteArray(is);
is.close();
super.defineClass("ResponseKotlin2", bytes, 0, bytes.length);
}
}
示例11: ExtClassLoader
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public ExtClassLoader() throws IOException {
super(Thread.currentThread().getContextClassLoader());
{
byte[] bytes;
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("kotlin/ClassWithPairMixedTypes.clazz");
bytes = IOUtils.toByteArray(is);
is.close();
super.defineClass("ClassWithPairMixedTypes", bytes, 0, bytes.length);
}
}
示例12: setup
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Before
public void setup() throws IOException {
final InputStream modelStream = teleporter.getService(LaunchpadContentProvider.class).getResourceAsStream(MODEL_RESOURCE_PATH);
assertNotNull("Expecting embedded model resource at " + MODEL_RESOURCE_PATH, modelStream);
try {
modelContent = new String(IOUtils.toByteArray(modelStream));
} finally {
modelStream.close();
}
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:11,代码来源:EmbeddedModelTest.java
示例13: readTestResource
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* Read a test resource file's contents.
* @param fileName File to read.
* @return File's contents as String.
* @throws FileNotFoundException If somethig is wrong.
* @throws IOException If somethig is wrong.
*/
private String readTestResource(final String fileName)
throws FileNotFoundException, IOException {
return new String(
IOUtils.toByteArray(
new FileInputStream(
new File("src/test/resources/" + fileName)
)
)
);
}
示例14: importFile
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
* Imports a file of unknown type.
*
* @param file The file to open
* @param globalConfig The current global config
* @param currentHistory history of the opened files to this point
* @param importHybridSpecificationHandler A file handler (invoked if the file is a Specification)
* @param importStvsRootModelHandler A file handler (invoked if the file is a Session)
* @param codeConsumer A file handler (invoked if the file is a code file)
* @throws IOException general io exception
* @throws ImportException general importing exception
*/
public static void importFile(File file, GlobalConfig globalConfig, History currentHistory,
ImportHybridSpecificationHandler importHybridSpecificationHandler,
ImportStvsRootModelHandler importStvsRootModelHandler, ImportCodeHandler codeConsumer)
throws IOException, ImportException {
StringWriter writer = new StringWriter();
byte[] byteArray = IOUtils.toByteArray(new FileInputStream(file));
IOUtils.copy(new ByteArrayInputStream(byteArray), writer, "utf8");
String inputString = writer.toString();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
try {
Document doc = dbf.newDocumentBuilder().parse(new InputSource(new StringReader(inputString)));
if (doc != null && doc.getFirstChild() != null) {
Node rootNode = doc.getFirstChild();
switch (rootNode.getNodeName()) {
case "session":
importStvsRootModelHandler
.accept(importSession(file, ImportFormat.XML, globalConfig, currentHistory));
return;
case "specification":
importHybridSpecificationHandler.accept(importHybridSpec(file, ImportFormat.XML));
return;
default:
codeConsumer.accept(importStCode(file));
return;
}
}
} catch (SAXException | ParserConfigurationException | ImportException e) {
// ignore, because it might have been code
}
codeConsumer.accept(importStCode(file));
}
示例15: onCreate
import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hub_main);
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
setTitle("Tap In Hub");
yeeid = (TextView)findViewById(R.id.yeeid);
spinner = (ProgressBar)findViewById(R.id.progressBar);
gifImageView = (GifImageView)findViewById(R.id.gifImageView);
try
{
InputStream inputStream = getAssets().open("nfc.gif");
byte[] bytes = IOUtils.toByteArray(inputStream);
gifImageView.setBytes(bytes);
gifImageView.startAnimation();
}
catch (IOException e)
{}
gifImageView.setVisibility(View.VISIBLE);
spinner.setVisibility(View.INVISIBLE);
}