Java 类org.apache.commons.io.output.CloseShieldOutputStream 实例源码

项目:dkpro-argumentation    文件:ArgumentDumpWriter.java   
@Override
public void initialize(UimaContext context)
        throws ResourceInitializationException
{
    super.initialize(context);

    try {
        if (out == null) {
            if ("-".equals(outputFile.getName())) {
                // default to System.out
                out = new PrintWriter(new CloseShieldOutputStream(System.out));
            }
            else {
                if (outputFile.getParentFile() != null) {
                    outputFile.getParentFile().mkdirs();
                }
                out = new PrintWriter(
                        new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
            }
        }
    }
    catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
}
项目:dkpro-argumentation-minimal    文件:ArgumentDumpWriter.java   
@Override
public void initialize(UimaContext context)
        throws ResourceInitializationException
{
    super.initialize(context);

    try {
        if (out == null) {
            if ("-".equals(outputFile.getName())) {
                // default to System.out
                out = new PrintWriter(new CloseShieldOutputStream(System.out));
            }
            else {
                if (outputFile.getParentFile() != null) {
                    outputFile.getParentFile().mkdirs();
                }
                out = new PrintWriter(
                        new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
            }
        }
    }
    catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
}
项目:caarray    文件:GeoSoftExporterBean.java   
/**
 * {@inheritDoc}
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public void export(Project project, String permaLinkUrl, PackagingInfo.PackagingMethod method, OutputStream out)
        throws IOException {

    final OutputStream closeShield = new CloseShieldOutputStream(out);
    final Experiment experiment = project.getExperiment();
    boolean addReadMe = false;
    if (method == PackagingInfo.PackagingMethod.TGZ) {
        addReadMe = true;
    } else {
        ensureZippable(project);
    }

    final ArchiveOutputStream arOut = method.createArchiveOutputStream(closeShield);
    try {
        exportArchive(experiment, permaLinkUrl, addReadMe, arOut);
    } finally {
        // note that the caller's stream is shielded from the close(),
        // but this is the only way to finish and flush the (gzip) stream.
        IOUtils.closeQuietly(arOut);
    }
}
项目:aliyun-maxcompute-data-collectors    文件:LobFile.java   
@Override
/**
 * {@inheritDoc}
 */
public OutputStream writeBlobRecord(long claimedLen) throws IOException {
  finishRecord(); // finish any previous record.
  checkForNull(this.out);
  startRecordIndex();
  this.header.getStartMark().write(out);
  LOG.debug("Starting new record; id=" + curEntryId
      + "; claimedLen=" + claimedLen);
  WritableUtils.writeVLong(out, curEntryId);
  WritableUtils.writeVLong(out, claimedLen);
  this.curClaimedLen = claimedLen;
  this.userCountingOutputStream = new CountingOutputStream(
      new CloseShieldOutputStream(out));
  if (null == this.codec) {
    // No codec; pass thru the same OutputStream to the user.
    this.userOutputStream = this.userCountingOutputStream;
  } else {
    // Wrap our CountingOutputStream in a compressing OutputStream to
    // give to the user.
    this.compressor.reset();
    this.userOutputStream = new CompressorStream(
        this.userCountingOutputStream, compressor);
  }

  return this.userOutputStream;
}
项目:oma-riista-web    文件:HuntingClubAreaExportFeature.java   
@Transactional(readOnly = true)
public byte[] exportCombinedGeoJsonAsArchive(final long clubAreaId, final Locale locale) {
    final HuntingClubArea clubArea = requireEntityService.requireHuntingClubArea(clubAreaId, EntityPermission.READ);

    final FeatureCollection featureCollection =
            toFeatureCollectionWithMetadata(clubArea, clubArea.getClub(), clubArea.getHuntingYear());

    try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
         final ZipOutputStream zip = new ZipOutputStream(bos, StandardCharsets.UTF_8)) {
        zip.setComment("Exported from oma.riista.fi on " + DTF.print(DateUtil.now()));
        zip.setLevel(9);

        // GeoJSON
        zip.putNextEntry(new ZipEntry(FILENAME_GEOJSON));
        final OutputStreamWriter gos = new OutputStreamWriter(new CloseShieldOutputStream(zip), StandardCharsets.UTF_8);
        objectMapper.writeValue(gos, featureCollection);
        zip.closeEntry();

        // Metadata
        final OutputStreamWriter mos = new OutputStreamWriter(zip, StandardCharsets.UTF_8);
        zip.putNextEntry(new ZipEntry(FILENAME_METADATA));
        mos.write(exportMetadataString(clubArea, locale));
        mos.flush();
        zip.closeEntry();

        zip.flush();
        zip.close();

        return bos.toByteArray();

    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
项目:extract    文件:DumpQueueTask.java   
@Override
public Void run() throws Exception {
    try (final OutputStream output = new BufferedOutputStream(new CloseShieldOutputStream(System.out));
    final DocumentQueue queue = new DocumentQueueFactory(options).createShared()) {
        monitor.hintRemaining(queue.size());
        dump(queue, output);
    }

    return null;
}
项目:extract    文件:DumpReportTask.java   
@Override
public Void run() throws Exception {
    final Optional<ExtractionStatus> result = options.get("reportStatus").value(ExtractionStatus::parse);

    try (final OutputStream output = new BufferedOutputStream(new CloseShieldOutputStream(System.out));
         final ReportMap reportMap = new ReportMapFactory(options).createShared()) {
        monitor.hintRemaining(reportMap.size());
        dump(reportMap, output, result.orElse(null));
    }

    return null;
}
项目:Pushjet-Android    文件:ForkingGradleHandle.java   
public GradleHandle start() {
    if (execHandle != null) {
        throw new IllegalStateException("you have already called start() on this handle");
    }

    AbstractExecHandleBuilder execBuilder = execHandleFactory.create();
    execBuilder.setStandardOutput(new CloseShieldOutputStream(new TeeOutputStream(System.out, standardOutput)));
    execBuilder.setErrorOutput(new CloseShieldOutputStream(new TeeOutputStream(System.err, errorOutput)));
    execHandle = execBuilder.build();

    execHandle.start();

    return this;
}
项目:Pushjet-Android    文件:ForkingGradleHandle.java   
public GradleHandle start() {
    if (execHandle != null) {
        throw new IllegalStateException("you have already called start() on this handle");
    }

    AbstractExecHandleBuilder execBuilder = execHandleFactory.create();
    execBuilder.setStandardOutput(new CloseShieldOutputStream(new TeeOutputStream(System.out, standardOutput)));
    execBuilder.setErrorOutput(new CloseShieldOutputStream(new TeeOutputStream(System.err, errorOutput)));
    execHandle = execBuilder.build();

    execHandle.start();

    return this;
}
项目:zSqoop    文件:LobFile.java   
@Override
/**
 * {@inheritDoc}
 */
public OutputStream writeBlobRecord(long claimedLen) throws IOException {
  finishRecord(); // finish any previous record.
  checkForNull(this.out);
  startRecordIndex();
  this.header.getStartMark().write(out);
  LOG.debug("Starting new record; id=" + curEntryId
      + "; claimedLen=" + claimedLen);
  WritableUtils.writeVLong(out, curEntryId);
  WritableUtils.writeVLong(out, claimedLen);
  this.curClaimedLen = claimedLen;
  this.userCountingOutputStream = new CountingOutputStream(
      new CloseShieldOutputStream(out));
  if (null == this.codec) {
    // No codec; pass thru the same OutputStream to the user.
    this.userOutputStream = this.userCountingOutputStream;
  } else {
    // Wrap our CountingOutputStream in a compressing OutputStream to
    // give to the user.
    this.compressor.reset();
    this.userOutputStream = new CompressorStream(
        this.userCountingOutputStream, compressor);
  }

  return this.userOutputStream;
}
项目:sqoop    文件:LobFile.java   
@Override
/**
 * {@inheritDoc}
 */
public OutputStream writeBlobRecord(long claimedLen) throws IOException {
  finishRecord(); // finish any previous record.
  checkForNull(this.out);
  startRecordIndex();
  this.header.getStartMark().write(out);
  LOG.debug("Starting new record; id=" + curEntryId
      + "; claimedLen=" + claimedLen);
  WritableUtils.writeVLong(out, curEntryId);
  WritableUtils.writeVLong(out, claimedLen);
  this.curClaimedLen = claimedLen;
  this.userCountingOutputStream = new CountingOutputStream(
      new CloseShieldOutputStream(out));
  if (null == this.codec) {
    // No codec; pass thru the same OutputStream to the user.
    this.userOutputStream = this.userCountingOutputStream;
  } else {
    // Wrap our CountingOutputStream in a compressing OutputStream to
    // give to the user.
    this.compressor.reset();
    this.userOutputStream = new CompressorStream(
        this.userCountingOutputStream, compressor);
  }

  return this.userOutputStream;
}
项目:Reer    文件:OutputCapturer.java   
public OutputCapturer(OutputStream standardStream, String outputEncoding) {
    this.buffer = new ByteArrayOutputStream();
    this.outputStream = new CloseShieldOutputStream(new TeeOutputStream(standardStream, buffer));
    this.outputEncoding = outputEncoding;
}
项目:Pushjet-Android    文件:SafeStreams.java   
public static OutputStream systemErr() {
    return new CloseShieldOutputStream(System.err);
}
项目:Pushjet-Android    文件:SafeStreams.java   
public static OutputStream systemOut() {
    return new CloseShieldOutputStream(System.out);
}
项目:Pushjet-Android    文件:SafeStreams.java   
public static OutputStream systemErr() {
    return new CloseShieldOutputStream(System.err);
}
项目:Pushjet-Android    文件:SafeStreams.java   
public static OutputStream systemOut() {
    return new CloseShieldOutputStream(System.out);
}
项目:deeplearning4j    文件:ModelSerializer.java   
/**
 * Write a model to an output stream
 * @param model the model to save
 * @param stream the output stream to write to
 * @param saveUpdater whether to save the updater for the model or not
 * @param dataNormalization the normalizer ot save (may be null)
 * @throws IOException
 */
public static void writeModel(@NonNull Model model, @NonNull OutputStream stream, boolean saveUpdater,DataNormalization dataNormalization)
        throws IOException {
    ZipOutputStream zipfile = new ZipOutputStream(new CloseShieldOutputStream(stream));

    // Save configuration as JSON
    String json = "";
    if (model instanceof MultiLayerNetwork) {
        json = ((MultiLayerNetwork) model).getLayerWiseConfigurations().toJson();
    } else if (model instanceof ComputationGraph) {
        json = ((ComputationGraph) model).getConfiguration().toJson();
    }
    ZipEntry config = new ZipEntry("configuration.json");
    zipfile.putNextEntry(config);
    zipfile.write(json.getBytes());

    // Save parameters as binary
    ZipEntry coefficients = new ZipEntry("coefficients.bin");
    zipfile.putNextEntry(coefficients);
    DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(zipfile));
    try {
        Nd4j.write(model.params(), dos);
    } finally {
        dos.flush();
        if (!saveUpdater)
            dos.close();
    }

    if (saveUpdater) {
        INDArray updaterState = null;
        if (model instanceof MultiLayerNetwork) {
            updaterState = ((MultiLayerNetwork) model).getUpdater().getStateViewArray();
        } else if (model instanceof ComputationGraph) {
            updaterState = ((ComputationGraph) model).getUpdater().getStateViewArray();
        }

        if (updaterState != null && updaterState.length() > 0) {
            ZipEntry updater = new ZipEntry(UPDATER_BIN);
            zipfile.putNextEntry(updater);

            try {
                Nd4j.write(updaterState, dos);
            } finally {
                dos.flush();
                dos.close();
            }
        }
    }


    if(dataNormalization != null) {
        // now, add our normalizer as additional entry
        ZipEntry nEntry = new ZipEntry(NORMALIZER_BIN);
        zipfile.putNextEntry(nEntry);
        NormalizerSerializer.getDefault().write(dataNormalization, zipfile);
    }


    zipfile.close();
}