當前位置: 首頁>>代碼示例>>Java>>正文


Java IOUtils.closeQuietly方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.utils.IOUtils.closeQuietly方法的典型用法代碼示例。如果您正苦於以下問題:Java IOUtils.closeQuietly方法的具體用法?Java IOUtils.closeQuietly怎麽用?Java IOUtils.closeQuietly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.utils.IOUtils的用法示例。


在下文中一共展示了IOUtils.closeQuietly方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: publish

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
public void publish(BrokerStats brokerStats) throws IOException {
  try {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    BinaryEncoder binaryEncoder = avroEncoderFactory.binaryEncoder(stream, null);

    avroEventWriter.write(brokerStats, binaryEncoder);
    binaryEncoder.flush();
    IOUtils.closeQuietly(stream);

    String key = brokerStats.getName() + "_" + System.currentTimeMillis();
    int numPartitions = kafkaProducer.partitionsFor(destTopic).size();
    int partition = brokerStats.getId() % numPartitions;

    Future<RecordMetadata> future = kafkaProducer.send(
        new ProducerRecord(destTopic, partition, key.getBytes(), stream.toByteArray()));
    future.get();

    OpenTsdbMetricConverter.incr("kafka.stats.collector.success", 1, "host=" + HOSTNAME);
  } catch (Exception e) {
    LOG.error("Failure in publish stats", e);
    OpenTsdbMetricConverter.incr("kafka.stats.collector.failure", 1, "host=" + HOSTNAME);
    throw new RuntimeException("Avro serialization failure", e);
  }
}
 
開發者ID:pinterest,項目名稱:doctorkafka,代碼行數:25,代碼來源:KafkaAvroPublisher.java

示例2: sendMessage

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
public synchronized void sendMessage(String clusterName, String message) {
  int numRetries = 0;
  while (numRetries < MAX_RETRIES) {
    try {
      long timestamp = System.currentTimeMillis();
      OperatorAction operatorAction = new OperatorAction(timestamp, clusterName, message);

      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      BinaryEncoder binaryEncoder = avroEncoderFactory.binaryEncoder(stream, null);
      avroWriter.write(operatorAction, binaryEncoder);
      binaryEncoder.flush();
      IOUtils.closeQuietly(stream);

      String key = "" + System.currentTimeMillis();
      ProducerRecord  producerRecord =
          new ProducerRecord(topic, key.getBytes(), stream.toByteArray());
      Future<RecordMetadata> future = kafkaProducer.send(producerRecord);
      future.get();
      LOG.info("Send an message {} to action report : ", message);
      break;
    } catch (Exception e) {
      LOG.error("Failed to publish report message {}: {}", clusterName, message, e);
      numRetries++;
    }
  }
}
 
開發者ID:pinterest,項目名稱:doctorkafka,代碼行數:27,代碼來源:DoctorKafkaActionReporter.java

示例3: gZip

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
public static byte[] gZip(byte[] data) throws IOException
{
	byte[] ret = null;
	ByteArrayOutputStream bos = null;
	GZIPOutputStream gzip = null;
	try
	{
		bos = new ByteArrayOutputStream();
		gzip = new GZIPOutputStream(bos);
		gzip.write(data);
		gzip.finish();
		ret = bos.toByteArray();
	} finally
	{
		IOUtils.closeQuietly(gzip);
		IOUtils.closeQuietly(bos);
	}
	return ret;
}
 
開發者ID:tywo45,項目名稱:talent-aio,代碼行數:20,代碼來源:GzipUtils.java

示例4: run

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
@Override
public void run() {
    try {
        final InputStreamReader isr = new InputStreamReader(is);
        final BufferedReader br = new BufferedReader(isr);
        String line;
        final String[] errors = new String[3];

        int counter = 0;
        while ((line = br.readLine()) != null) {
            Log.v(TAG, line);
            errors[counter++ % 3] = line;
        }
        if (er != null)
            er.onError(errors);

    } catch (final IOException ioe) {
        ioe.printStackTrace();
    } finally {
        IOUtils.closeQuietly(is);
    }
}
 
開發者ID:greenaddress,項目名稱:abcore,代碼行數:23,代碼來源:ProcessLogger.java

