Java 类java.io.InputStream 实例源码

项目:ViperBot    文件:DownloadManager.java   
public File download(boolean delete, String link) throws IOException{
    URL url = new URL(link);
    URLConnection conn = url.openConnection();
    InputStream in = conn.getInputStream();
    File f = new File(defaultFolder, link);
    FileOutputStream out = new FileOutputStream(f);
    byte[] buffer = new byte[1024];
    int len;
    while((len = in.read(buffer)) > 0){
        out.write(buffer, 0, len);
    }
    in.close();
    out.close();
    if(delete) f.deleteOnExit();
    return f;
}
项目:graphium    文件:BaseSegmentXInfoService.java   
private void streamBaseXInfos(String graph, String version, InputStream inputStream, boolean isSegmentXInfo)
        throws XInfoNotSupportedException, GraphImportException, GraphStorageException, GraphNotExistsException {
    //First checkk if already another import is running. The singleton serverStatus has to be injected therefore
    if (!serverStatus.registerImport()) {
        throw new GraphImportException("Sorry, system is busy, a graph import is currently executed");
    }
    IBaseSegmentProducer<IBaseSegment> producer = null;
    try {

        BlockingQueue<IBaseSegment> segmentsQueue;

        segmentsQueue = new ArrayBlockingQueue<>(queueSize);

        producer = new BaseSegmentProducerImpl<>(inputFormat, inputStream, segmentsQueue);

        Thread producerThread = new Thread(producer, "basesegment-xinfo-parser-thread");
        producerThread.start();

        List<IBaseSegment> segments = new ArrayList<>();
        while (producerThread.isAlive() || !segmentsQueue.isEmpty()) {
            if (!segmentsQueue.isEmpty()) {
                segments.add(segmentsQueue.poll());
            }
            if (segments.size() >= this.batchSize) {
                this.writeSegments(segments,graph,version,isSegmentXInfo);
                segments.clear();
            }
        }
        this.writeSegments(segments,graph,version,isSegmentXInfo);
    } finally {
        serverStatus.unregisterImport();
        if (producer != null && producer.getException() != null) {
            throw new GraphImportException("Graph could not be imported",producer.getException());
        }
    }
}
项目:19porn    文件:Codec.java   
private static String getMD5(final InputStream is, final int bufLen) {
    if (is == null || bufLen <= 0) {
        return null;
    }
    try {
        MessageDigest md = MessageDigest.getInstance(Algorithm.MD5.getType());
        StringBuilder md5Str = new StringBuilder(32);

        byte[] buf = new byte[bufLen];
        int readCount = 0;
        while ((readCount = is.read(buf)) != -1) {
            md.update(buf, 0, readCount);
        }

        byte[] hashValue = md.digest();

        for (int i = 0; i < hashValue.length; i++) {
            md5Str.append(Integer.toString((hashValue[i] & 0xff) + 0x100, 16).substring(1));
        }
        return md5Str.toString();
    } catch (Exception e) {
        return null;
    }
}
项目:Image-Detection-Samples    文件:Utils.java   
public static String exportResource(Context context, int resourceId, String dirname) {
    String fullname = context.getResources().getString(resourceId);
    String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
    try {
        InputStream is = context.getResources().openRawResource(resourceId);
        File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
        File resFile = new File(resDir, resName);

        FileOutputStream os = new FileOutputStream(resFile);

        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = is.read(buffer)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        is.close();
        os.close();

        return resFile.getAbsolutePath();
    } catch (IOException e) {
        e.printStackTrace();
        throw new CvException("Failed to export resource " + resName
                + ". Exception thrown: " + e);
    }
}
项目:FastDFS_Client    文件:StorageModifyCommandTest.java   
@Test
public void testStorageModifyCommand() throws IOException {
    String text = "Tobato is a good man. this is a test of StorageTruncateCommand.";
    InputStream firstIn = getTextInputStream(text);
    long firstSize = firstIn.available();
    // 上载文字
    System.out.println(firstSize);
    StorePath path = uploadInputStream(firstIn, "txt", firstSize, true);
    // 文件修改
    String Modifytext = "This is a test of StorageModifyCommand";
    InputStream modifyIn = getTextInputStream(Modifytext);
    long modifySize = modifyIn.available();
    // 观察运行效果:
    // fileOffset参数0 结果为 This is a test of StorageModifyCommandf
    // StorageTruncateCommand
    // fileOffset参数为20 结果为 Tobato is a good manThis is a test of
    // StorageModifyCommandmand
    StorageModifyCommand command = new StorageModifyCommand(path.getPath(), modifyIn, modifySize, 0);
    executeStoreCmd(command);
    LOGGER.debug("--文件修改处理成功--");
}
项目:trellis    文件:HttpBasedBinaryServiceTest.java   
@Test
public void testGetContentSegment() {
    final BinaryService resolver = new HttpBasedBinaryService(idService.getSupplier("http://example.org/"));

    final Optional<InputStream> res = resolver.getContent(resource, singletonList(between(5, 20)));
    assertTrue(res.isPresent());
    final String str = res.map(this::uncheckedToString).get();

    assertFalse(str.contains("owl:Ontology"));
    assertEquals(16, str.length());
}
项目:Jupiter    文件:Utils.java   
/**
* 
* @param file 書き込み先のファイルオブジェクト
* @param content 書き込む内容(InputStream)
* 
* <p>writeFile - Utils</p>
* 
* <p>contentで指定した内容をファイルに書き込みます。</p>
* 
* Jupiter by Jupiter Development Team
* 
*/

  public static void writeFile(File file, InputStream content) throws IOException {
      if (content == null) {
          throw new IllegalArgumentException("content must not be null");
      }
      if (!file.exists()) {
          file.createNewFile();
      }
      FileOutputStream stream = new FileOutputStream(file);
      byte[] buffer = new byte[1024];
      int length;
      while ((length = content.read(buffer)) != -1) {
          stream.write(buffer, 0, length);
      }
      stream.close();
      content.close();
  }
