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


Java Channels.newInputStream方法代码示例

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


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

示例1: load

import java.nio.channels.Channels; //导入方法依赖的package包/类
@Override
public boolean load(BuildCacheKey buildCacheKey, BuildCacheEntryReader buildCacheEntryReader)
    throws BuildCacheException {
  try {
    Blob blob = cloudStorage.get(cacheKeyToBlobId(buildCacheKey));
    if (blob == null || !blob.exists()) {
      return false;
    }
    try (InputStream is = Channels.newInputStream(blob.reader())) {
      buildCacheEntryReader.readFrom(is);
    }
  } catch (Exception e) {
    logger.warn(
        "Exception when trying to read from cloud storage, this usually means gcloud "
            + "auth application-default login has not been called. Builds may be slower.",
        e);
    return false;
  }
  return true;
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:21,代码来源:CloudStorageBuildCacheService.java

示例2: readBytes

import java.nio.channels.Channels; //导入方法依赖的package包/类
/**
 * 
 */
public static byte[] readBytes(File file) throws IOException {
    if (file != null) {
        long fileSize = file.length();
        
        if (fileSize > MAX_ARRAY_SIZE) {
            throw new IOException("file is too large");
        }
        
        try (SeekableByteChannel byteChannel = Files.newByteChannel(file.toPath());
                InputStream inputStream = Channels.newInputStream(byteChannel)) {
            
            int available = inputStream.available();
            
            if (available > 0) {
                return readBytes(inputStream,available > fileSize ?
                        available : (int)fileSize);
            }
        }
    }
    
    return EMPTY_BYTE_ARRAY;
}
 
开发者ID:annoflex,项目名称:annoflex,代码行数:26,代码来源:SystemToolkit.java

示例3: parseDatHeader

import java.nio.channels.Channels; //导入方法依赖的package包/类
private void parseDatHeader() throws IOException {
    if (parsed) return;
    try (SeekableByteChannel channel = Files.newByteChannel(datFile)) {
        channel.position(Math.abs(position));
        CountingStream countingStream = new CountingStream(new BufferedInputStream(Channels.newInputStream(channel)), Long.MAX_VALUE);
        DataInputStream stream = new DataInputStream(countingStream);
        String status = readString(stream);
        String size = readString(stream);
        String msg = readString(stream);
        String contentType = readString(stream);
        String lastModified = readString(stream);
        String etag = readString(stream);

        for (;;) {
            String line = readString(stream);
            if (line.equals("HTS")) break;
            if (line.equals("SD")) {
                readString(stream); // supplementary data
            }
        }

        dataLen = Long.parseLong(readString(stream));
        headerLen = countingStream.count;
        parsed = true;
    }
}
 
开发者ID:nla,项目名称:httrack2warc,代码行数:27,代码来源:NdxCache.java

示例4: getImpl

import java.nio.channels.Channels; //导入方法依赖的package包/类
@Override
public <T> T getImpl(Class<? extends T> cl)
{
   if (InputStream.class.isAssignableFrom(cl))
   {
      try
      {
         Pipe pipe = Pipe.open();
         DownloadTask dltask = new DownloadTask(pipe);
         Thread download_thread = new Thread(dltask, "Product Download");
         download_thread.start();

         InputStream is = Channels.newInputStream(pipe.source());
         return cl.cast(is);
      }
      catch (IOException ex)
      {
         LOGGER.error("could not create pipe", ex);
      }
   }
   return null;
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:23,代码来源:DownloadableProduct.java

示例5: init

import java.nio.channels.Channels; //导入方法依赖的package包/类
private void init(FileInputStream is) {
        fileInputStream=is;
        fileChannel=is.getChannel();
        try{
            fileSize=fileChannel.size();
        }catch(IOException e){
            e.printStackTrace();
            fileSize=0;
        }
        boolean openok=false;
//        reader=new InputStreamReader(fileInputStream);
//
//        try{
//            readHeader();
//        }catch(IOException e){
//            log.warning("couldn't read header");
//        }
        size=fileSize/motionData.getLoggedObjectSize();
        dataInputStream=new DataInputStream(Channels.newInputStream(fileChannel));
        getSupport().firePropertyChange("position",0,position());
        position(1);

    }
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:24,代码来源:MotionInputStream.java

示例6: main

import java.nio.channels.Channels; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    ReadableByteChannel channel = new ReadableByteChannel() {
        public int read(ByteBuffer dst) {
            dst.put((byte) 129);
            return 1;
        }

        public boolean isOpen() {
            return true;
        }

        public void close() {
        }
    };

    InputStream in = Channels.newInputStream(channel);
    int data = in.read();
    if (data < 0)
        throw new RuntimeException(
            "InputStream.read() spec'd to return 0-255");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:ReadByte.java

示例7: main

import java.nio.channels.Channels; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    ReadableByteChannel rbc = new ReadableByteChannel() {
        public int read(ByteBuffer dst) {
            dst.put((byte)0);
            return 1;
        }
        public boolean isOpen() {
            return true;
        }
        public void close() {
        }
    };

    InputStream in = Channels.newInputStream(rbc);

    byte[] b = new byte[3];
    in.read(b, 0, 1);
    in.read(b, 2, 1);       // throws IAE
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ReadOffset.java

示例8: RandomBufferedReader

import java.nio.channels.Channels; //导入方法依赖的package包/类
public RandomBufferedReader(Reader in, RandomAccessFile raf, String encoding) throws UnsupportedEncodingException {
    super(in);
    this.raf = raf;
    this.encoding = encoding;
    this.is = Channels.newInputStream(raf.getChannel());
    initBufferedReader();
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:8,代码来源:RandomBufferedReader.java

示例9: getInputStream

import java.nio.channels.Channels; //导入方法依赖的package包/类
@Override
public InputStream getInputStream(long from) throws Exception {
    RandomAccessFile raf = new RandomAccessFile(new File(mUri.getPath()), "r");
    if (raf != null) {
        raf.seek(from);
        return Channels.newInputStream(raf.getChannel());
    }
    return null;
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:10,代码来源:LocalStorageFileEditor.java

示例10: getNextSpectrumFromSeekable

import java.nio.channels.Channels; //导入方法依赖的package包/类
private T getNextSpectrumFromSeekable() {
	FromXMLStreamBuilder<T> spectrumBuilder = null;
	try {
		InputStream is = Channels.newInputStream(this.seekable);
		XMLStreamReader xr = XMLInputFactory.newInstance()
			.createXMLStreamReader(is);
		
		while (xr.hasNext()) {
			xr.next();
			
			if (spectrumBuilder != null) {
				spectrumBuilder.accept(xr);
			}

			if(xr.getEventType() == XMLStreamReader.START_ELEMENT){
				if(xr.getLocalName().equals("spectrum")) {
					spectrumBuilder = this.factory.create(this.xml.toString(), xr);
				} else if( xr.getLocalName().equals("referenceableParamGroupRef")) {
					LOGGER.log(Level.WARN, "Random access to spectra will not parse referenceable params");
				}
			} else if(xr.getEventType() == XMLStreamReader.END_ELEMENT) {
				if(xr.getLocalName().equals("spectrum")) {
					return spectrumBuilder.build();
				}					
			}
		}
	} catch (XMLStreamException | FactoryConfigurationError e) {
		LOGGER.log(Level.ERROR, e.toString());
	} 

	return null;
}
 
开发者ID:digitalproteomics,项目名称:dp-mzml,代码行数:33,代码来源:MzMLStAXParser.java

示例11: reverseRead

import java.nio.channels.Channels; //导入方法依赖的package包/类
public static byte[] reverseRead(final Path path,Charset charset,long size) throws IOException {
    try (SeekableByteChannel sbc = Files.newByteChannel(path);
         InputStream in = Channels.newInputStream(sbc)) {
        long startIndex = sbc.size() - size;
        if (startIndex < 0) {
            startIndex = 0;
        }
        in.skip(startIndex);
        if (size > (long) MAX_BUFFER_SIZE)
            throw new OutOfMemoryError("Required array size too large");

        return read(in, (int) size);

    }
}
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:16,代码来源:IOUtils.java

示例12: mockStream

import java.nio.channels.Channels; //导入方法依赖的package包/类
public static InputStream mockStream(long length) {
    try {
        RandomAccessFile raf = new RandomAccessFile("t", "rw");
        raf.setLength(length);

        return Channels.newInputStream(raf.getChannel());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:josueeduardo,项目名称:rest-client,代码行数:11,代码来源:TestUtils.java

示例13: setGalleryAppImage

import java.nio.channels.Channels; //导入方法依赖的package包/类
/**
 * when an app is published/updated, we need to move the image
 * that was temporarily uploaded into projects/projectid/image
 * into the gallery image
 * @param app gallery app
 */
private void setGalleryAppImage(GalleryApp app) {
  // best thing would be if GCS has a mv op, we can just do that.
  // don't think that is there, though, so for now read one and write to other
  // First, read the file from projects name
  boolean lockForRead = false;
  //String projectImageKey = app.getProjectImageKey();
  GallerySettings settings = loadGallerySettings();
  String projectImageKey = settings.getProjectImageKey(app.getProjectId());
  try {
    GcsService gcsService = GcsServiceFactory.createGcsService();
    //GcsFilename filename = new GcsFilename(GalleryApp.GALLERYBUCKET, projectImageKey);
    GcsFilename filename = new GcsFilename(settings.getBucket(), projectImageKey);
    GcsInputChannel readChannel = gcsService.openReadChannel(filename, 0);
    InputStream gcsis = Channels.newInputStream(readChannel);

    byte[] buffer = new byte[8000];
    int bytesRead = 0;
    ByteArrayOutputStream bao = new ByteArrayOutputStream();

    while ((bytesRead = gcsis.read(buffer)) != -1) {
      bao.write(buffer, 0, bytesRead);
    }
    // close the project image file
    readChannel.close();

    // if image is greater than 200 X 200, it will be scaled (200 X 200).
    // otherwise, it will be stored as origin.
    byte[] oldImageData = bao.toByteArray();
    byte[] newImageData;
    ImagesService imagesService = ImagesServiceFactory.getImagesService();
    Image oldImage = ImagesServiceFactory.makeImage(oldImageData);
    //if image size is too big, scale it to a smaller size.
    if(oldImage.getWidth() > 200 && oldImage.getHeight() > 200){
        Transform resize = ImagesServiceFactory.makeResize(200, 200);
        Image newImage = imagesService.applyTransform(resize, oldImage);
        newImageData = newImage.getImageData();
    }else{
        newImageData = oldImageData;
    }

    // set up the cloud file (options)
    // After publish, copy the /projects/projectId image into /apps/appId
    //String galleryKey = app.getImageKey();
    String galleryKey = settings.getImageKey(app.getGalleryAppId());

    //GcsFilename outfilename = new GcsFilename(GalleryApp.GALLERYBUCKET, galleryKey);
    GcsFilename outfilename = new GcsFilename(settings.getBucket(), galleryKey);
    GcsFileOptions options = new GcsFileOptions.Builder().mimeType("image/jpeg")
        .acl("public-read").cacheControl("no-cache").build();
    GcsOutputChannel writeChannel = gcsService.createOrReplace(outfilename, options);
    writeChannel.write(ByteBuffer.wrap(newImageData));

    // Now finalize
    writeChannel.close();

  } catch (IOException e) {
    // TODO Auto-generated catch block
    LOG.log(Level.INFO, "FAILED WRITING IMAGE TO GCS");
    e.printStackTrace();
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:68,代码来源:GalleryServiceImpl.java

示例14: 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

示例15: getInputStream

import java.nio.channels.Channels; //导入方法依赖的package包/类
@Override
public InputStream getInputStream() throws IOException {
	return Channels.newInputStream(throwExceptionForNullBlob(getGoogleStorageObject()).reader());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:5,代码来源:GoogleStorageResourceObject.java


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