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


Java IOUtils.copy方法代码示例

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


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

示例1: serveStaticContent

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
protected void serveStaticContent(HttpServletRequest request, HttpServletResponse response, String pathInfo) throws ServletException {
	InputStream is = super.getServletContext().getResourceAsStream(pathInfo);
	if (is == null) {
		throw new ServletException("Static resource " + pathInfo + " is not available");
	}
	try {
		int ind = pathInfo.lastIndexOf(".");
		if (ind != -1 && ind < pathInfo.length()) {
			String type = STATIC_CONTENT_TYPES.get(pathInfo.substring(ind + 1));
			if (type != null) {
				response.setContentType(type);
			}
		}

		ServletOutputStream os = response.getOutputStream();
		IOUtils.copy(is, os);
		os.flush();
	} catch (IOException ex) {
		throw new ServletException("Static resource " + pathInfo + " can not be written to the output stream");
	}
}
 
开发者ID:opensourceBIM,项目名称:BIMserver,代码行数:22,代码来源:GenericWebServiceServlet.java

示例2: getStringFromInputStream

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
private static String getStringFromInputStream(InputStream in) throws Exception {
    CachedOutputStream bos = new CachedOutputStream();
    IOUtils.copy(in, bos);
    in.close();
    bos.close();
    return bos.getOut().toString();
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:8,代码来源:Client.java

示例3: handleMessage

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
public void handleMessage(Message message) throws Fault {
    // check the fault from the message
    Throwable ex = message.getContent(Throwable.class);
    if (ex != null) {
        if (ex instanceof Fault) {
            throw (Fault)ex;
        } else {
            throw new Fault(ex);
        }
    }

    List<?> params = message.getContent(List.class);
    if (null != params) {
        InputStream is = (InputStream)params.get(0);
        OutputStream os = message.getContent(OutputStream.class);
        if (os == null) {
            //InOny
            return;
        }

        try {
            if (is instanceof StreamCache) {
                ((StreamCache)is).writeTo(os);
            } else {
                IOUtils.copy(is, os);
            }
        } catch (Exception e) {
            throw new Fault(e);
        } finally {
            IOHelper.close(is, "input stream", null);
            // Should not close the output stream as the interceptor chain will close it
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:35,代码来源:RawMessageContentRedirectInterceptor.java

示例4: getStringFromInputStream

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
public static String getStringFromInputStream(InputStream in) throws Exception {
    CachedOutputStream bos = new CachedOutputStream();
    IOUtils.copy(in, bos);
    in.close();
    bos.close();
    return bos.getOut().toString();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:CxfUtils.java

示例5: unpackClasspathSource

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
/**
 * Extracts sources from the test jar class path to a temporary location for upload
 *
 * @param classpathLocation
 *            The location relative to the class path root of the file to upload
 * @param extension
 *            The extension of the file being uploaded (used with temporary file)
 * @return File representation of the file extracted from the jar
 */
private static File unpackClasspathSource(String classpathLocation, String extension) {
    final InputStream stream = TestSources.class.getClassLoader().getResourceAsStream(classpathLocation);

    OutputStream outputStream = null;

    try {
        File outputFile = File.createTempFile("temp", extension);

        try {
            if (!outputFile.exists() && !outputFile.createNewFile()) {
                throw new IOException("Cannot create temporary file " + outputFile.getName());
            }

            outputStream = new FileOutputStream(outputFile);
            IOUtils.copy(stream, outputStream);

            return outputFile;
        } finally {
            try {
                if (stream != null) {
                    stream.close();
                }
            } finally {
                if (outputStream != null) {
                    outputStream.close();
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Error copying test source file", e);
    }
}
 
开发者ID:blackducksoftware,项目名称:sdk-client-tools-protex,代码行数:42,代码来源:TestSources.java

示例6: createMessageObserver

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private MessageObserver createMessageObserver(final Conduit c)
{
   return new MessageObserver() 
   {
       public void onMessage(Message inMessage) 
       {
          LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream();
          try 
          {
             IOUtils.copy(inMessage.getContent(InputStream.class), bout);
             inMessage.getExchange().put(InputStream.class, bout.createInputStream());
                   
             Map<String, List<String>> inHeaders = 
                (Map<String, List<String>>)inMessage.get(Message.PROTOCOL_HEADERS);
                   
             inMessage.getExchange().put(Message.PROTOCOL_HEADERS, inHeaders);
             c.close(inMessage);
          } 
          catch (IOException e) 
          {
             //ignore
             Logger.getLogger(SOAPConnectionImpl.class).trace(e);
          }
       }
   };
}
 
开发者ID:jbossws,项目名称:jbossws-cxf,代码行数:28,代码来源:SOAPConnectionImpl.java

示例7: writeTo

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
	if(writeClassNames){
		httpHeaders.putSingle("Content-Type", "application/fast-json");	
	}
	ObjectJSON json=cache.get();
	if(json.obj==t){
		IOUtils.copy(new ByteArrayInputStream(json.json), entityStream);
		json.obj=null;
		json.json=null;
	}else{
		JSON.writeJSONStringTo(t, new OutputStreamWriter(entityStream, encoding),feature);
	}
}
 
开发者ID:GeeQuery,项目名称:cxf-plus,代码行数:14,代码来源:FastJSONProvider.java

示例8: handleMessage

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
public void handleMessage(Message message) {
	InputStream is = message.getContent(InputStream.class);
	if (is != null) {
		CachedOutputStream bos = new CachedOutputStream();
		try {
			Scanner scanner = new Scanner(is, "UTF-8");
			if (scanner != null && scanner.hasNext()) {
				String inputStreamString = scanner.useDelimiter("\\A").next();
				inputStreamString = inputStreamString
						.replaceAll("<record>",
								"<record xmlns=\"http://www.loc.gov/MARC21/slim\">");
				inputStreamString = inputStreamString
						.replaceAll("<collection>",
								"<collection xmlns=\"http://www.loc.gov/MARC21/slim\">");

				is = new ByteArrayInputStream(
						inputStreamString.getBytes("UTF-8"));
				scanner.close();
			} else {
				IOUtils.copy(is, bos);
				bos.flush();
				is = bos.getInputStream();
			}
			message.setContent(InputStream.class, is);
			is.close();
			bos.close();

		} catch (Exception e) {
			throw new Fault(e);
		}
	}
}
 
开发者ID:petkivim,项目名称:finto-subject-headings,代码行数:33,代码来源:RecordInterceptor.java

示例9: sendRequest

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
public void sendRequest() throws Exception {
       URLConnection connection = new URL("http://localhost:8181/cxf/HelloWorld")
               .openConnection();
       connection.setDoInput(true);
       connection.setDoOutput(true);
       OutputStream os = connection.getOutputStream();
       // Post the request file.
       InputStream fis = getClass().getClassLoader().getResourceAsStream("org/apache/servicemix/samples/cxf_osgi/request.xml");
       IOUtils.copy(fis, os);
       // Read the response.
       InputStream is = connection.getInputStream();
System.out.println("the response is ====> ");
System.out.println(IOUtils.toString(is));        

   }
 
开发者ID:apache,项目名称:servicemix,代码行数:16,代码来源:Client.java

示例10: format

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
protected String format(final String json) throws IOException {
    final StringIndenter formatter = new StringIndenter(json);
    final Writer outWriter = new StringWriter();
    IOUtils.copy(new StringReader(formatter.result()), outWriter, 2048);
    outWriter.close();
    return outWriter.toString();
}
 
开发者ID:apache,项目名称:tomee,代码行数:8,代码来源:AbstractCommand.java

示例11: serveStaticContent

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
public boolean serveStaticContent(final HttpServletRequest request,
                                  final HttpServletResponse response,
                                  final String pathInfo) throws ServletException {
    final InputStream is = findStaticContent(request, DEFAULT_WELCOME_FILES);
    if (is == null) {
        return false;
    }
    try {
        final int ind = pathInfo.lastIndexOf(".");
        if (ind != -1 && ind < pathInfo.length()) {
            final String type = STATIC_CONTENT_TYPES.get(pathInfo.substring(ind + 1));
            if (type != null) {
                response.setContentType(type);
            }
        }

        final ServletOutputStream os = response.getOutputStream();
        IOUtils.copy(is, os);
        os.flush();
        response.setStatus(HttpURLConnection.HTTP_OK);
    } catch (final IOException ex) {
        throw new ServletException("Static resource " + pathInfo + " can not be written to the output stream");
    } finally {
        try {
            is.close();
        } catch (final IOException e) {
            // no-op
        }
    }
    return true;
}
 
开发者ID:apache,项目名称:tomee,代码行数:32,代码来源:CxfRsHttpListener.java

示例12: getBytes

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
@Override
protected byte[] getBytes(Object object) {
    DataSource dataSource = (DataSource) object;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        InputStream stream = dataSource.getInputStream();
        IOUtils.copy(stream, baos);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return baos.toByteArray();
}
 
开发者ID:claudemamo,项目名称:jruby-cxf,代码行数:13,代码来源:DataSourceType.java

示例13: getBytes

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
@Override
protected byte[] getBytes(Object object) {
    DataHandler handler = (DataHandler) object;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        InputStream stream = handler.getInputStream();
        IOUtils.copy(stream, baos);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return baos.toByteArray();
}
 
开发者ID:claudemamo,项目名称:jruby-cxf,代码行数:13,代码来源:DataHandlerType.java

示例14: logging

import org.apache.cxf.helpers.IOUtils; //导入方法依赖的package包/类
private void logging(Message message) throws Fault {
    String id = (String) message.getExchange().get(LoggingMessageSecure.ID_KEY);
    if (id == null) {
        id = LoggingMessageSecure.nextId();
        message.getExchange().put(LoggingMessageSecure.ID_KEY, id);
    }
    final LoggingMessageSecure buffer = createNewLoggingMessage(id);

    String encoding = (String) message.get(Message.ENCODING);

    if (encoding != null) {
        buffer.getEncoding().append(encoding);
    }
    String ct = (String) message.get(Message.CONTENT_TYPE);
    if (ct != null) {
        buffer.getContentType().append(ct);
    }
    Object headers = message.get(Message.PROTOCOL_HEADERS);

    if (headers != null) {
        buffer.getHeader().append(headers);
    }
    String uri = (String) message.get(Message.ENDPOINT_ADDRESS);
    if (uri != null) {
        buffer.getAddress().append(uri);
    }

    InputStream is = message.getContent(InputStream.class);
    if (is != null) {
        CachedOutputStream bos = new CachedOutputStream();
        try {
            IOUtils.copy(is, bos);

            bos.flush();
            is.close();

            message.setContent(InputStream.class, bos.getInputStream());
            if (bos.getTempFile() != null) {
                // large thing on disk...
                buffer.getMessage().append("\nMessage (saved to tmp file):\n");
                buffer.getMessage().append("Filename: " + bos.getTempFile().getAbsolutePath() + "\n");
            }
            if (bos.size() > limit) {
                buffer.getMessage().append("(message truncated to " + limit + " bytes)\n");
            }
            bos.writeCacheTo(buffer.getPayload(), limit);

            bos.close();
        } catch (IOException e) {
            throw new Fault(e);
        }
    }

    if (writer != null) {
        writer.println(buffer.toString());
    } else if (getLogger().isLoggable(Level.INFO)) {
        getLogger().info(buffer.toString());
    }
}
 
开发者ID:blackducksoftware,项目名称:blackduck-cxf-utilities,代码行数:60,代码来源:AbstractPayloadFilteredLoggingInInterceptor.java


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