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


Java Channels.newOutputStream方法代码示例

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


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

示例1: getContentOutputStream

import java.nio.channels.Channels; //导入方法依赖的package包/类
/**
 * @see Channels#newOutputStream(java.nio.channels.WritableByteChannel)
 */
public OutputStream getContentOutputStream() throws ContentIOException
{
    try
    {
        WritableByteChannel channel = getWritableChannel();
        OutputStream is = new BufferedOutputStream(Channels.newOutputStream(channel));
        // done
        return is;
    }
    catch (Throwable e)
    {
        throw new ContentIOException("Failed to open stream onto channel: \n" +
                "   writer: " + this,
                e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:20,代码来源:AbstractContentWriter.java

示例2: store

import java.nio.channels.Channels; //导入方法依赖的package包/类
@Override
public void store(BuildCacheKey buildCacheKey, BuildCacheEntryWriter buildCacheEntryWriter)
    throws BuildCacheException {
  Blob blob = cloudStorage.get(cacheKeyToBlobId(buildCacheKey));
  if (blob == null || !blob.exists()) {
    blob =
        cloudStorage.create(
            BlobInfo.newBuilder(cacheKeyToBlobId(buildCacheKey))
                .setContentType(BUILD_CACHE_CONTENT_TYPE)
                .build());
  }
  try (OutputStream os = Channels.newOutputStream(blob.writer())) {
    buildCacheEntryWriter.writeTo(os);
  } catch (IOException e) {
    throw new UncheckedIOException("Error writing file from cloud storage.", e);
  }
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:18,代码来源:CloudStorageBuildCacheService.java

示例3: CompressedSequentialWriter

import java.nio.channels.Channels; //导入方法依赖的package包/类
/**
 * Create CompressedSequentialWriter without digest file.
 *
 * @param file File to write
 * @param offsetsPath File name to write compression metadata
 * @param digestFile File to write digest
 * @param option Write option (buffer size and type will be set the same as compression params)
 * @param parameters Compression mparameters
 * @param sstableMetadataCollector Metadata collector
 */
public CompressedSequentialWriter(String file,
                                  String offsetsPath,
                                  String digestFile,
                                  SequentialWriterOption option,
                                  CompressionParams parameters,
                                  MetadataCollector sstableMetadataCollector,
                                  Configuration conf)
{
    super(file,
            SequentialWriterOption.newBuilder()
                        .bufferSize(option.bufferSize())
                        .bufferType(option.bufferType())
                        .bufferSize(parameters.chunkLength())
                        .bufferType(parameters.getSstableCompressor().preferredBufferType())
                        .finishOnClose(option.finishOnClose())
                        .build(),
            conf);
    this.compressor = parameters.getSstableCompressor();
    this.digestFile = Optional.ofNullable(digestFile);

    // buffer for compression should be the same size as buffer itself
    compressed = compressor.preferredBufferType().allocate(compressor.initialCompressedBufferLength(buffer.capacity()));

    /* Index File (-CompressionInfo.db component) and it's header */
    metadataWriter = CompressionMetadata.Writer.open(parameters, offsetsPath, conf);

    this.sstableMetadataCollector = sstableMetadataCollector;
    crcMetadata = new ChecksumWriter(new DataOutputStream(Channels.newOutputStream(channel)), conf);
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:40,代码来源:CompressedSequentialWriter.java

示例4: acceptSocketAndKey

import java.nio.channels.Channels; //导入方法依赖的package包/类
synchronized boolean acceptSocketAndKey(int key, SocketChannel socket, ObjectInputStream istm) throws IOException {
    if (closed) {
        return false;
    }
    if (id != key) {
        return false;
    }
    this.ostm = Channels.newOutputStream(socket);
    this.istm = istm;
    this.controlSocket = socket;
    notify();
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:JShellConnection.java

示例5: writeEmptyTranslog

import java.nio.channels.Channels; //导入方法依赖的package包/类
/**
 * Write a translog containing the given translog UUID to the given location. Returns the number of bytes written.
 */
public static int writeEmptyTranslog(Path filename, String translogUUID) throws IOException {
    final BytesRef translogRef = new BytesRef(translogUUID);
    try (FileChannel fc = FileChannel.open(filename, StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.CREATE_NEW);
            OutputStreamDataOutput out = new OutputStreamDataOutput(Channels.newOutputStream(fc))) {
        TranslogWriter.writeHeader(out, translogRef);
        fc.force(true);
    }
    return TranslogWriter.getHeaderLength(translogRef.length);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:TruncateTranslogCommand.java

示例6: SmbFSIndexOutput

import java.nio.channels.Channels; //导入方法依赖的package包/类
SmbFSIndexOutput(String name) throws IOException {
    super("SmbFSIndexOutput(path=\"" + fsDirectory.getDirectory().resolve(name) + "\")", name, new FilterOutputStream(Channels.newOutputStream(Files.newByteChannel(fsDirectory.getDirectory().resolve(name), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.READ, StandardOpenOption.WRITE))) {
        // This implementation ensures, that we never write more than CHUNK_SIZE bytes:
        @Override
        public void write(byte[] b, int offset, int length) throws IOException {
            while (length > 0) {
                final int chunk = Math.min(length, CHUNK_SIZE);
                out.write(b, offset, chunk);
                length -= chunk;
                offset += chunk;
            }
        }
    }, CHUNK_SIZE);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:SmbDirectoryWrapper.java

示例7: write

import java.nio.channels.Channels; //导入方法依赖的package包/类
public BlobHandle write(byte[] data, String fileName, String mimeType, boolean finalize) {
  LOGGER.fine("Entering writeBytes");
  BlobHandle handle = new BlobHandle();
  // Get a file service
  FileService fileService = FileServiceFactory.getFileService();
  try {
    // Create a new Blob file with mime-type
    AppEngineFile file = fileService.createNewBlobFile(mimeType, fileName);
    // Open a channel to write to it
    boolean lock = finalize;
    FileChannel writeChannel = fileService.openWriteChannel(file, lock);
    DataOutputStream out = new DataOutputStream(Channels.newOutputStream(writeChannel));
    // This time we write to the channel using standard Java
    out.write(data);
    out.close();
    // Now read from the file using the Blobstore API
    handle.filePath = file.getFullPath();
    // Now finalize, if needed
    if (finalize) {
      writeChannel.close();
      // Get the blob key, which is available for finalized blobs
      BlobKey blobKey = fileService.getBlobKey(file);
      if (blobKey != null) {
        handle.blobKey = blobKey.getKeyString();
      }
    }
  } catch (Exception e) {
    LOGGER.severe(
        "Exception while trying to write to blobstore: file = {0}, mimeType = {1}: {2} : {3}",
        fileName, mimeType, e.getClass().getName(), e.getMessage());
  }
  LOGGER.fine("Exiting uploadToBlobStore");
  return handle;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:35,代码来源:HDFSBlobStoreService.java

示例8: write

import java.nio.channels.Channels; //导入方法依赖的package包/类
@Override
public StatusOutputStream<Void> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
    try {
        final java.nio.file.Path p = session.toPath(file);
        final Set<OpenOption> options = new HashSet<>();
        options.add(StandardOpenOption.WRITE);
        if(status.isAppend()) {
            if(!status.isExists()) {
                options.add(StandardOpenOption.CREATE);
            }
        }
        else {
            if(status.isExists()) {
                if(file.isSymbolicLink()) {
                    Files.delete(p);
                    options.add(StandardOpenOption.CREATE);
                }
                else {
                    options.add(StandardOpenOption.TRUNCATE_EXISTING);
                }
            }
            else {
                options.add(StandardOpenOption.CREATE_NEW);
            }
        }
        final FileChannel channel = FileChannel.open(session.toPath(file), options.stream().toArray(OpenOption[]::new));
        channel.position(status.getOffset());
        return new VoidStatusOutputStream(Channels.newOutputStream(channel));
    }
    catch(IOException e) {
        throw new LocalExceptionMappingService().map("Upload {0} failed", e, file);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:34,代码来源:LocalWriteFeature.java

示例9: getOutputStream

import java.nio.channels.Channels; //导入方法依赖的package包/类
@Override
public OutputStream getOutputStream() throws IOException {
	Blob blob = getGoogleStorageObject();
	if ((blob == null || !blob.exists()) && this.createBlobIfNotExists) {
		blob = createBlob();
	}
	return Channels.newOutputStream(throwExceptionForNullBlob(blob).writer());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:9,代码来源:GoogleStorageResourceObject.java

示例10: writeFileToTable

import java.nio.channels.Channels; //导入方法依赖的package包/类
/**
 * Example of riting a local file to a table.
 */
// [TARGET writer(WriteChannelConfiguration)]
// [VARIABLE "my_dataset_name"]
// [VARIABLE "my_table_name"]
// [VARIABLE FileSystems.getDefault().getPath(".", "my-data.csv")]
public long writeFileToTable(String datasetName, String tableName, Path fileFullPath, FormatOptions formatOptions)
    throws IOException, InterruptedException, TimeoutException {
  // [START writeFileToTable]
  TableId tableId = TableId.of(datasetName, tableName);
  WriteChannelConfiguration writeChannelConfiguration =
      WriteChannelConfiguration.newBuilder(tableId)
          .setFormatOptions(formatOptions)
          .build();
  TableDataWriteChannel writer = bigquery.writer(writeChannelConfiguration);
  // Write data to writer
  try (OutputStream stream = Channels.newOutputStream(writer)) {
  	Files.copy(fileFullPath, stream);
  }
  // Get load job
  Job job = writer.getJob();
  job = job.waitFor();
  if(job.getStatus().getExecutionErrors() != null){
  	String errors = "";
  	for(BigQueryError error : job.getStatus().getExecutionErrors()){
  		errors += "error: " + error.getMessage() + ", reason: " + error.getReason() + ", location: " + error.getLocation() + "; ";
  	}
  	throw new IOException(errors);
  }
  LoadStatistics stats = job.getStatistics();
  return stats.getOutputRows();
  // [END writeFileToTable]
}
 
开发者ID:michael-hll,项目名称:BigQueryStudy,代码行数:35,代码来源:BigQuerySnippets.java

示例11: execute

import java.nio.channels.Channels; //导入方法依赖的package包/类
/**
 * Execute an operation remotely.
 * This method will block until the return value has been received.
 *
 * @param operation The operation to execute remotely.
 *
 * @return The result of the operation.
 *
 * @exception RuntimeException In case of network error or if the return value class is unknown.
 */

public <T> T execute(Operation<T> operation)
{
    SocketChannel channel = null;
    T result;

    try
    {
        channel = SocketChannel.open(new InetSocketAddress(this.host, this.port));

        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(Channels.newOutputStream(channel), BUFFER_SIZE));
        out.writeObject(operation);
        out.flush();

        ObjectInputStream in = new ObjectInputStream(Channels.newInputStream(channel));
        @SuppressWarnings("unchecked")
        T obj = (T) in.readObject();
        result = obj;
    }
    catch (IOException ioe)
    {
        throw new RuntimeException(ioe);
    }
    catch (ClassNotFoundException cnfe)
    {
        throw new RuntimeException(cnfe);
    }
    finally
    {
        try
        {
            channel.socket().shutdownOutput();
            channel.close();
        }
        catch (Exception e)
        {
            // Ignore
        }
    }

    return result;
}
 
开发者ID:mtommila,项目名称:apfloat,代码行数:53,代码来源:RemoteOperationExecutor.java


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