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


Java IOUtils.write方法代码示例

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


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

示例1: save

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private Configuration save()
{
	try
	{
		if(json.entrySet().size() == 0)
		{
			if(this.file.exists())
			{
				this.file.delete();
			}
		}
		else
		{
			if(!this.file.exists())
			{
				this.file.createNewFile();
			}
			IOUtils.write(json.toString(), new FileOutputStream(this.file), "UTF-8");
		}
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	return this;
}
 
开发者ID:timmyrs,项目名称:SuprDiscordBot,代码行数:27,代码来源:Configuration.java

示例2: code

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
 * 生成代码
 */
@RequestMapping("/code")
@RequiresPermissions("sys:generator:code")
public void code(HttpServletRequest request, HttpServletResponse response) throws IOException{
	String[] tableNames = new String[]{};
	//获取表名,不进行xss过滤
	HttpServletRequest orgRequest = XssHttpServletRequestWrapper.getOrgRequest(request);
	String tables = orgRequest.getParameter("tables");
	tableNames = JSON.parseArray(tables).toArray(tableNames);
	
	byte[] data = sysGeneratorService.generatorCode(tableNames);
	
	response.reset();  
       response.setHeader("Content-Disposition", "attachment; filename=\"renren.zip\"");  
       response.addHeader("Content-Length", "" + data.length);  
       response.setContentType("application/octet-stream; charset=UTF-8");  
 
       IOUtils.write(data, response.getOutputStream());  
}
 
开发者ID:guolf,项目名称:pds,代码行数:22,代码来源:SysGeneratorController.java

示例3: write

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public void write(final Collection<S> collection, final Local file) throws AccessDeniedException {
    final NSArray list = new NSArray(collection.size());
    int i = 0;
    for(S bookmark : collection) {
        list.setValue(i, bookmark.<NSDictionary>serialize(SerializerFactory.get()));
        i++;
    }
    final String content = list.toXMLPropertyList();
    final OutputStream out = file.getOutputStream(false);
    try {
        IOUtils.write(content, out, Charset.forName("UTF-8"));
    }
    catch(IOException e) {
        throw new AccessDeniedException(String.format("Cannot create file %s", file.getAbsolute()), e);
    }
    finally {
        IOUtils.closeQuietly(out);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:21,代码来源:PlistWriter.java

示例4: writeResponseResult

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
protected void writeResponseResult(HttpServletRequest request, HttpServletResponse response) throws Exception {
	Set<String> classNames = CachedIntrospector.getClassNames();
	StringBuilder sb = new StringBuilder();
	for (String className : classNames) {
		sb.append(".")
		  .append(className.replaceAll("\\.", "-"))
		  .append("-16")
		  .append(" {background-image:url(")

		  .append("../../admin/services/database_objects.GetIcon?className=")
		  .append(className)
		  .append(") !important;")
		  .append("}\r\n");
	}

	response.setContentType(MimeType.Css.value());
	IOUtils.write(sb.toString(), response.getOutputStream(), "UTF-8");
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:20,代码来源:GetTreeIconsCSS.java

示例5: create

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public Payment create(Payment payment) {
    try {
        HttpURLConnection con = getConnection("/payments");
        con.setRequestMethod("POST");
        con.setDoOutput(true);
        con.setRequestProperty("Content-Type", "application/json");
        String json = JsonUtils.toJson(payment);
        IOUtils.write(json, con.getOutputStream(), "utf-8");
        int status = con.getResponseCode();
        if (status != 200) {
            throw new RuntimeException("status code was " + status);
        }
        String content = IOUtils.toString(con.getInputStream(), "utf-8");
        return JsonUtils.fromJson(content, Payment.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:intuit,项目名称:karate,代码行数:19,代码来源:Consumer.java

示例6: download

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
 * 从hadoop中下载文件
 *
 * @param taskName
 * @param filePath
 */
public static void download(String taskName, String filePath, boolean existDelete) {
    File file = new File(filePath);
    if (file.exists()) {
        if (existDelete) {
            file.deleteOnExit();
        } else {
            return;
        }
    }
    String hadoopAddress = propertyConfig.getProperty("sqoop.task." + taskName + ".tolink.linkConfig.uri");
    String itemmodels = propertyConfig.getProperty("sqoop.task." + taskName + ".recommend.itemmodels");
    try {
        DistributedFileSystem distributedFileSystem = distributedFileSystem(hadoopAddress);
        FSDataInputStream fsDataInputStream = distributedFileSystem.open(new Path(itemmodels));
        byte[] bs = new byte[fsDataInputStream.available()];
        fsDataInputStream.read(bs);
        log.info(new String(bs));

        FileOutputStream fileOutputStream = new FileOutputStream(new File(filePath));
        IOUtils.write(bs, fileOutputStream);
        IOUtils.closeQuietly(fileOutputStream);
    } catch (IOException e) {
        log.error(e);
    }
}
 
开发者ID:babymm,项目名称:mmsns,代码行数:32,代码来源:HadoopUtil.java

示例7: write

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public void write(List<MessageItem> items) throws IOException{
	if(StringUtils.isBlank(path)){
		return;
	}
	StringBuilder msg=new StringBuilder();
	for(MessageItem item:items){
		msg.append(item.toHtml());
	}
	String fullPath=path+"/urule-debug.html";
	StringBuilder sb=new StringBuilder();
	sb.append("<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><title>URule调试日志信息</title><body style='font-size:12px'>");
	sb.append(msg.toString());
	sb.append("</body></html>");
	FileOutputStream out=new FileOutputStream(new File(fullPath));
	IOUtils.write(sb.toString(), out);
	out.flush();
	out.close();
}
 
开发者ID:youseries,项目名称:urule,代码行数:20,代码来源:DefaultHtmlFileDebugWriter.java

示例8: testReadRangeUnknownLength

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testReadRangeUnknownLength() throws Exception {
    final B2Session session = new B2Session(
            new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
                    new Credentials(
                            System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")
                    )));
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());

    final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path test = new Path(bucket, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    new B2TouchFeature(session).touch(test, new TransferStatus());

    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    final byte[] content = RandomUtils.nextBytes(1000);
    final OutputStream out = local.getOutputStream(false);
    assertNotNull(out);
    IOUtils.write(content, out);
    out.close();
    new B2SingleUploadService(new B2WriteFeature(session)).upload(
            test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(),
            new TransferStatus().length(content.length),
            new DisabledConnectionCallback());
    final TransferStatus status = new TransferStatus();
    status.setLength(-1L);
    status.setAppend(true);
    status.setOffset(100L);
    final InputStream in = new B2ReadFeature(session).read(test, status, new DisabledConnectionCallback());
    assertNotNull(in);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - 100);
    new StreamCopier(status, status).transfer(in, buffer);
    final byte[] reference = new byte[content.length - 100];
    System.arraycopy(content, 100, reference, 0, content.length - 100);
    assertArrayEquals(reference, buffer.toByteArray());
    in.close();
    new B2DeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:40,代码来源:B2ReadFeatureTest.java

示例9: toJson

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Override
public void toJson(final OutputStream out, final T object) {
    try (StringWriter writer = new StringWriter()) {
        this.objectMapper.writer(this.prettyPrinter).writeValue(writer, object);
        final String hjsonString = JsonValue.readHjson(writer.toString()).toString(Stringify.HJSON);
        IOUtils.write(hjsonString, out);
    } catch (final Exception e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:11,代码来源:AbstractJacksonBackedJsonSerializer.java

示例10: testReadRange

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testReadRange() throws Exception {
    final Host host = new Host(new DAVProtocol(), "test.cyberduck.ch", new Credentials(
            System.getProperties().getProperty("webdav.user"), System.getProperties().getProperty("webdav.password")
    ));
    host.setDefaultPath("/dav/basic");
    final DAVSession session = new DAVSession(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path test = new Path(new DefaultHomeFinderService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    session.getFeature(Touch.class).touch(test, new TransferStatus());

    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    final byte[] content = new RandomStringGenerator.Builder().build().generate(1000).getBytes();
    final OutputStream out = local.getOutputStream(false);
    assertNotNull(out);
    IOUtils.write(content, out);
    out.close();
    new DAVUploadFeature(new DAVWriteFeature(session)).upload(
            test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(),
            new TransferStatus().length(content.length),
            new DisabledConnectionCallback());
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    status.setAppend(true);
    status.setOffset(100L);
    final InputStream in = new DAVReadFeature(session).read(test, status.length(content.length - 100), new DisabledConnectionCallback());
    assertNotNull(in);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - 100);
    new StreamCopier(status, status).transfer(in, buffer);
    final byte[] reference = new byte[content.length - 100];
    System.arraycopy(content, 100, reference, 0, content.length - 100);
    assertArrayEquals(reference, buffer.toByteArray());
    in.close();
    new DAVDeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:38,代码来源:DAVReadFeatureTest.java

示例11: testReadRange

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testReadRange() throws Exception {
    final Path drive = new OneDriveHomeFinderFeature(session).find();
    final Path test = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    new OneDriveTouchFeature(session).touch(test, new TransferStatus());

    final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
    final byte[] content = RandomUtils.nextBytes(1000);
    final OutputStream out = local.getOutputStream(false);
    assertNotNull(out);
    IOUtils.write(content, out);
    out.close();
    new DefaultUploadFeature<Void>(new OneDriveWriteFeature(session)).upload(
            test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(),
            new TransferStatus().length(content.length),
            new DisabledConnectionCallback());
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    status.setAppend(true);
    status.setOffset(100L);
    final OneDriveReadFeature read = new OneDriveReadFeature(session);
    assertTrue(read.offset(test));
    final InputStream in = read.read(test, status.length(content.length - 100), new DisabledConnectionCallback());
    assertNotNull(in);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - 100);
    new StreamCopier(status, status).transfer(in, buffer);
    final byte[] reference = new byte[content.length - 100];
    System.arraycopy(content, 100, reference, 0, content.length - 100);
    assertArrayEquals(reference, buffer.toByteArray());
    in.close();
    new OneDriveDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:33,代码来源:OneDriveReadFeatureTest.java

示例12: testInterruptStatus

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
@Test
public void testInterruptStatus() throws Exception {
    final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new IRODSProtocol())));
    final Profile profile = new ProfilePlistReader(factory).read(
            new Local("../profiles/iRODS (iPlant Collaborative).cyberduckprofile"));
    final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials(
            System.getProperties().getProperty("irods.key"), System.getProperties().getProperty("irods.secret")
    ));

    final IRODSSession session = new IRODSSession(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    final int length = 32770;
    final byte[] content = RandomUtils.nextBytes(length);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(content, out);
    out.close();
    final Path test = new Path(new IRODSHomeFinderService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final TransferStatus status = new TransferStatus().length(content.length);
    final Checksum checksum = new IRODSUploadFeature(session).upload(
            test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener() {
                @Override
                public void sent(final long bytes) {
                    super.sent(bytes);
                    status.setCanceled();
                }
            },
            status,
            new DisabledConnectionCallback());
    assertTrue(status.isCanceled());
    assertFalse(status.isComplete());
    session.close();
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:35,代码来源:IRODSUploadFeatureTest.java

示例13: put

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void put(String key, V value) {
  try (OutputStream os = fs.create(makePath(key))) {
    IOUtils.write(config.getSerializer().serialize(value), os);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:8,代码来源:FilePStore.java

示例14: extract

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void extract(File dir ) throws IOException {
    File listDir[] = dir.listFiles();
    if (listDir.length!=0){
        for (File i:listDir){
    /*  Warning! this will try and extract all files in the directory
        if other files exist, a for loop needs to go here to check that
        the file (i) is an archive file before proceeding */
            if (i.isDirectory()){
                break;
            }
            String fileName = i.toString();
            String tarFileName = fileName +".tar";
            FileInputStream instream= new FileInputStream(fileName);
            GZIPInputStream ginstream =new GZIPInputStream(instream);
            FileOutputStream outstream = new FileOutputStream(tarFileName);
            byte[] buf = new byte[1024];
            int len;
            while ((len = ginstream.read(buf)) > 0)
            {
                outstream.write(buf, 0, len);
            }
            ginstream.close();
            outstream.close();
            //There should now be tar files in the directory
            //extract specific files from tar
            TarArchiveInputStream myTarFile=new TarArchiveInputStream(new FileInputStream(tarFileName));
            TarArchiveEntry entry = null;
            int offset;
            FileOutputStream outputFile=null;
            //read every single entry in TAR file
            while ((entry = myTarFile.getNextTarEntry()) != null) {
                //the following two lines remove the .tar.gz extension for the folder name
                fileName = i.getName().substring(0, i.getName().lastIndexOf('.'));
                fileName = fileName.substring(0, fileName.lastIndexOf('.'));
                File outputDir =  new File(i.getParent() + "/" + fileName + "/" + entry.getName());
                if(! outputDir.getParentFile().exists()){
                    outputDir.getParentFile().mkdirs();
                }
                //if the entry in the tar is a directory, it needs to be created, only files can be extracted
                if(entry.isDirectory()){
                    outputDir.mkdirs();
                }else{
                    byte[] content = new byte[(int) entry.getSize()];
                    offset=0;
                    myTarFile.read(content, offset, content.length - offset);
                    outputFile=new FileOutputStream(outputDir);
                    IOUtils.write(content,outputFile);
                    outputFile.close();
                }
            }
            //close and delete the tar files, leaving the original .tar.gz and the extracted folders
            myTarFile.close();
            File tarFile =  new File(tarFileName);
            tarFile.delete();
        }
    }
}
 
开发者ID:SamaGames,项目名称:Hydroangeas,代码行数:58,代码来源:ResourceManager.java

示例15: sendEvent

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private void sendEvent(Socket socket, String content, String encoding) throws IOException {
  OutputStream output = socket.getOutputStream();
  IOUtils.write(content + IOUtils.LINE_SEPARATOR_UNIX, output, encoding);
  output.flush();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:6,代码来源:TestNetcatSource.java


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