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


Java IO.copy方法代码示例

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


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

示例1: writeTo

import org.eclipse.jetty.util.IO; //导入方法依赖的package包/类
/** 
 * @param out 
 * @param start First byte to write
 * @param count Bytes to write or -1 for all of them.
 */
public void writeTo(OutputStream out,long start,long count)
    throws IOException
{
    InputStream in = getInputStream();
    try
    {
        in.skip(start);
        if (count<0)
            IO.copy(in,out);
        else
            IO.copy(in,out,count);
    }
    finally
    {
        in.close();
    }
}
 
开发者ID:itead,项目名称:IoTgo_Android_App,代码行数:23,代码来源:Resource.java

示例2: copyTo

import org.eclipse.jetty.util.IO; //导入方法依赖的package包/类
@Override
public void copyTo(File destination)
    throws IOException
{
    if (isDirectory())
    {
        IO.copyDir(getFile(),destination);
    }
    else
    {
        if (destination.exists())
            throw new IllegalArgumentException(destination+" exists");
        IO.copy(getFile(),destination);
    }
}
 
开发者ID:itead,项目名称:IoTgo_Android_App,代码行数:16,代码来源:FileResource.java

示例3: ClassPathResource

import org.eclipse.jetty.util.IO; //导入方法依赖的package包/类
/**
 * Specifies the classpath path containing the resource
 */