示例5: onPause

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
@Override
protected void onPause() {
    super.onPause();
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED &&
            !ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE))
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    0);

    // save file
    OutputStream f = null;
    try {
        f = new FileOutputStream(Utils.getBitcoinConf(this));
        IOUtils.copy(new ByteArrayInputStream(((EditText) findViewById(R.id.editText))
                .getText().toString().getBytes("UTF-8")), f);

    } catch (final IOException e) {
        Log.i(TAG, e.getMessage());
    } finally {
        IOUtils.closeQuietly(f);
    }
}
 
開發者ID:greenaddress,項目名稱:abcore,代碼行數:26,代碼來源:BitcoinConfEditActivity.java

示例6: saveToFile

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
/**
 * Saves the passed bytes to the passed file
 *
 * @param compressedFile The file the bytes are to be saved to
 * @param boas The {@link ByteArrayOutputStream} containing the bytes to be saved
 * @return true if the file was successfully saved
 */
public static boolean saveToFile(File compressedFile, ByteArrayOutputStream boas)
{
    try
    {
        // Creating file
        if (!compressedFile.exists())
        {
            compressedFile.getParentFile().mkdirs();
            compressedFile.createNewFile();
        }

        byte[] buffer = boas.toByteArray();
        IOUtils.closeQuietly(boas);
        GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(compressedFile));
        out.write(buffer, 0, buffer.length);
        IOUtils.closeQuietly(out);
        return true;
    }

    catch (Exception e)
    {
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:duke605,項目名稱:DiscordCE,代碼行數:33,代碼來源:CompressionUtil.java

示例7: initialize

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
@Override
public void initialize(final UimaContext context) throws ResourceInitializationException {
	super.initialize(context);

	model = ModelFactory.createOntologyModel();
	InputStream in = null;
	try {
		in = new FileInputStream(outputFileName);
		model.read(in, "http://github.com/quadrama/metadata/ontology.owl");
		in.close();
	} catch (IOException e) {
		Ontology o = model.createOntology("http://github.com/quadrama/metadata/ontology.owl");
		o.setRDFType(OWL2.Ontology);
		model.setNsPrefix("gndo", "http://d-nb.info/standards/elementset/gnd#");
		model.setNsPrefix("gnd", "http://d-nb.info/gnd/");
		model.setNsPrefix("dc", "http://purl.org/dc/elements/1.1/");
		model.setNsPrefix("oa", "http://www.w3.org/ns/oa#");
		model.setNsPrefix("dbo", "http://dbpedia.org/ontology/");
		model.setNsPrefix("qd", QD.NS);
	} finally {
		IOUtils.closeQuietly(in);
	}

}
 
開發者ID:quadrama,項目名稱:DramaNLP,代碼行數:25,代碼來源:MetaDataExport.java

示例8: collectionProcessComplete

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
@Override
public void collectionProcessComplete() throws AnalysisEngineProcessException {
	BaseXMLWriter xmlWriter = new Basic();

	if (outputFileName == null) {
		xmlWriter.write(model, System.out, "");
		System.out.flush();
	} else {
		Writer w = null;
		try {
			w = new FileWriter(new File(outputFileName));
			xmlWriter.write(model, w, "");
			w.flush();
			w.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			IOUtils.closeQuietly(w);
		}

	}
}
 
開發者ID:quadrama,項目名稱:DramaNLP,代碼行數:23,代碼來源:MetaDataExport.java

示例9: close

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
@Override
protected void close()
{
    if ( jsonGenerator == null )
    {
        return;
    }

    try
    {
        if ( startedArray.get() )
        {
            jsonGenerator.writeEndArray();
        }

        jsonGenerator.writeEndObject();
    }
    catch ( IOException ignored )
    {
    }
    finally
    {
        IOUtils.closeQuietly( jsonGenerator );
    }
}
 
開發者ID:dhis2,項目名稱:dhis2-core,代碼行數:26,代碼來源:StreamingJsonCompleteDataSetRegistrations.java

示例10: getStringContent

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
private static String getStringContent(HttpEntity httpEntity) {

        BufferedReader bufferedReader;
        StringBuilder content = new StringBuilder();

        try {
            bufferedReader = new BufferedReader(
                    new InputStreamReader((httpEntity.getContent()), "UTF-8"));
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                content.append(line);
            }
            IOUtils.closeQuietly(bufferedReader);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return content.toString();
    }
 
開發者ID:voyages-sncf-technologies,項目名稱:hesperides,代碼行數:19,代碼來源:FeedbacksAggregate.java

示例11: extractZipFile

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
private static void extractZipFile(final File destination, final ZipFile zipFile) throws IOException {
    final Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();

    while (entries.hasMoreElements()) {
        final ZipArchiveEntry entry = entries.nextElement();
        final File entryDestination = new File(destination, entry.getName());

        if (entry.isDirectory()) {
            entryDestination.mkdirs();
        } else {
            entryDestination.getParentFile().mkdirs();
            final InputStream in = zipFile.getInputStream(entry);
            try (final OutputStream out = new FileOutputStream(entryDestination)) {
                IOUtils.copy(in, out);
                IOUtils.closeQuietly(in);
            }
        }
    }
}
 
開發者ID:awslabs,項目名稱:aws-codepipeline-plugin-for-jenkins,代碼行數:20,代碼來源:ExtractionTools.java

示例12: run

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
@Override
public void run() {
  // get the file
  Thread.currentThread().setName(SPOOL_DIR_THREAD_PREFIX + threadNumber);
  initGaugeIfNeeded();
  Offset offset = offsets.get(lastSourceFileName);

  while (!context.isStopped()) {
    try {
      offset = produce(offset, context.startBatch());
    } catch (StageException ex) {
      handleStageError(ex.getErrorCode(), ex);
    }
  }

  IOUtils.closeQuietly(parser);
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:18,代碼來源:SpoolDirRunnable.java

示例13: readNext

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
private Path readNext() {
    if(fileIt != null && !fileIt.hasNext()) {
        IOUtils.closeQuietly(filesStream); // no more files on this folder, close it.
        if(!hostIt.hasNext()) {
            IOUtils.closeQuietly(hostsStream);
            return null; // no more file and folders available
        }
        // iterate over next folder available
        Path hostPath = null;
        try {
            hostPath = hostIt.next();
            filesStream = Files.newDirectoryStream(hostPath);
            fileIt = filesStream.iterator();
        } catch (IOException e) {
            String f = hostPath == null ? null : hostPath.toString();
            throw new IllegalArgumentException("Failed to open host folder: "+f, e);
        }
    }
    
    if(fileIt != null && fileIt.hasNext()) {
        return fileIt.next();
    }
    
    return null;
}
 
開發者ID:ViDA-NYU,項目名稱:ache,代碼行數:26,代碼來源:FileSystemTargetRepository.java

示例14: callService

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public <T> T callService(String urlWithoutPrefix, boolean failSilently) {
	URL url = null;
	BufferedReader in = null;
	try {
		url = new URL(serverUrl + SERVICE_PREFIX + "/" + urlWithoutPrefix);
		URLConnection yc = url.openConnection();
		in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
		ObjectMapper objectMapper = new ObjectMapper();
		Map<String, Object> result = (Map<String, Object>) objectMapper.readValue(in, HashMap.class);
		return (T) result.get("messageResult");
	} catch (IOException e1) {
		if (!failSilently) {
			log("Error while accessing url = " + url, e1);
		}
		return null;
	} finally {
		IOUtils.closeQuietly(in);
	}
}
 
開發者ID:flower-platform,項目名稱:flower-platform-arduino-ide-plugin,代碼行數:21,代碼來源:FlowerPlatformPlugin.java

示例15: saveKeyPair

import org.apache.commons.compress.utils.IOUtils; //導入方法依賴的package包/類
/**
 * Saves public and private keys to specified files.
 *
 * @param keyPair        the key pair
 * @param privateKeyFile the private key file
 * @param publicKeyFile  the public key file
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void saveKeyPair(KeyPair keyPair, String privateKeyFile, String publicKeyFile)
        throws IOException {
  File privateFile = makeDirs(privateKeyFile);
  File publicFile = makeDirs(publicKeyFile);
  OutputStream privateKeyOutput = null;
  OutputStream publicKeyOutput = null;
  try {
    privateKeyOutput = new FileOutputStream(privateFile);
    publicKeyOutput = new FileOutputStream(publicFile);
    saveKeyPair(keyPair, privateKeyOutput, publicKeyOutput);
  } finally {
    IOUtils.closeQuietly(privateKeyOutput);
    IOUtils.closeQuietly(publicKeyOutput);
  }
}
 
開發者ID:kaaproject,項目名稱:kaa,代碼行數:24,代碼來源:KeyUtil.java


注:本文中的org.apache.commons.compress.utils.IOUtils.closeQuietly方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。