项目:openjdk-jdk10    文件:HTTPTestServer.java   
private synchronized Thread pipe(InputStream is, OutputStream os, char tag) {
    return new Thread("TunnelPipe("+tag+")") {
        @Override
        public void run() {
            try {
                try {
                    int c;
                    while ((c = is.read()) != -1) {
                        os.write(c);
                        os.flush();
                        // if DEBUG prints a + or a - for each transferred
                        // character.
                        if (DEBUG) System.out.print(tag);
                    }
                    is.close();
                } finally {
                    os.close();
                }
            } catch (IOException ex) {
                if (DEBUG) ex.printStackTrace(System.out);
            }
        }
    };
}
项目:Cubes    文件:AssetFinder.java   
private static InputStream getInputStream(URL jar) throws IOException {
  //to fix offset caused by launch4j
  InputStream is = jar.openStream();
  Log.debug("Scanning for jar...");
  long offset = 0;
  boolean found = false;
  try {
    while (true) {
      if (getUnsignedInt(is) == 0x04034b50L) {
        found = true;
        break;
      }
      offset += 4;
    }
  } catch (IOException ignored) {
  }
  is.close();

  InputStream finalIS = jar.openStream();
  if (!found) {
    Log.debug("Failed to find start");
  } else {
    Log.debug("Skipping " + offset + " bytes until start of jar [" + finalIS.skip(offset) + "]");
    if (finalIS.markSupported()) finalIS.mark(Integer.MAX_VALUE);
  }
  return finalIS;
}
项目:bubichain-sdk-java    文件:HttpKit.java   
/**
 *  鍙戦�丳ost璇锋眰
 * @param url
 * @param params
 * @return
 * @throws IOException 
 * @throws NoSuchProviderException 
 * @throws NoSuchAlgorithmException 
 * @throws KeyManagementException 
 */
