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


Java FileUtils.readFileToByteArray方法代码示例

本文整理汇总了Java中org.apache.commons.io.FileUtils.readFileToByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.readFileToByteArray方法的具体用法?Java FileUtils.readFileToByteArray怎么用?Java FileUtils.readFileToByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.io.FileUtils的用法示例。


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

示例1: read

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void read(Object manifestPath) {
    File manifestFile = fileResolver.resolve(manifestPath);
    try {
        byte[] manifestBytes = FileUtils.readFileToByteArray(manifestFile);
        manifestBytes = prepareManifestBytesForInteroperability(manifestBytes);
        // Eventually convert manifest content to UTF-8 before handing it to java.util.jar.Manifest
        if (!DEFAULT_CONTENT_CHARSET.equals(contentCharset)) {
            manifestBytes = new String(manifestBytes, contentCharset).getBytes(DEFAULT_CONTENT_CHARSET);
        }
        // Effectively read the manifest
        Manifest javaManifest = new Manifest(new ByteArrayInputStream(manifestBytes));
        addJavaManifestToAttributes(javaManifest);
        addJavaManifestToSections(javaManifest);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:18,代码来源:DefaultManifest.java

示例2: onDone

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
public void onDone(String utteranceId) {
    //this allows us to keep track of multiple callbacks
    SpeechFromTextCallback callback = mCallbacks.get(utteranceId);
    if(callback != null){
        //get our cache file where we'll be storing the audio
        File cacheFile = getCacheFile(utteranceId);
        try {
            byte[] data = FileUtils.readFileToByteArray(cacheFile);
            callback.onSuccess(data);
        } catch (IOException e) {
            e.printStackTrace();
            //bubble up our error
            callback.onError(e);
        }

        cacheFile.delete();
        //remove the utteranceId from our callback once we're done
        mCallbacks.remove(utteranceId);
    }
}
 
开发者ID:vaibhavs4424,项目名称:AI-Powered-Intelligent-Banking-Platform,代码行数:22,代码来源:VoiceHelper.java

示例3: downloadNotebook

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@RequestMapping(value = "/exportNotebook")
public ResponseEntity<byte[]> downloadNotebook(@RequestParam(value = "type") String type, @RequestParam(value = "notebookId") int notebookId, HttpSession session) throws IOException, DocumentException{
    String leftPath = session.getServletContext().getRealPath("/temp/");
    //在服务器端生成zip文件
    File file = downloadService.downloadNotebook(notebookId, type, leftPath);
    //将文件返回给用户
    HttpHeaders headers = downloadService.genHttpHeaders(notebookId, type, "notebook");
    ResponseEntity<byte[]> result = new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
    file.delete();
    return result;
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:12,代码来源:NoteController.java

示例4: sync

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void sync() {
	File tempFile = new File(Constants.CONFIG_TEMP_DB);
	if(!tempFile.exists()){
		DialogHelper.alert("����", "ͬ���ļ������ڣ��������غ���ͬ����");
		return;
	}
	progressbar.setVisible(true);
	progressbar.setProgress(-1f);
	progressbar.setProgress(0.5f);
	progressbar.setProgress(-1f);
	iv_down.setDisable(true);
	iv_sync.setDisable(true);

	String projectDir = System.getProperty("user.dir");
	File destFile = new File(projectDir,"notebook.db");

	try {
		byte[] data = FileUtils.readFileToByteArray(tempFile);
		FileUtils.writeByteArrayToFile(destFile, data);
	} catch (IOException e) {
		e.printStackTrace();
		DialogHelper.alert("Error", e.toString());
	}
	progressbar.setProgress(1f);
	iv_down.setDisable(false);
	iv_sync.setDisable(false);
	DialogHelper.alert("Success", "ͬ���ɹ���-> \r\n" + tempFile.getAbsolutePath() + " �ѱ��ƶ��� " + projectDir);
}
 
开发者ID:coding-dream,项目名称:Notebook,代码行数:29,代码来源:SyncFragment.java

示例5: sendFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void sendFile(URL fileUrl, String contentType, DataOutputStream os) throws IOException, URISyntaxException {
  File file = new File(fileUrl.toURI());

  if (file.exists()) {
    os.writeBytes("HTTP/1.1 200 OK" + HTTP_EOL);
    os.writeBytes("Content-Type: " + contentType + HTTP_EOL);
    os.writeBytes(HTTP_EOL);

    byte[] bytes = FileUtils.readFileToByteArray(file);
    IOUtils.write(bytes, os);
  } else {
    os.writeBytes("HTTP/1.1 404 Not Found" + HTTP_EOL);
    os.writeBytes(HTTP_EOL);
    os.writeBytes("404 Not Found");
  }
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:17,代码来源:CallbackRequestHandler.java

示例6: testWriteFileAndReadAsBytes

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * Write ORC file using generic file base ORC writer and then read bytes of the file and read and
 * assert using memory (byte-array) based reader.
 *
 * @throws IOException if not able to write or read the data
 */
@Test
public void testWriteFileAndReadAsBytes() throws IOException {
  final File file = new File("/tmp/tmp_2.orc");
  file.deleteOnExit();

  final OrcFile.WriterOptions wOpts =
      OrcFile.writerOptions(new Configuration()).inspector(ROW_OI);
  final OrcFile.ReaderOptions rOpts = new OrcFile.ReaderOptions(new Configuration());

  final Writer writer = OrcFile.createWriter(new Path(file.toString()), wOpts);
  writeUsingOrcWriter(writer);
  final byte[] memOrcBytes = FileUtils.readFileToByteArray(file);

  readAndAssertUsingReader(OrcUtils.createReader(memOrcBytes, rOpts).rows());
}
 
开发者ID:ampool,项目名称:monarch,代码行数:22,代码来源:AOrcReaderWriterTest.java

示例7: getBytesFromFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Nullable
public static byte[] getBytesFromFile(@NotNull String filename) {
    try {
        return FileUtils.readFileToByteArray(new File(filename));
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:lebronzj,项目名称:pysonar2,代码行数:9,代码来源:$.java

示例8: getFileEncoding

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * 获取文件编码
 * @author eko.zhan at Jul 3, 2017 1:54:50 PM
 * @param file
 * @return
 * @throws IOException 
 */
public static String getFileEncoding(File file) throws IOException{
	UniversalDetector detector = new UniversalDetector(null);
	byte[] bytes = FileUtils.readFileToByteArray(file);
	detector.handleData(bytes, 0, bytes.length);
	detector.dataEnd();
	return detector.getDetectedCharset();
}
 
开发者ID:ekoz,项目名称:kbase-doc,代码行数:15,代码来源:HtmlUtils.java

示例9: downloadNote

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@RequestMapping(value = "/exportNote")
public ResponseEntity<byte[]> downloadNote(@RequestParam(value = "type") String type, @RequestParam(value = "noteId") int noteId, HttpSession session) throws IOException, DocumentException{
    String leftPath = session.getServletContext().getRealPath("/temp/");
    //在服务器端生成html文件
    File file = downloadService.downloadNote(noteId, type, leftPath);
    //将文件返回给用户
    HttpHeaders headers = downloadService.genHttpHeaders(noteId, type, "note");
    ResponseEntity<byte[]> result = new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED);
    file.delete();
    return result;
}
 
开发者ID:qinjr,项目名称:TeamNote,代码行数:12,代码来源:NoteController.java

示例10: createStepNodeValue

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
	protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
		if (isEnabled()) {
			try {
				Engine.logBeans.info("Hashing file \"" + sourceFilePath + "\"");

				File sourceFile = new File(sourceFilePath);
				if (!sourceFile.exists()) {
					throw new EngineException("Source file does not exist: " + sourceFilePath);
				}

				if (!sourceFile.isFile()) {
					throw new EngineException("Source file is not a file: " + sourceFilePath);
				}

				byte[] path = null;
				path = FileUtils.readFileToByteArray(sourceFile);
				
				String hash = null;
				if (hashAlgorithm == HashAlgorithm.MD5) {
					hash = org.apache.commons.codec.digest.DigestUtils.md5Hex(path);
				} else if (hashAlgorithm == HashAlgorithm.SHA1) {
					hash = org.apache.commons.codec.digest.DigestUtils.sha1Hex(path);
				}
				Engine.logBeans.info("File \"" + sourceFilePath	+ "\" has been hashed.");
				
//				Node hashNode = doc.createElement("hash");
//				hashNode.appendChild(doc.createTextNode(hash));
//				stepNode.appendChild(hashNode);
				
				Node text = doc.createTextNode(hash);
				stepNode.appendChild(text);
				
			} catch (Exception e) {
				setErrorStatus(true);
				throw new EngineException("Unable to compute hash code", e);
			}
		}
	}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:40,代码来源:GenerateHashCodeStep.java

示例11: upload

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
public String upload(File file) {
	FDFSFile fdfsFile=null;
	try {
		byte[] content = FileUtils.readFileToByteArray(file);
		String extension = FilenameUtils.getExtension(file.getName());
		fdfsFile = new FDFSFile(file.getName(), content, extension);
		return this.upload(fdfsFile);
	} catch (IOException e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:babymm,项目名称:mumu,代码行数:14,代码来源:FDFSAttachmentServiceImpl.java

示例12: readFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * 读取二进制文件
 * @param filePathAndName 带有完整绝对路径的文件名
 * @return 二进制数据
 * @version 2017-02-28
 */
public static byte[] readFile(String filePathAndName) {
	byte[] byteA = null;
	try {
		byteA = FileUtils.readFileToByteArray(new File(filePathAndName));
	} catch (IOException e) {
		e.printStackTrace();
		logger.error("调用ApacheCommon读二进制数据时:" + e.toString());
	}
	return byteA;
}
 
开发者ID:rocye,项目名称:wx-idk,代码行数:17,代码来源:FileIo.java

示例13: testUpload2

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void testUpload2() throws Exception {

    byte[] byteArray = FileUtils.readFileToByteArray(new File("/Users/ayg/Desktop/logo.gif"));
    CompletableFuture<FileId> path = client.upload("123.gif", byteArray);
    FileId fileId = path.get();
    System.out.println(fileId);
    CompletableFuture<FileMetadata> metadataGet = client.metadataGet(fileId);
    System.out.println(metadataGet.get(10, TimeUnit.SECONDS));
    System.out.println("==========");
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:12,代码来源:FastdfsClientTest.java

示例14: getJarBytesFromThisLocator

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * read the jar bytes in the file system
 */
// used when creating cluster config response
// and used when uploading the jars to another locator
public byte[] getJarBytesFromThisLocator(String group, String jarName) throws Exception {
  Configuration configuration = getConfiguration(group);

  File jar = getPathToJarOnThisLocator(group, jarName).toFile();

  if (configuration == null || !configuration.getJarNames().contains(jarName) || !jar.exists()) {
    return null;
  }

  return FileUtils.readFileToByteArray(jar);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:17,代码来源:ClusterConfigurationService.java

示例15: dispatch

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
@Nullable
public byte[] dispatch(@NonNull final String _command,
                       @NonNull final String[] _arguments,
                       @NonNull final String _outputFile) {
    final String[] commandWithArguments = Stream.concat(Arrays.stream(new String[]{_command}), Arrays.stream(_arguments))
            .toArray(String[]::new);

    try {
        final String formattedCommand = Stream
                .of(commandWithArguments)
                .collect(Collectors.joining(" ","[","]"));
        log.info("Executing process: " + formattedCommand);

        @Cleanup("destroy") final Process process = new ProcessBuilder(commandWithArguments).start();

        if (process.waitFor(30, TimeUnit.MINUTES)) {
            if (process.exitValue() == 0) {
                final File outputFile = new File(_outputFile);

                log.debug("Reading output produced by command");
                byte data[] = FileUtils.readFileToByteArray(outputFile);

                log.debug("Deleting file produced by command");
                final boolean deletionSuccessful = outputFile.delete();

                if (!deletionSuccessful) {
                    log.warn("Failed to delete temporary file: %s", outputFile.toPath());
                }

                return data;
            } else {
                log.error(String.format("Non-zero exit code (%d) executing command: %s", process.exitValue(), _command));
            }
        } else {
            log.error("Timed out executing command: " + _command);
        }
    } catch (Exception _e) {
        log.error("Failed to execute command: " + _command, _e);
    }

    return null;
}
 
开发者ID:jonfryd,项目名称:tifoon,代码行数:44,代码来源:ProcessExecutorPlugin.java


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