List of usage examples for org.apache.commons.io IOUtils copyLarge
public static long copyLarge(Reader input, Writer output) throws IOException
Reader
to a Writer
. From source file:org.marketcetera.util.file.CopyCharsUnicodeUtils.java
/** * Copies a character stream from one given location (and * interpreted using the given strategy) to another, attempting to * retain signature/charset information. * * @param in The name of the character source, as interpreted by * {@link ReaderWrapper#ReaderWrapper(String,DecodingStrategy)}. * @param decodingStrategy The decoding strategy. It may be null * to use the default JVM charset./*from w ww . j a va 2 s . c o m*/ * @param out The name of the character sink, as interpreted by * {@link WriterWrapper#WriterWrapper(String,SignatureCharset)}. * * @return The number of characters copied. * * @throws I18NException Thrown if there is a data read/write * error. */ public static long copy(String in, DecodingStrategy decodingStrategy, String out) throws I18NException { CloseableRegistry registry = new CloseableRegistry(); try { ReaderWrapper inW = new ReaderWrapper(in, decodingStrategy); registry.register(inW); Reader reader = inW.getReader(); SignatureCharset sc = null; if (reader instanceof UnicodeInputStreamReader) { sc = ((UnicodeInputStreamReader) reader).getSignatureCharset(); } WriterWrapper outW = new WriterWrapper(out, sc); registry.register(outW); return IOUtils.copyLarge(inW.getReader(), outW.getWriter()); } catch (IOException ex) { throw ExceptUtils.wrap(ex, new I18NBoundMessage2P(Messages.CANNOT_COPY_FILES, in, out)); } finally { registry.close(); } }
From source file:org.marketcetera.util.file.CopyCharsUnicodeUtils.java
/** * Copies a character stream from the given source to the given * location, attempting to retain signature/charset information. * * @param in The character source, as interpreted by {@link * ReaderWrapper#ReaderWrapper(Reader,boolean)}. * @param skipClose True if the source reader should not be * closed./*from w w w . j av a 2 s .co m*/ * @param out The name of the character sink, as interpreted by * {@link WriterWrapper#WriterWrapper(String,SignatureCharset)}. * * @return The number of characters copied. * * @throws I18NException Thrown if there is a data read/write * error. */ public static long copy(Reader in, boolean skipClose, String out) throws I18NException { CloseableRegistry registry = new CloseableRegistry(); try { ReaderWrapper inW = new ReaderWrapper(in, skipClose); registry.register(inW); SignatureCharset sc = null; if (in instanceof UnicodeInputStreamReader) { sc = ((UnicodeInputStreamReader) in).getSignatureCharset(); } WriterWrapper outW = new WriterWrapper(out, sc); registry.register(outW); return IOUtils.copyLarge(inW.getReader(), outW.getWriter()); } catch (IOException ex) { throw ExceptUtils.wrap(ex, new I18NBoundMessage1P(Messages.CANNOT_COPY_READER, out)); } finally { registry.close(); } }
From source file:org.marketcetera.util.file.CopyCharsUnicodeUtils.java
/** * Copies a character stream from the given location (and * interpreted using the given strategy) to the given sink. * * @param in The name of the character source, as interpreted by {@link * ReaderWrapper#ReaderWrapper(String,DecodingStrategy)}. * @param decodingStrategy The decoding strategy. It may be null * to use the default JVM charset./*www .j a va2s .c o m*/ * @param out The character sink, as interpreted by {@link * WriterWrapper#WriterWrapper(Writer,boolean)}. * @param skipClose True if the sink writer should not be closed. * * @return The number of characters copied. * * @throws I18NException Thrown if there is a data read/write * error. */ public static long copy(String in, DecodingStrategy decodingStrategy, Writer out, boolean skipClose) throws I18NException { CloseableRegistry registry = new CloseableRegistry(); try { ReaderWrapper inW = new ReaderWrapper(in, decodingStrategy); registry.register(inW); WriterWrapper outW = new WriterWrapper(out, skipClose); registry.register(outW); return IOUtils.copyLarge(inW.getReader(), outW.getWriter()); } catch (IOException ex) { throw ExceptUtils.wrap(ex, new I18NBoundMessage1P(Messages.CANNOT_COPY_WRITER, in)); } finally { registry.close(); } }
From source file:org.marketcetera.util.file.CopyCharsUtils.java
/** * Copies a character stream from the given source to the given * sink.//from www .j a v a 2 s . com * * @param in The character source, as interpreted by {@link * ReaderWrapper#ReaderWrapper(Reader,boolean)}. * @param inSkipClose True if the source reader should not be * closed. * @param out The character sink, as interpreted by {@link * WriterWrapper#WriterWrapper(Writer,boolean)}. * @param outSkipClose True if the sink writer should not be * closed. * * @return The number of characters copied. * * @throws I18NException Thrown if there is a data read/write * error. */ public static long copy(Reader in, boolean inSkipClose, Writer out, boolean outSkipClose) throws I18NException { CloseableRegistry registry = new CloseableRegistry(); try { ReaderWrapper inW = new ReaderWrapper(in, inSkipClose); registry.register(inW); WriterWrapper outW = new WriterWrapper(out, outSkipClose); registry.register(outW); return IOUtils.copyLarge(inW.getReader(), outW.getWriter()); } catch (IOException ex) { throw ExceptUtils.wrap(ex, Messages.CANNOT_COPY_CSTREAMS); } finally { registry.close(); } }
From source file:org.marketcetera.util.file.CopyCharsUtils.java
/** * Copies a character stream from one given location to another. * * @param in The name of the character source, as interpreted by * {@link ReaderWrapper#ReaderWrapper(String)}. * @param out The name of the character sink, as interpreted by * {@link WriterWrapper#WriterWrapper(String)}. * * @return The number of characters copied. * * @throws I18NException Thrown if there is a data read/write * error./*from w ww .j a v a2 s . co m*/ */ public static long copy(String in, String out) throws I18NException { CloseableRegistry registry = new CloseableRegistry(); try { ReaderWrapper inW = new ReaderWrapper(in); registry.register(inW); WriterWrapper outW = new WriterWrapper(out); registry.register(outW); return IOUtils.copyLarge(inW.getReader(), outW.getWriter()); } catch (IOException ex) { throw ExceptUtils.wrap(ex, new I18NBoundMessage2P(Messages.CANNOT_COPY_FILES, in, out)); } finally { registry.close(); } }
From source file:org.marketcetera.util.file.CopyCharsUtils.java
/** * Copies a character stream from the given source to the given * location.// ww w . j av a 2s.c o m * * @param in The character source, as interpreted by {@link * ReaderWrapper#ReaderWrapper(Reader,boolean)}. * @param skipClose True if the source reader should not be * closed. * @param out The name of the character sink, as interpreted by * {@link WriterWrapper#WriterWrapper(String)}. * * @return The number of characters copied. * * @throws I18NException Thrown if there is a data read/write * error. */ public static long copy(Reader in, boolean skipClose, String out) throws I18NException { CloseableRegistry registry = new CloseableRegistry(); try { ReaderWrapper inW = new ReaderWrapper(in, skipClose); registry.register(inW); WriterWrapper outW = new WriterWrapper(out); registry.register(outW); return IOUtils.copyLarge(inW.getReader(), outW.getWriter()); } catch (IOException ex) { throw ExceptUtils.wrap(ex, new I18NBoundMessage1P(Messages.CANNOT_COPY_READER, out)); } finally { registry.close(); } }
From source file:org.marketcetera.util.file.CopyCharsUtils.java
/** * Copies a character stream from the given location to the given * sink./*www . ja v a2 s.c o m*/ * * @param in The name of the character source, as interpreted by {@link * ReaderWrapper#ReaderWrapper(String)}. * @param out The character sink, as interpreted by {@link * WriterWrapper#WriterWrapper(Writer,boolean)}. * @param skipClose True if the sink writer should not be closed. * * @return The number of characters copied. * * @throws I18NException Thrown if there is a data read/write * error. */ public static long copy(String in, Writer out, boolean skipClose) throws I18NException { CloseableRegistry registry = new CloseableRegistry(); try { ReaderWrapper inW = new ReaderWrapper(in); registry.register(inW); WriterWrapper outW = new WriterWrapper(out, skipClose); registry.register(outW); return IOUtils.copyLarge(inW.getReader(), outW.getWriter()); } catch (IOException ex) { throw ExceptUtils.wrap(ex, new I18NBoundMessage1P(Messages.CANNOT_COPY_WRITER, in)); } finally { registry.close(); } }
From source file:org.n52.web.ctrl.DataController.java
private void writeRawData(RequestSimpleParameterSet parameters, HttpServletResponse response) throws InternalServerException, ResourceNotFoundException, BadRequestException { if (!dataService.supportsRawData()) { throw new BadRequestException( "Querying of raw timeseries data is not supported by the underlying service!"); }/*w w w . j a v a 2s . com*/ final RawDataService rawDataService = dataService.getRawDataService(); try (final InputStream inputStream = rawDataService.getRawData(parameters)) { if (inputStream == null) { throw new ResourceNotFoundException("No raw data found."); } IOUtils.copyLarge(inputStream, response.getOutputStream()); } catch (IOException e) { throw new InternalServerException("Error while querying raw data", e); } }
From source file:org.n52.web.ctrl.ParameterController.java
@Override public void getRawData(HttpServletResponse response, String id, MultiValueMap<String, String> query) { if (!getParameterService().supportsRawData()) { throw new BadRequestException( "Querying of raw procedure data is not supported by the underlying service!"); }//from www .j av a 2 s .com IoParameters queryMap = createFromQuery(query); LOGGER.debug("getRawData() with id '{}' and query '{}'", id, queryMap); try (InputStream inputStream = getParameterService().getRawDataService().getRawData(id, queryMap)) { if (inputStream == null) { throw new ResourceNotFoundException("No raw data found for id '" + id + "'."); } IOUtils.copyLarge(inputStream, response.getOutputStream()); } catch (IOException e) { throw new InternalServerException("Error while querying raw data", e); } }
From source file:org.n52.web.ctrl.TimeseriesDataController.java
@RequestMapping(value = "/getData", method = POST, params = { RawFormats.RAW_FORMAT }) public void getRawTimeseriesCollectionData(HttpServletResponse response, @RequestBody RequestSimpleParameterSet parameters) throws Exception { checkIfUnknownTimeseries(parameters, parameters.getDatasets()); if (!timeseriesDataService.supportsRawData()) { throw new BadRequestException( "Querying of raw timeseries data is not supported by the underlying service!"); }// www. j a va2 s .c o m try (InputStream inputStream = timeseriesDataService.getRawDataService().getRawData(parameters)) { if (inputStream == null) { throw new ResourceNotFoundException("No raw data found."); } IOUtils.copyLarge(inputStream, response.getOutputStream()); } catch (IOException e) { throw new InternalServerException("Error while querying raw data", e); } }