public static String post(String url, String params,Boolean https) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException {
    StringBuffer bufferRes = null;
    TrustManager[] tm = { new MyX509TrustManager() };
    SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
    sslContext.init(null, tm, new java.security.SecureRandom());
    // 浠庝笂杩癝SLContext瀵硅薄涓緱鍒癝SLSocketFactory瀵硅薄  
    SSLSocketFactory ssf = sslContext.getSocketFactory();

    URL urlGet = new URL(url);
    HttpsURLConnection http = (HttpsURLConnection) urlGet.openConnection();
    // 杩炴帴瓒呮椂
    http.setConnectTimeout(50000);
    // 璇诲彇瓒呮椂 --鏈嶅姟鍣ㄥ搷搴旀瘮杈冩參锛屽澶ф椂闂�
    http.setReadTimeout(50000);
    http.setRequestMethod("POST");
    http.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
    http.setSSLSocketFactory(ssf);
    http.setHostnameVerifier(new Verifier());
    http.setDoOutput(true);
    http.setDoInput(true);
    http.connect();

    OutputStream out = http.getOutputStream();
    out.write(params.getBytes("UTF-8"));
    out.flush();
    out.close();

    InputStream in = http.getInputStream();
    BufferedReader read = new BufferedReader(new InputStreamReader(in, DEFAULT_CHARSET));
    String valueString = null;
    bufferRes = new StringBuffer();
    while ((valueString = read.readLine()) != null){
        bufferRes.append(valueString);
    }
    in.close();
    if (http != null) {
        // 鍏抽棴杩炴帴
        http.disconnect();
    }
    return bufferRes.toString();
}
项目:APITools    文件:SWTResourceManager.java   
/**
 * Returns an {@link Image} encoded by the specified {@link InputStream}.
 * 
 * @param stream
 *            the {@link InputStream} encoding the image data
 * @return the {@link Image} encoded by the specified input stream
 */