public ClassPathResource(String path) {
	this.path = path;
	InputStream is = LauncherUtils.getSeleniumResourceAsStream(path);
	if (is != null) {
		os = new ByteArrayOutputStream();
		try {
			IO.copy(is, os);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:epam,项目名称:Wilma,代码行数:16,代码来源:ClassPathResource.java

示例4: inputStreamToBytes

import org.eclipse.jetty.util.IO; //导入方法依赖的package包/类
public static byte[] inputStreamToBytes(InputStream input, long byteCount) throws IOException  {
	if (input == null) {
		throw new NullPointerException("parameter input is null.");
	}
	
	BufferedInputStream in = new BufferedInputStream(input);
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	if (byteCount == -1) {
		IO.copy(in, out);
	} else {
		IO.copy(in, out, byteCount);
	}
	return out.toByteArray();
}
 
开发者ID:chipster,项目名称:chipster,代码行数:15,代码来源:Files.java

示例5: mergeWebXml

import org.eclipse.jetty.util.IO; //导入方法依赖的package包/类
/**
 * Take the web fragment and put it inside a copy of the web.xml.
 * 
 * You can specify the insertion point by specifying the string in the
 * insertionMarker configuration entry.
 * 
 * If you dont specify the insertionMarker, then the fragment will be
 * inserted at the end of the file just before the &lt;/webapp&gt;
 * 
 * @throws Exception
 * @param webXmlText
 */
public void mergeWebXml(String webXmlText) throws Exception
{
    if (mergeFragment)
    {
        File fragmentWebXml = new File(webXmlFragment);
        if (!fragmentWebXml.exists())
        {
            getLog().info("No fragment web.xml file generated");
        }
        File mergedWebXml = new File(fragmentWebXml.getParentFile(), "web.xml");
        BufferedReader webXmlReader = new BufferedReader(new StringReader(webXmlText));
        PrintWriter mergedWebXmlWriter = new PrintWriter(new FileWriter(mergedWebXml));

        // read up to the insertion marker or the </webapp> if there is no
        // marker
        boolean atInsertPoint = false;
        boolean atEOF = false;
        String marker = (insertionMarker == null
                || insertionMarker.equals("") ? END_OF_WEBAPP : insertionMarker);
        while (!atInsertPoint && !atEOF)
        {
            String line = webXmlReader.readLine();
            if (line == null)
                atEOF = true;
            else if (line.indexOf(marker) >= 0)
            {
                atInsertPoint = true;
            }
            else
            {
                mergedWebXmlWriter.println(line);
            }
        }

        // put in the generated fragment
        BufferedReader fragmentWebXmlReader = new BufferedReader(
                new FileReader(fragmentWebXml));
        IO.copy(fragmentWebXmlReader, mergedWebXmlWriter);

        // if we inserted just before the </web-app>, put it back in
        if (marker.equals(END_OF_WEBAPP))
            mergedWebXmlWriter.println(END_OF_WEBAPP);

        // copy in the rest of the original web.xml file
        IO.copy(webXmlReader, mergedWebXmlWriter);

        webXmlReader.close();
        mergedWebXmlWriter.close();
        fragmentWebXmlReader.close();
    }
}
 
开发者ID:Devexperts,项目名称:QD,代码行数:64,代码来源:JspcMojo.java

示例6: checkKeyStore

import org.eclipse.jetty.util.IO; //导入方法依赖的package包/类
/**
 * Check KeyStore Configuration. Ensures that if keystore has been
 * configured but there's no truststore, that keystore is
 * used as truststore.
 * @throws IllegalStateException if SslContextFactory configuration can't be used.
 */
public void checkKeyStore()
{
    if (_context != null)
        return; //nothing to check if using preconfigured context


    if (_keyStore == null && _keyStoreInputStream == null && _keyStorePath == null)
        throw new IllegalStateException("SSL doesn't have a valid keystore");

    // if the keystore has been configured but there is no
    // truststore configured, use the keystore as the truststore
    if (_trustStore == null && _trustStoreInputStream == null && _trustStorePath == null)
    {
        _trustStore = _keyStore;
        _trustStorePath = _keyStorePath;
        _trustStoreInputStream = _keyStoreInputStream;
        _trustStoreType = _keyStoreType;
        _trustStoreProvider = _keyStoreProvider;
        _trustStorePassword = _keyStorePassword;
        _trustManagerFactoryAlgorithm = _keyManagerFactoryAlgorithm;
    }

    // It's the same stream we cannot read it twice, so read it once in memory
    if (_keyStoreInputStream != null && _keyStoreInputStream == _trustStoreInputStream)
    {
        try
        {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            IO.copy(_keyStoreInputStream, baos);
            _keyStoreInputStream.close();

            _keyStoreInputStream = new ByteArrayInputStream(baos.toByteArray());
            _trustStoreInputStream = new ByteArrayInputStream(baos.toByteArray());
        }
        catch (Exception ex)
        {
            throw new IllegalStateException(ex);
        }
    }
}
 
开发者ID:AdrianBZG,项目名称:PhoneChat,代码行数:47,代码来源:SslContextFactory.java

示例7: read

import org.eclipse.jetty.util.IO; //导入方法依赖的package包/类
/**
 * Method for getting a range from the file.
 * 
 * @param filePosition
 * @param length
 * @return array of bytes
 * @throws IOException
 */
public byte[] read(long filePosition, long length) throws IOException {

	if (fileChannel != null) {
		InputStream in = Channels.newInputStream(fileChannel.position(filePosition));
		try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
			
			IO.copy(in, out, length);

			return out.toByteArray();
		}

	} else {

		long endFilePosition = filePosition + length - 1;

		//Make sure that we won't make requests outside the file end   	        	        	
		if (endFilePosition > length()) {
			endFilePosition = length();
		}

		HttpURLConnection connection = null;
		try {

			connection = (HttpURLConnection)url.openConnection();
			KeyAndTrustManager.configureForChipsterCertificate(connection);
			connection.setRequestProperty("Range", "bytes=" + filePosition + "-" + endFilePosition);
			
			try (InputStream in = connection.getInputStream();				
			ByteArrayOutputStream out = new ByteArrayOutputStream()) {
				
				IOUtils.copy(in, out);
				return out.toByteArray();
			}
			
		} catch (IOException e) {
			if(e.getMessage().contains("HTTP") && e.getMessage().contains(" 416 ")) {
				//Requested Range Not Satisfiable
				//This happens often when data files have bigger coordinates than annotations, just ignore
			} else {
				throw e;
			}
		} finally {
			IOUtils.disconnectIfPossible(connection);
		}
	}
	return null;   
}
 
开发者ID:chipster,项目名称:chipster,代码行数:56,代码来源:ByteDataSource.java


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