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


Java ByteStreams.copy方法代码示例

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


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

示例1: write

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override
public void write(OutputStream output, ByteArraySessionOutputBuffer buffer) throws IOException {

	buffer.reset();
	final InputStream payload = writePayload(buffer);
	final long contentLength = buffer.contentLength();

	this.warcHeaders.updateHeader(new WarcHeader(WarcHeader.Name.CONTENT_LENGTH, Long.toString(contentLength)));

	Util.toOutputStream(BasicLineFormatter.formatProtocolVersion(WarcRecord.PROTOCOL_VERSION, null), output);
	output.write(ByteArraySessionOutputBuffer.CRLF);
	writeHeaders(this.warcHeaders, output);
	output.write(ByteArraySessionOutputBuffer.CRLF);
	ByteStreams.copy(payload, output);
	output.write(ByteArraySessionOutputBuffer.CRLFCRLF);
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:17,代码来源:AbstractWarcRecord.java

示例2: badge

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@EventHandlerMethod(preventXsrf = false)
public void badge(SectionInfo info, long instId) throws Exception
{
	HttpServletResponse response = info.getResponse();
	response.setContentType("image/jpeg");
	try( InputStream in = getBadgeStream(instId); ServletOutputStream out = response.getOutputStream() )
	{
		if( in != null )
		{
			ByteStreams.copy(in, out);
		}
	}
	finally
	{
		info.setRendered();
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:18,代码来源:InstitutionSection.java

示例3: exporter

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
private FileWorker exporter(final Control control)
{
	return new AbstractFileWorker<Object>(CurrentLocale.get("com.tle.admin.controls.exported"), //$NON-NLS-1$
		CurrentLocale.get("com.tle.admin.controls.error.exporting")) //$NON-NLS-1$
	{
		@Override
		public Object construct() throws Exception
		{
			final Driver driver = Driver.instance();
			final PluginService pluginService = driver.getPluginService();

			final ExportedControl ctl = getExportedControl(control, pluginService, driver.getVersion().getFull());

			byte[] zipData = getCollectionService(driver).exportControl(new XStream().toXML(ctl));

			ByteArrayInputStream stream = new ByteArrayInputStream(zipData);
			try( OutputStream out = new FileOutputStream(file) )
			{
				ByteStreams.copy(stream, out);
			}
			return null;
		}
	};
}
 
开发者ID:equella,项目名称:Equella,代码行数:25,代码来源:WizardTree.java

示例4: getBody

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override
public String getBody()
{
	if( body == null )
	{
		final ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
		try (InputStream in = getInputStream())
		{
			ByteStreams.copy(in, out);
			// TODO: check headers to see if indeed UTF8...
			body = new String(out.toByteArray(), Constants.UTF8);
			if( LOGGER.isTraceEnabled() )
			{
				LOGGER.trace("Received\n" + body);
			}
		}
		catch( IOException u )
		{
			throw Throwables.propagate(u);
		}
	}
	return body;
}
 
开发者ID:equella,项目名称:Equella,代码行数:24,代码来源:HttpServiceImpl.java

示例5: extractContents

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
private Map<String, byte[]> extractContents(InputStream inputStream)
    throws IOException {
  Map<String, byte[]> contents = new HashMap<String, byte[]>();

  // assumption: the zip is non-empty
  ZipInputStream zip = new ZipInputStream(inputStream);
  ZipEntry entry;
  while ((entry = zip.getNextEntry()) != null) {
    if (entry.isDirectory())  continue;
    ByteArrayOutputStream contentStream = new ByteArrayOutputStream();
    ByteStreams.copy(zip, contentStream);
    contents.put(entry.getName(), contentStream.toByteArray());
  }
  zip.close();

  return contents;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:18,代码来源:ComponentServiceImpl.java

示例6: onImport

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override
protected final void onImport()
{
	final int confirm = JOptionPane.showConfirmDialog(
		parentFrame,
		CurrentLocale.get("com.tle.admin.gui.baseentitytool.warningimport", getEntityNameLower(),
			CurrentLocale.get("com.tle.application.name")),
		CurrentLocale.get("com.tle.admin.gui.baseentitytool.import", getEntityNameNormal()),
		JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

	if( confirm == JOptionPane.YES_OPTION )
	{
		FileFilter filter = new ZipFileFilter();
		final DialogResult result = DialogUtils.openDialog(parentFrame, null, filter, null);
		if( result.isOkayed() )
		{
			try( InputStream in = new FileInputStream(result.getFile()) )
			{
				ByteArrayOutputStream out = new ByteArrayOutputStream();
				ByteStreams.copy(in, out);

				doImport(service.importEntity(out.toByteArray()));
			}
			catch( Exception ex )
			{
				Driver.displayInformation(parentFrame,
					CurrentLocale.get("com.tle.admin.gui.baseentitytool.notvalid"));
				LOGGER.error("Couldn't load selected file", ex);
			}
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:33,代码来源:BaseEntityTool.java

示例7: addFile

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override
public void addFile ( final ContentProvider content, final String targetFile, final FileInformation fileInformation ) throws IOException
{
    try ( InputStream resource = content.createInputStream () )
    {
        final File tmp = Files.createTempFile ( "data", "" ).toFile ();
        final File old = this.tempFiles.put ( targetFile, tmp );
        if ( old != null )
        {
            old.delete ();
        }
        try ( BufferedOutputStream os = new BufferedOutputStream ( new FileOutputStream ( tmp ) ) )
        {
            ByteStreams.copy ( resource, os );
        }
    }

    if ( fileInformation != null )
    {
        boolean conf = false;

        for ( final FileOptions option : fileInformation.getOptions () )
        {
            switch ( option )
            {
                case CONFIGURATION:
                    conf = true;
                    break;
            }
        }

        final EntryInformation ei = new EntryInformation ( fileInformation.getOwner (), fileInformation.getGroup (), fileInformation.getMode (), conf );

        this.tempFilesOptions.put ( targetFile, ei );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:37,代码来源:DebianDeploymentContext.java

示例8: encrypt

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
public byte[] encrypt(final byte[] src, final KeyIv keyIv) {
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try (final OutputStream out = getCryptOut(bos, keyIv)) {
        ByteStreams.copy(new ByteArrayInputStream(src), out);
    } catch (final IOException e) {
        throw new UncheckedIOException(e);
    }

    return bos.toByteArray();
}
 
开发者ID:osiegmar,项目名称:setra,代码行数:11,代码来源:Cryptor.java

示例9: file

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
/**
 * Download attached file.
 */
@GetMapping("/file/{id:[a-f0-9]{64}}/{key:[a-f0-9]{64}}")
public ResponseEntity<StreamingResponseBody> file(@PathVariable("id") final String id,
                                                  @PathVariable("key") final String keyHex,
                                                  final HttpSession session) {

    final KeyIv keyIv =
        new KeyIv(BaseEncoding.base16().lowerCase().decode(keyHex), resolveFileIv(id, session));

    final DecryptedFile decryptedFile = messageService.resolveStoredFile(id, keyIv);

    final HttpHeaders headers = new HttpHeaders();

    // Set application/octet-stream instead of the original mime type to force download
    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);

    if (decryptedFile.getName() != null) {
        headers.setContentDispositionFormData("attachment", decryptedFile.getName(),
            StandardCharsets.UTF_8);
    }
    headers.setContentLength(decryptedFile.getOriginalFileSize());

    final StreamingResponseBody body = out -> {
        try (final InputStream in = messageService.getStoredFileInputStream(id, keyIv)) {
            ByteStreams.copy(in, out);
            out.flush();
        }

        messageService.burnFile(id);
    };

    return new ResponseEntity<>(body, headers, HttpStatus.OK);
}
 
开发者ID:osiegmar,项目名称:setra,代码行数:36,代码来源:ReceiveController.java

示例10: jarTestClasses

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
/**
 * Create a temporary JAR file containing the specified test classes.
 */
protected Path jarTestClasses(Class... classes) throws IOException {
  Path jar = File.createTempFile("junit", ".jar", temp.getRoot()).toPath();
  try (JarOutputStream out = new JarOutputStream(new FileOutputStream(jar.toFile()))) {
    for (Class clazz : classes) {
      try (FileInputStream in =
          new FileInputStream(ToolHelper.getClassFileForTestClass(clazz).toFile())) {
        out.putNextEntry(new ZipEntry(clazz.getCanonicalName().replace('.', '/') + ".class"));
        ByteStreams.copy(in, out);
        out.closeEntry();
      }
    }
  }
  return jar;
}
 
开发者ID:inferjay,项目名称:r8,代码行数:18,代码来源:TestBase.java

示例11: fromPipe

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
/**
 * Creates a new {@link BlobDescriptor} from the contents of an {@link InputStream} while piping
 * to an {@link OutputStream}. Does not close either streams.
 */
static BlobDescriptor fromPipe(InputStream inputStream, OutputStream outputStream)
    throws IOException {
  CountingDigestOutputStream countingDigestOutputStream =
      new CountingDigestOutputStream(outputStream);
  ByteStreams.copy(inputStream, countingDigestOutputStream);
  countingDigestOutputStream.flush();
  return countingDigestOutputStream.toBlobDescriptor();
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:13,代码来源:BlobDescriptor.java

示例12: doWrite

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
private void doWrite(final long uuid, final File file)
{
	final boolean exportSecurity = JOptionPane.showConfirmDialog(parentFrame,
		CurrentLocale.get("com.tle.admin.gui.baseentitytool.exportrules"),
		CurrentLocale.get("com.tle.admin.gui.baseentitytool.export"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;

	final GlassSwingWorker<?> worker = new GlassSwingWorker<Object>()
	{
		@Override
		public Object construct() throws IOException
		{
			try( OutputStream out = new FileOutputStream(file) )
			{
				byte[] xml = service.exportEntity(uuid, exportSecurity);
				ByteArrayInputStream stream = new ByteArrayInputStream(xml);
				ByteStreams.copy(stream, out);
			}
			return null;
		}

		@Override
		public void finished()
		{
			Driver.displayInformation(parentFrame,
				CurrentLocale.get("com.tle.admin.gui.baseentitytool.exported", getEntityNameNormal()));
		}

		@Override
		public void exception()
		{
			Driver.displayError(parentFrame, getExportingErrorMessage(), getException());
			LOGGER.error("Error exporting " + getEntityNameLower(), getException());
		}
	};

	worker.setComponent(parentFrame);
	worker.start();
}
 
开发者ID:equella,项目名称:Equella,代码行数:39,代码来源:BaseEntityTool.java

示例13: add

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
public static void add(ZipOutputStream zipFile, String directory, File inputFile) throws IOException
{
	try( BufferedInputStream in = new BufferedInputStream(new FileInputStream(inputFile)) )
	{
		zipFile.putNextEntry(new ZipEntry(directory + inputFile.getName()));
		ByteStreams.copy(in, zipFile);
		zipFile.closeEntry();
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:10,代码来源:ZipUtils.java

示例14: addResourceToRepositoryConnection

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
private void addResourceToRepositoryConnection(RepositoryConnection repositoryConnection,
    Optional<Resource> optionalPrefixesResource, Resource resource,
    List<InputStream> streamList) {
  final String extension = FilenameUtils.getExtension(resource.getFilename());
  try {
    final InputStream inputStreamWithEnv;
    if (optionalPrefixesResource.isPresent()
        && !resource.getFilename().equals("_prefixes.trig")) {
      try (SequenceInputStream resourceSequenceInputStream = new SequenceInputStream(
          optionalPrefixesResource.get().getInputStream(), resource.getInputStream())) {
        inputStreamWithEnv = new EnvironmentAwareResource(resourceSequenceInputStream,
            environment).getInputStream();
      }
    } else {
      inputStreamWithEnv =
          new EnvironmentAwareResource(resource.getInputStream(), environment).getInputStream();
    }
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ByteStreams.copy(inputStreamWithEnv, outputStream);
    repositoryConnection.add(new ByteArrayInputStream(outputStream.toByteArray()), "#",
        FileFormats.getFormat(extension));
    streamList.add(new ByteArrayInputStream(outputStream.toByteArray()));
  } catch (IOException ex) {
    LOG.error("Configuration file %s could not be read.", resource.getFilename());
    throw new ConfigurationException(
        String.format("Configuration file <%s> could not be read.", resource.getFilename()));
  }
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:29,代码来源:FileConfigurationBackend.java

示例15: addArFile

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
private void addArFile ( final File file, final String entryName ) throws IOException
{
    final ArArchiveEntry entry = new ArArchiveEntry ( entryName, file.length (), 0, 0, AR_ARCHIVE_DEFAULT_MODE, timestampProvider.getModTime () / 1000 );
    this.ar.putArchiveEntry ( entry );

    ByteStreams.copy ( new FileInputStream ( file ), this.ar );

    this.ar.closeArchiveEntry ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:10,代码来源:DebianPackageWriter.java


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