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