protected static Image getImage(InputStream stream) throws IOException {
    try {
        Display display = Display.getCurrent();
        ImageData data = new ImageData(stream);
        if (data.transparentPixel > 0) {
            return new Image(display, data, data.getTransparencyMask());
        }
        return new Image(display, data);
    } finally {
        stream.close();
    }
}
项目:openjdk-jdk10    文件:OpenWaveFile.java   
static void check(Object source) throws Exception {
     AudioFileFormat aff2 = null;
     if (source instanceof File) {
        aff2 = AudioSystem.getAudioFileFormat((File) source);
     }
     else if (source instanceof InputStream) {
        aff2 = AudioSystem.getAudioFileFormat((InputStream) source);
     }
     else if (source instanceof URL) {
        aff2 = AudioSystem.getAudioFileFormat((URL) source);
     } else throw new Exception("wrong source. Test FAILED");
     System.out.println("Got: "+aff2);
     if (aff2.getFormat().getSampleSizeInBits()==-1) {
        throw new Exception("wrong audio format. Test FAILED");
     }
}
项目:jdk8u-jdk    文件:ZipFileSystem.java   
private static void copyStream(InputStream is, OutputStream os)
    throws IOException
{
    byte[] copyBuf = new byte[8192];
    int n;
    while ((n = is.read(copyBuf)) != -1) {
        os.write(copyBuf, 0, n);
    }
}
项目:ramus    文件:AbstractEngine.java   
@Override
public Properties getProperties(String path) {
    InputStream is = getInputStream(path);
    Properties res = new Properties();
    if (is != null) {
        try {
            res.loadFromXML(is);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
    return res;
}
项目:CustomWorldGen    文件:TemplateManager.java   
/**
 * reads a template from an inputstream
 */
private void readTemplateFromStream(String id, InputStream stream) throws IOException
{
    NBTTagCompound nbttagcompound = CompressedStreamTools.readCompressed(stream);
    Template template = new Template();
    template.read(nbttagcompound);
    this.templates.put(id, template);
}
项目:junit-dataproviders    文件:ExcelParametersProvider.java   
private Object[] paramsFromFile() {
    try {
        InputStream inputStream = createProperReader();
        try {
            return map(inputStream);
        } finally {
            inputStream.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(
                "Could not successfully read parameters from file: " + filepath, e);
    }
}
项目:hadoop    文件:FSImageLoader.java   
private static byte[][] loadINodeSection(InputStream in)
        throws IOException {
  FsImageProto.INodeSection s = FsImageProto.INodeSection
      .parseDelimitedFrom(in);
  LOG.info("Loading " + s.getNumInodes() + " inodes.");
  final byte[][] inodes = new byte[(int) s.getNumInodes()][];

  for (int i = 0; i < s.getNumInodes(); ++i) {
    int size = CodedInputStream.readRawVarint32(in.read(), in);
    byte[] bytes = new byte[size];
    IOUtils.readFully(in, bytes, 0, size);
    inodes[i] = bytes;
  }
  LOG.debug("Sorting inodes");
  Arrays.sort(inodes, INODE_BYTES_COMPARATOR);
  LOG.debug("Finished sorting inodes");
  return inodes;
}
项目:ARCLib    文件:FileRepositoryTest.java   
@Test
public void deleteTest() throws IOException {
    String id;
    try (InputStream stream = resource("cz/inqool/uas/file/test.pdf")) {
        FileRef pdfFile = repository.create(stream, "test.pdf", "application/pdf", false);
        id = pdfFile.getId();
    }

    FileRef fileRef = repository.get(id);
    try (InputStream stream = resource("cz/inqool/uas/file/test.pdf"); InputStream stream2 = fileRef.getStream()) {
        IOUtils.contentEquals(stream, stream2);
    }

    repository.del(fileRef);

    assertThrown(() -> repository.get(id))
            .isInstanceOf(MissingObject.class);
}
项目:mintleaf    文件:SqlStreamReaderTest.java   
@Test
public void testSqlReaderReadTest() throws MintleafException {

    InputStream iStream = this.getClass().getResourceAsStream("/EmptyPackage.sql");
    SqlStreamReader reader = new SqlStreamReader(iStream);


    final StringBuilder actual = new StringBuilder();
    ReadListener listner = new EmptyPackageReadListner() {

        @Override
        public Object eachRow(int rowNum, Row row) throws MintleafException {
            actual.append(((ChangeSet) row).getChangeSetSource());
            return null;
        }


    };
    reader.setReadListener(listner);
    reader.read();

    StringBuilder expected = new StringBuilder();

    expected.append("create or replace package EmptyPackage\n");
    expected.append("as\n");
    expected.append("end EmptyPackage;");
    expected.append("create or replace\n");
    expected.append("package body EmptyPackage\n");
    expected.append("as\n");
    expected.append("end EmptyPackage;");

    assertEquals(expected.toString(), actual.toString());
}
项目:OpenJSharp    文件:MicToken_v2.java   
public void verify(InputStream data) throws GSSException {
    byte[] dataBytes = null;
    try {
        dataBytes = new byte[data.available()];
        data.read(dataBytes);
    } catch (IOException e) {
        // Error reading application data
        throw new GSSException(GSSException.BAD_MIC, -1,
            "Corrupt checksum or sequence number in MIC token");
    }
    verify(dataBytes, 0, dataBytes.length);
}
项目:oscm-app    文件:ApplicationBean.java   
/**
 * Read the build id and date from the ear manifest.
 */
private void initBuildIdAndDate() {
    if (buildId != null) {
        return;
    }
    buildId = "-1";
    buildDate = "";

    // read the implementation version property from the war manifest
    final InputStream in = FacesContext.getCurrentInstance()
            .getExternalContext()
            .getResourceAsStream("/META-INF/MANIFEST.MF");
    String str = null;
    if (in != null) {
        final Properties prop = PropertiesLoader.loadProperties(in);
        str = prop.getProperty("Implementation-Version");
    }

    if (str == null) {
        return;
    }

    // parse the implementation version
    final int sep = str.lastIndexOf("-");
    buildId = str.substring(0, sep);

    SimpleDateFormat inFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    SimpleDateFormat outFormat = new SimpleDateFormat("yyyy/MM/dd");
    try {
        buildDate = outFormat
                .format(inFormat.parse(str.substring(sep + 1)));
    } catch (ParseException e) {
        logger.error(e.getMessage());
    }

}
项目:testcontainers-java-module-elasticsearch    文件:ElasticsearchResource.java   
public ElasticsearchResource(String resourceName) {
    // Find the latest version this project was built with
    String propVersion;
    String propBaseUrl;
    String defaultBaseUrl = null;
    String defaultVersion = null;
    Properties props = new Properties();
    try {
        props.load(ElasticsearchResource.class.getResourceAsStream(FALLBACK_RESOURCE_NAME));
        defaultBaseUrl = props.getProperty("baseUrl");
        defaultVersion = props.getProperty("version");
    } catch (IOException ignored) {
        // This can normally never happen unless someone modifies the JAR file o_O
    }
    try {
        InputStream stream = ElasticsearchResource.class.getResourceAsStream(resourceName);
        if (stream != null) {
            props.load(stream);
            propBaseUrl = props.getProperty("baseUrl", defaultBaseUrl);
            propVersion = props.getProperty("version", defaultVersion);
        } else {
            propBaseUrl = defaultBaseUrl;
            propVersion = defaultVersion;
        }
    } catch (IOException e) {
        // We might get that exception if the user provides a badly formatted property file
        propBaseUrl = null;
        propVersion = null;
    }
    baseUrl = propBaseUrl;
    version = propVersion;
}
项目:nifi-nars    文件:PutScp.java   
@Override
public void onTrigger(final ProcessContext context, final ProcessSession processSession) {
    List<FlowFile> flowFiles = processSession.get(batchSize);
    if (flowFiles.isEmpty()) {
        return;
    }

    Session jschSession = null;
    Channel channel = null;
    try {
        jschSession = openSession(context);
        final String remotePath = context.getProperty(REMOTE_PATH).evaluateAttributeExpressions().getValue();
        channel = openExecChannel(context, jschSession, "scp -r -d -t " + remotePath);

        InputStream channelIn = channel.getInputStream();
        OutputStream channelOut = channel.getOutputStream();

        channel.connect();
        waitForAck(channelIn);

        ListIterator<FlowFile> fileIt = flowFiles.listIterator();
        while (fileIt.hasNext()) {
            final FlowFile flowFile = fileIt.next();

            // conditionally reject files that are zero bytes or less
            if (context.getProperty(REJECT_ZERO_BYTE).asBoolean() && flowFile.getSize() == 0) {
                logger.warn("Rejecting {} because it is zero bytes", new Object[]{flowFile});
                processSession.transfer(processSession.penalize(flowFile), REL_REJECT);
                fileIt.remove();
                continue;
            }

            final String filename = flowFile.getAttribute(CoreAttributes.FILENAME.key());
            final String permissions = context.getProperty(PERMISSIONS).evaluateAttributeExpressions(flowFile).getValue();

            // destination path + filename
            // final String fullPath = buildFullPath(context, flowFile, filename);

            processSession.read(flowFile, new InputStreamCallback() {
                @Override
                public void process(final InputStream flowFileIn) throws IOException {
                    // send "C0644 filesize filename", where filename should not include '/'
                    StringBuilder command = new StringBuilder("C").append(permissions).append(' ');
                    command.append(flowFile.getSize()).append(' ');
                    command.append(filename).append('\n');

                    channelOut.write(command.toString().getBytes(StandardCharsets.UTF_8));
                    channelOut.flush();
                    waitForAck(channelIn);

                    IOUtils.copy(flowFileIn, channelOut);
                    channelOut.flush();
                    sendAck(channelOut);
                    waitForAck(channelIn);
                }
            });

            processSession.transfer(flowFile, REL_SUCCESS);
            processSession.getProvenanceReporter().send(flowFile, remotePath);
            fileIt.remove();
            if (logger.isDebugEnabled()) {
                logger.debug("Sent {} to remote host", new Object[]{flowFile});
            }
        }

    } catch (JSchException | IOException ex) {
        context.yield();
        logger.error("Unable to create session to remote host due to {}", new Object[]{ex}, ex);
        processSession.transfer(flowFiles, REL_FAILURE);

    } finally {
        if (channel != null) {
            channel.disconnect();
        }
        if (jschSession != null) {
            jschSession.disconnect();
        }
    }
}
项目:tomcat7    文件:TestChunkedInputFilter.java   
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    resp.setContentType("text/plain");
    PrintWriter pw = resp.getWriter();
    // Headers not visible yet, body not processed
    dumpHeader("x-trailer1", req, pw);
    dumpHeader("x-trailer2", req, pw);

    // Read the body - quick and dirty
    InputStream is = req.getInputStream();
    int count = 0;
    try {
        while (is.read() > -1) {
            count++;
        }
    } catch (IOException ioe) {
        exceptionDuringRead = true;
        if (!expectPass) { // as expected
            log(ioe.toString());
            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }
        throw ioe;
    }

    pw.write(Integer.valueOf(count).toString());

    // Headers should be visible now
    dumpHeader("x-trailer1", req, pw);
    dumpHeader("x-trailer2", req, pw);
}
项目:geomapapp    文件:TableDB.java   
void read( String urlString ) throws IOException {
    URL url = URLFactory.url(urlString);
    InputStream input = urlString.endsWith(".gz")
        ? new GZIPInputStream( url.openStream() )
        : url.openStream();

    BufferedReader in = new BufferedReader(
        new InputStreamReader( input));
    read( in );
}
项目:dooo    文件:EsClientManager.java   
/**
 * 初始化索引
 *
 * @throws Exception
 */
private static void initIndex() throws Exception {
    String indice = esprop.getIndice();
    IndicesAdminClient c = client.admin().indices();
    //创建一个空的
    boolean a = c.prepareExists(indice).get().isExists();
    LOGGER.info("index {} isExists  {}",indice, a);
    if (!c.prepareExists(indice).get().isExists()) {
        CreateIndexResponse createIndexResponse =c.prepareCreate(indice).get();
        LOGGER.info("create index {}", createIndexResponse);
    }
    for (IndexType type : IndexType.values()) {
        TypesExistsResponse typesExistsResponse = c.typesExists(new TypesExistsRequest(new String[]{indice}, type.getDataName())).get();
        if (typesExistsResponse.isExists()) {
            continue;
        }
        String esMapper = type.getMapper();
        InputStream in = EsClientManager.class.getResourceAsStream(esMapper);
        String mappingStr = IOUtils.toString(in).trim();
        IOUtils.closeQuietly(in);
        c.preparePutMapping(indice).setType(type.getDataName()).setSource(mappingStr).get();
    }
}
项目:Cable-Android    文件:PersistentBlobProvider.java   
private Uri create(@NonNull  MasterSecret masterSecret,
                   @NonNull  InputStream input,
                             long id,
                   @NonNull  String mimeType,
                   @Nullable String fileName,
                   @Nullable Long fileSize)
{
  persistToDisk(masterSecret, id, input);
  final Uri uniqueUri = CONTENT_URI.buildUpon()
                                   .appendPath(mimeType)
                                   .appendPath(getEncryptedFileName(masterSecret, fileName))
                                   .appendEncodedPath(String.valueOf(fileSize))
                                   .appendEncodedPath(String.valueOf(System.currentTimeMillis()))
                                   .build();
  return ContentUris.withAppendedId(uniqueUri, id);
}
项目:rlc-analyser    文件:RlcAnalyser.java   
/**
 * This method takes a potential RLC file and unpacks it as a ZIP file. Then
 * filters through the entries in the ZIP file to find the XML file for
 * processing. XML is then parsed through XStream and stored in an engine
 * for data collection.
 *
 * @param file
 *            - file for processing
 * @throws FileNotFoundException
 * @throws IOException
 */
private void analyseRlc(final File file) throws FileNotFoundException, IOException, RuntimeException {
    final InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
    final ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(inputStream);
    ZipArchiveEntry entry;
    try {
        while ((entry = zipInputStream.getNextZipEntry()) != null) {
            // Find the XML configuration file and ignore the rest
            if (!entry.isDirectory()) {
                final String entryName = entry.getName().trim().toLowerCase();
                final int directoryIndex = entryName.indexOf('/');

                if (entryName.length() > 4 && entryName.endsWith(".xml") && directoryIndex <= 0) {
                    if (!zipInputStream.canReadEntryData(entry)) {
                        throw new RuntimeException("RLC file could not be processed.");
                    }
                    logger.info("[PROCESSING] : " + entryName);

                    final Engine engine = parser.parse(zipInputStream);

                    if (engine == null) {
                        // Null returned do not add to engine list
                        logger.error("[ERROR] : Could not process " + entryName);
                    } else {
                        this.fileCounter++; // increment file count.
                        // file count used as a way to name files and distinguish RLC's with same names.
                        // Name of a file: FileCoutner + ":" + <FileName>. n is the file count.
                        engine.setFileName(this.fileCounter + ":" + file.getName());
                        this.engineList.add(engine);
                        this.dataCollector.collectData(engine);
                    }
                }
            }
        }
    } finally {
        zipInputStream.close();
    }
}
项目:RootPGPExplorer    文件:MyPGPUtil.java   
/**
 * A simple routine that opens a key ring file and loads the first available key
 * suitable for signature generation.
 *
 * @param input stream to read the secret key ring collection from.
 * @return a secret key.
 * @throws IOException on a problem with using the input stream.
 * @throws PGPException if there is an issue parsing the input stream.
 */
public static PGPSecretKey readSecretKey(InputStream input) throws IOException, PGPException
{
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
            PGPUtil.getDecoderStream(input), new JcaKeyFingerprintCalculator());

    //
    // we just loop through the collection till we find a key suitable for encryption, in the real
    // world you would probably want to be a bit smarter about this.
    //

    Iterator keyRingIter = pgpSec.getKeyRings();
    while (keyRingIter.hasNext())
    {
        PGPSecretKeyRing keyRing = (PGPSecretKeyRing)keyRingIter.next();

        Iterator keyIter = keyRing.getSecretKeys();
        while (keyIter.hasNext())
        {
            PGPSecretKey key = (PGPSecretKey)keyIter.next();

            if (key.isSigningKey())
            {
                return key;
            }
        }
    }

    throw new IllegalArgumentException("Can't find signing key in key ring.");
}
项目:incubator-netbeans    文件:Env.java   
/** Creates a new instance of Env */
Env(CommandLine cmd, InputStream is, OutputStream os, OutputStream err, File currentDir) {
    this.is = is;
    this.os = os instanceof PrintStream ? (PrintStream)os : new PrintStream(os);
    this.err = err instanceof PrintStream ? (PrintStream)err : new PrintStream(err);
    this.currentDir = currentDir;
    this.cmd = cmd;
}
项目:hadoop-oss    文件:FsUrlConnection.java   
@Override
public InputStream getInputStream() throws IOException {
  if (is == null) {
    connect();
  }
  return is;
}
项目:Blockly    文件:BlocklyXmlHelper.java   
/**
 * Convenience function that creates a new {@link ArrayList}.
 * @param inputXml The input stream of XML from which to read.
 * @throws BlockLoadingException If any error occurs with the input. It may wrap an IOException
 *                               or XmlPullParserException as a root cause.
 */
public static List<Block> loadFromXml(InputStream inputXml, BlockFactory blockFactory)
        throws BlockLoadingException {
    List<Block> result = new ArrayList<>();
    loadBlocksFromXml(inputXml, null, blockFactory, result);
    return result;
}
项目:Towan    文件:CompositeImageData.java   
/**
 * @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream, boolean, boolean, int[])
 */
public ByteBuffer loadImage(InputStream is, boolean flipped, boolean forceAlpha, int[] transparent) throws IOException {
    CompositeIOException exception = new CompositeIOException();
    ByteBuffer buffer = null;

    BufferedInputStream in = new BufferedInputStream(is, is.available());
    in.mark(is.available());

    // cycle through our source until one of them works
    for (int i=0;i<sources.size();i++) {
        in.reset();
        try {
            LoadableImageData data = (LoadableImageData) sources.get(i);

            buffer = data.loadImage(in, flipped, forceAlpha, transparent);
            picked = data;
            break;
        } catch (Exception e) {
            Log.warn(sources.get(i).getClass()+" failed to read the data", e);
            exception.addException(e);
        }
    }

    if (picked == null) {
        throw exception;
    }

    return buffer;
}
项目:GitHub    文件:Issue1462.java   
public ExtClassLoader() throws IOException {
    super(Thread.currentThread().getContextClassLoader());

    {
        byte[] bytes;
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("kotlin/ObjectA.clazz");
        bytes = IOUtils.toByteArray(is);
        is.close();

        super.defineClass("ObjectA", bytes, 0, bytes.length);
    }
}
项目:cyberduck    文件:SFTPWriteFeatureTest.java   
@Test
public void testWrite() throws Exception {
    final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", new Credentials(
            System.getProperties().getProperty("sftp.user"), System.getProperties().getProperty("sftp.password")
    ));
    final SFTPSession session = new SFTPSession(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final TransferStatus status = new TransferStatus();
    final int length = 1048576;
    final byte[] content = RandomUtils.nextBytes(length);
    status.setLength(content.length);
    final Path home = new SFTPHomeDirectoryService(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final CryptoWriteFeature<Void> writer = new CryptoWriteFeature<>(session, new SFTPWriteFeature(session), cryptomator);
    final Cryptor cryptor = cryptomator.getCryptor();
    final FileHeader header = cryptor.fileHeaderCryptor().create();
    status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header));
    status.setNonces(new RandomNonceGenerator());
    status.setChecksum(writer.checksum(test).compute(new ByteArrayInputStream(content), status));
    final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    out.close();
    assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(test));
    Assert.assertEquals(content.length, new CryptoListService(session, session, cryptomator).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize());
    Assert.assertEquals(content.length, writer.append(test, status.getLength(), PathCache.empty()).size, 0L);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final InputStream in = new CryptoReadFeature(session, new SFTPReadFeature(session), cryptomator).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    new StreamCopier(status, status).transfer(in, buffer);
    assertArrayEquals(content, buffer.toByteArray());
    new CryptoDeleteFeature(session, new SFTPDeleteFeature(session), cryptomator).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
