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


Java FileUtils.writeByteArrayToFile方法代码示例

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


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

示例1: buildSHADockerfile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public String buildSHADockerfile() throws Exception {
    File bindir = new File(inputDir, "bin");
    bindir.mkdirs();
    byte[] data = new byte[1024 * 1024 * 10];
    new Random().nextBytes(data);

    FileUtils.writeByteArrayToFile(new File(bindir, "test.bin"), data);

    builder.run("apt update")
        .run("apt upgrade -y")
        .workdir("/hello")
        .copyFromCsar("bin", "bin", ".")
        .compressRunCommands()
        .entrypoint("sha256sum", "test.bin");

    builder.write();
    return DigestUtils.sha256Hex(data);
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:19,代码来源:BaseDockerfileTest.java

示例2: createTestFiles

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static int createTestFiles(File sourceDir, int size)
    throws IOException{
  File subdir = new File(sourceDir, "subdir");
  int expected = 0;
  mkdirs(subdir);
  File top = new File(sourceDir, "top");
  FileUtils.write(top, "toplevel");
  expected++;
  for (int i = 0; i < size; i++) {
    String text = String.format("file-%02d", i);
    File f = new File(subdir, text);
    FileUtils.write(f, f.toString());
  }
  expected += size;

  // and write the largest file
  File largest = new File(subdir, "largest");
  FileUtils.writeByteArrayToFile(largest,
      ContractTestUtils.dataset(8192, 32, 64));
  expected++;
  return expected;
}
 
开发者ID:steveloughran,项目名称:cloudup,代码行数:23,代码来源:CloudupTestUtils.java

示例3: upload

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * @param request
 * @return
 * @throws Exception
 */
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody
public Result upload(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws Exception {
    ServletContext sc = request.getSession().getServletContext();
    String dir = sc.getRealPath("/upload");
    String type = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1, file.getOriginalFilename().length());

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
    Random r = new Random();
    String imgName = "";
    if (type.equals("jpg")) {
        imgName = sdf.format(new Date()) + r.nextInt(100) + ".jpg";
    } else if (type.equals("png")) {
        imgName = sdf.format(new Date()) + r.nextInt(100) + ".png";
    } else if (type.equals("jpeg")) {
        imgName = sdf.format(new Date()) + r.nextInt(100) + ".jpeg";
    } else {
        return null;
    }
    FileUtils.writeByteArrayToFile(new File(dir, imgName), file.getBytes());
    Result result = ResultGenerator.genSuccessResult();
    result.setData("upload/" + imgName);
    return result;
}
 
开发者ID:ZHENFENG13,项目名称:perfect-ssm,代码行数:30,代码来源:LoadImageController.java

示例4: should_download_success

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void should_download_success() throws Exception {
    String response = performRequestWith200Status(get("/credentials"));
    Credential[] credentials = Jsonable.parseArray(response, Credential[].class);
    Assert.assertEquals(4, credentials.length);

    response = performRequestWith200Status(get("/credentials/rsa-credential"));
    Assert.assertNotNull(response);

    // when: get download file
    MvcResult result = mockMvc.perform(get("/credentials/rsa-credential/download")).andExpect(status().isOk())
        .andReturn();

    File file = new File(String.valueOf(Paths.get(workspace.toString(), "test.zip")));
    FileUtils.writeByteArrayToFile(file, result.getResponse().getContentAsByteArray());

    // then: response is not null
    Assert.assertNotNull(response);

    // then: file is exists
    Assert.assertEquals(true, file.exists());
    ZipFile zipFile = new ZipFile(file);

    // them: zipfile has two files
    Assert.assertEquals(2, zipFile.size());
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:27,代码来源:CredentialControllerTest.java

示例5: copyRecordExecutableToFs

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private File copyRecordExecutableToFs(Context context, InputStream recordResource) throws IOException {
    byte[] recordBytes = IOUtils.toByteArray(recordResource);
    File recordFile = new File(context.getCacheDir(), "ros_android_bag_record");

    if (recordFile.exists()) recordFile.delete();

    FileUtils.writeByteArrayToFile(recordFile, recordBytes);

    boolean result = recordFile.setExecutable(true);
    if (result == false) {
        String errorText = "Could not set executable flag to " + recordFile.toString();
        Log.e(Common.LOG_TAG, errorText);
        throw new IllegalStateException(errorText);
    }
    return recordFile;
}
 
开发者ID:lamerman,项目名称:ros_android_bag,代码行数:17,代码来源:RecordLauncher.java

示例6: createTempFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private File createTempFile(byte[] image, String fileExtension, String fileName,
		String completeFileName) throws IOException, BuenOjoFileException {
	File newTempFile =File.createTempFile(fileName, fileExtension);

	//write temp file
	try {
		FileUtils.writeByteArrayToFile(newTempFile, image);
	} catch (IOException e) {
		//clean up previous file
		log.error(e.getMessage());
		String message = "no se puedo guardar archivo temporal para el archivo:"+completeFileName;
		log.error(message);
		throw new BuenOjoFileException(message);

	}
	return newTempFile;
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:18,代码来源:ImageResourceService.java

示例7: retrieveArtifact

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

    File dummyFile = new File(tmpdir, "test.bin");
    dummyFile.delete();
    byte[] data = ByteArrayUtils.generateRandomByteArray(new Random(123), 2048);
    FileUtils.writeByteArrayToFile(dummyFile, data);

    when(csarService.getCsar(VALID_CSAR_NAME).get().getTransformation(VALID_PLATFORM_NAME).get().getTargetArtifact())
        .thenReturn(Optional.of(new TargetArtifact(dummyFile)));

    mvc.perform(
        get(GET_ARTIFACTS_VALID_URL)
    )
        .andExpect(status().is(200))
        .andExpect(content().contentType("application/octet-stream"))
        .andExpect(content().bytes(data))
        .andReturn();
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:21,代码来源:TransformationControllerTest.java

示例8: writeMultipartFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private static File writeMultipartFile(MultipartFile multipartFile) {

		File file = null;

		try {
			if (!multipartFile.isEmpty()) {

				String multipartFileName = multipartFile.getOriginalFilename();
				String prefix = FilenameUtils.getBaseName(multipartFileName);
				String suffix = FilenameUtils.getExtension(multipartFileName);
				file = File.createTempFile(prefix, suffix);

				FileUtils.writeByteArrayToFile(file, multipartFile.getBytes());
			}
		}
		catch (Exception e) {
			LOG.error(e.getMessage(), e);
		}

		return file;
	}
 
开发者ID:chrisipa,项目名称:cloud-portal,代码行数:22,代码来源:VirtualMachineController.java

示例9: upload

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public @ResponseBody
String upload(MultipartFile file) {// ①

	try {
		FileUtils.writeByteArrayToFile(new File("f:/upload/" + file.getOriginalFilename()),file.getBytes()); // ②
		return "ok";
	} catch (IOException e) {
		e.printStackTrace();
		return "wrong";
	}
}
 
开发者ID:longjiazuo,项目名称:springMvc4.x-project,代码行数:13,代码来源:UploadController.java

示例10: injectFolder

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * Inject replacement operations for class files in the specified folder
 *
 * @param pool
 * @param folder
 * @param outFolder
 * @return
 * @throws IOException
 * @throws CannotCompileException
 * @throws NotFoundException
 * @throws Exception
 */
public static List<String> injectFolder(ClassPool pool,
                                        File folder,
                                        File outFolder,
                                        InjectParam injectParam) throws Exception {
    List<String> errorFiles = new ArrayList<String>();
    if (folder.exists() && folder.isDirectory()) {
        Collection<File> classFiles = FileUtils.listFiles(folder, new String[] {"class"}, true);
        for (File classFile : classFiles) {
            String className = toRelative(folder, classFile.getAbsolutePath());
            File outClassFile = new File(outFolder, className);
            outClassFile.getParentFile().mkdirs();
            className = StringUtils.replace(className, File.separator, ".");
            className = className.substring(0, className.length() - 6);
            byte[] codes;

            codes = inject(pool, className, injectParam);
            FileUtils.writeByteArrayToFile(outClassFile, codes);

        }
    }
    return errorFiles;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:35,代码来源:CodeInjectByJavassist.java

示例11: 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

示例12: taskScreenShot

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void taskScreenShot(WebDriver driver,File saveFile){
	if(saveFile.exists()){
		saveFile.delete();
	}
	byte[] src=((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);//.FILE);linux下非root用户,java创建临时文件存在问题
	log.info("截图文件字节长度"+src.length);
	try {
		FileUtils.writeByteArrayToFile(saveFile, src);
	} catch (IOException e) {
		e.printStackTrace();
		log.error("截图写入失败",e);
	}
}
 
开发者ID:xbynet,项目名称:crawler,代码行数:14,代码来源:WindowUtil.java

示例13: upload

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@RequestMapping(value = "/upload", method = RequestMethod.POST)
//使用MultipartFile 接收文件
public @ResponseBody
String upload(MultipartFile file) {
    try {
        String file_name = file.getOriginalFilename();
        FileUtils.writeByteArrayToFile(new File("d:/ssh/" + file.getOriginalFilename()), file.getBytes());
        return "ok";
    } catch (IOException e) {
        e.printStackTrace();
        return "wrong";
    }
}
 
开发者ID:shuaishuaila,项目名称:java_springboot,代码行数:14,代码来源:UploadController.java

示例14: downloadSwaggerAPI

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void downloadSwaggerAPI() throws Exception {
    String url = getHttpUrl() + "v2/api-docs";
    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder().url(url).build();
    String result = client.newCall(request).execute().body().string();
    FileUtils.writeByteArrayToFile(new File(SWAGGER_OUTPUT_DIR), result.getBytes());
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:9,代码来源:SwaggerAPIDownloadIT.java

示例15: saveFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
public void saveFile(@NonNull final String _filename,
                     @NonNull final byte[] _data) {
    try {
        FileUtils.writeByteArrayToFile(new File(_filename), _data);
    } catch (IOException _e) {
        log.error("Failed to save report file", _e);
    }
}
 
开发者ID:jonfryd,项目名称:tifoon,代码行数:10,代码来源:ReportFileIOServiceImpl.java


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