项目:dota    文件:HttpUtils.java   
private static void closeStream(InputStream is, FileOutputStream fos) {
    try {
        if (is != null) is.close();
        if (fos != null) fos.close();
    } catch (IOException e) {
        logger.error(ExceptionUtils.getTraceInfo(e));
    }
}
项目:ditb    文件:AddColumnFamilyProcedure.java   
@Override
public void deserializeStateData(final InputStream stream) throws IOException {
  super.deserializeStateData(stream);

  MasterProcedureProtos.AddColumnFamilyStateData addCFMsg =
      MasterProcedureProtos.AddColumnFamilyStateData.parseDelimitedFrom(stream);
  user = MasterProcedureUtil.toUserInfo(addCFMsg.getUserInfo());
  tableName = ProtobufUtil.toTableName(addCFMsg.getTableName());
  cfDescriptor = HColumnDescriptor.convert(addCFMsg.getColumnfamilySchema());
  if (addCFMsg.hasUnmodifiedTableSchema()) {
    unmodifiedHTableDescriptor = HTableDescriptor.convert(addCFMsg.getUnmodifiedTableSchema());
  }
}
项目:nifi-registry    文件:TestFileSystemFlowPersistenceProvider.java   
private void verifySnapshot(final File flowStorageDir, final String bucketId, final String flowId, final int version,
                            final String contentString) throws IOException {
    // verify the correct snapshot file was created
    final File flowSnapshotFile = new File(flowStorageDir,
            bucketId + "/" + flowId + "/" + version + "/" + version + FileSystemFlowPersistenceProvider.SNAPSHOT_EXTENSION);
    Assert.assertTrue(flowSnapshotFile.exists());

    try (InputStream in = new FileInputStream(flowSnapshotFile)) {
        Assert.assertEquals(contentString, IOUtils.toString(in, StandardCharsets.UTF_8));
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:WARDirContext.java   
/**
 * Content accessor.
 * 
 * @return InputStream
 */
@Override
public InputStream streamContent()
    throws IOException {
    try {
        if (binaryContent == null) {
            InputStream is = base.getInputStream(entry);
            inputStream = is;
            return is;
        }
    } catch (ZipException e) {
        throw new IOException(e.getMessage(), e);
    }
    return super.streamContent();
}
项目:fuck_zookeeper    文件:IOUtils.java   
/**
 * Copies from one stream to another.
 * 
 * @param in
 *            InputStrem to read from
 * @param out
 *            OutputStream to write to
 * @param buffSize
 *            the size of the buffer
 */
public static void copyBytes(InputStream in, OutputStream out, int buffSize)
        throws IOException {
    PrintStream ps = out instanceof PrintStream ? (PrintStream) out : null;
    byte buf[] = new byte[buffSize];
    int bytesRead = in.read(buf);
    while (bytesRead >= 0) {
        out.write(buf, 0, bytesRead);
        if ((ps != null) && ps.checkError()) {
            throw new IOException("Unable to write to output stream.");
        }
        bytesRead = in.read(buf);
    }
}