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


Java IOUtils.read方法代码示例

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


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

示例1: populateCertificateRevocationListAttribute

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
 * Populate certificate revocation list attribute.
 * Dynamically set the attribute value to the crl content.
 * Encode it as base64 first. Doing this in the code rather
 * than in the ldif file to ensure the attribute can be populated
 * without dependencies on the classpath and or filesystem.
 * @throws Exception the exception
 */
private static void populateCertificateRevocationListAttribute() throws Exception {
    final Collection<LdapEntry> col = getDirectory().getLdapEntries();
    for (final LdapEntry ldapEntry : col) {
        if (ldapEntry.getDn().equals(DN)) {
            final LdapAttribute attr = new LdapAttribute(true);

            byte[] value = new byte[1024];
            IOUtils.read(new ClassPathResource("userCA-valid.crl").getInputStream(), value);
            value = EncodingUtils.encodeBase64ToByteArray(value);
            attr.setName("certificateRevocationList");
            attr.addBinaryValue(value);
            LdapTestUtils.modifyLdapEntry(getDirectory().getConnection(), ldapEntry, attr);

        }
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:25,代码来源:AbstractX509LdapTests.java

示例2: readNextChunk

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private int readNextChunk() throws IOException {
    final ByteBuffer ciphertextBuf = ByteBuffer.allocate(chunkSize);
    final int read = IOUtils.read(proxy, ciphertextBuf.array());
    if(read == 0) {
        return IOUtils.EOF;
    }
    ciphertextBuf.position(read);
    ciphertextBuf.flip();
    try {
        buffer = cryptor.fileContentCryptor().decryptChunk(ciphertextBuf, chunkIndexOffset++, header, true);
    }
    catch(CryptoException e) {
        throw new IOException(e.getMessage(), new CryptoAuthenticationException(e.getMessage(), e));
    }
    return read;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:17,代码来源:CryptoInputStream.java

示例3: bootstrap

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public static void bootstrap() throws Exception {
    initDirectoryServer();
    getDirectory().populateEntries(new ClassPathResource("ldif/users-x509.ldif").getInputStream());

    /**
     * Dynamically set the attribute value to the crl content.
     * Encode it as base64 first. Doing this in the code rather
     * than in the ldif file to ensure the attribute can be populated
     * without dependencies on the classpath and or filesystem.
     */
    final Collection<LdapEntry> col = getDirectory().getLdapEntries();
    for (final LdapEntry ldapEntry : col) {
        if (ldapEntry.getDn().equals(DN)) {
            final LdapAttribute attr = new LdapAttribute(true);

            byte[] value = new byte[1024];
            IOUtils.read(new ClassPathResource("userCA-valid.crl").getInputStream(), value);
            value = CompressionUtils.encodeBase64ToByteArray(value);
            attr.setName("certificateRevocationList");
            attr.addBinaryValue(value);

            final LDAPConnection serverCon = getDirectory().getConnection();
            final String address = "ldap://" + serverCon.getConnectedAddress() + ':' + serverCon.getConnectedPort();
            final Connection conn = DefaultConnectionFactory.getConnection(address);
            conn.open();
            final ModifyOperation modify = new ModifyOperation(conn);
            modify.execute(new ModifyRequest(ldapEntry.getDn(),
                    new AttributeModification(AttributeModificationType.ADD, attr)));
            conn.close();
            serverCon.close();
            return;
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:35,代码来源:AbstractX509LdapTests.java

示例4: bootstrap

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public static void bootstrap() throws Exception {
    initDirectoryServer();
    getDirectory().populateEntries(new ClassPathResource("ldif/users-x509.ldif").getInputStream());

    /**
     * Dynamically set the attribute value to the crl content.
     * Encode it as base64 first. Doing this in the code rather
     * than in the ldif file to ensure the attribute can be populated
     * without dependencies on the classpath and or filesystem.
     */
    final Collection<LdapEntry> col = getDirectory().getLdapEntries();
    for (final LdapEntry ldapEntry : col) {
        if (ldapEntry.getDn().equals(DN)) {
            final LdapAttribute attr = new LdapAttribute(true);

            byte[] value = new byte[1024];
            IOUtils.read(new ClassPathResource("userCA-valid.crl").getInputStream(), value);
            value = CompressionUtils.encodeBase64ToByteArray(value);
            attr.setName("certificateRevocationList");
            attr.addBinaryValue(value);

            final LDAPConnection serverCon = getDirectory().getConnection();
            final String address = "ldap://" + serverCon.getConnectedAddress() + ":" + serverCon.getConnectedPort();
            final Connection conn = DefaultConnectionFactory.getConnection(address);
            conn.open();
            final ModifyOperation modify = new ModifyOperation(conn);
            modify.execute(new ModifyRequest(ldapEntry.getDn(),
                    new AttributeModification(AttributeModificationType.ADD, attr)));
            conn.close();
            serverCon.close();
            return;
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:35,代码来源:AbstractX509LdapTests.java

示例5: doesResourceExist

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
/**
 * Does resource exist?
 *
 * @param res the res
 * @return the boolean
 */
public static boolean doesResourceExist(final Resource res) {
    if (res != null) {
        try {
            IOUtils.read(res.getInputStream(), new byte[1]);
            return true;
        } catch (final Exception e) {
            LOGGER.trace(e.getMessage(), e);
            return false;
        }
    }
    return false;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:ResourceUtils.java

示例6: consumeAsTar

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public static String consumeAsTar ( InputStream dockerTarStream, int chunkSize, int maxSize )
		throws Exception {

	StringWriter logwriter = new StringWriter();

	try (TarArchiveInputStream tarInputStream = new TarArchiveInputStream( dockerTarStream )) {
		TarArchiveEntry tarEntry = tarInputStream.getNextTarEntry();

		logger.info( "tar name: {}", tarEntry.getName() );
		byte[] bufferAsByteArray = new byte[ chunkSize ];

		long tarEntrySize = tarEntry.getSize();

		int numReadIn = 0;
		while (tarInputStream.available() > 0 && numReadIn < maxSize && numReadIn <= tarEntrySize) {
			int numRead = IOUtils.read( tarInputStream, bufferAsByteArray );

			numReadIn += numRead;

			String stringReadIn = new String( bufferAsByteArray, 0, numRead );
			logwriter.write( stringReadIn );
			logger.debug( "numRead: {}, chunk: {}", numRead, stringReadIn );
		}
		while (IOUtils.read( dockerTarStream, bufferAsByteArray ) > 0) {
			// need to read fully or stream will leak
		}
		// response.close();

	}
	return logwriter.toString();
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:32,代码来源:Docker_Java.java

示例7: consumeChunksAsString

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public static String consumeChunksAsString ( InputStream response, int maxChars, int chunkSize ) {

		StringWriter logwriter = new StringWriter();

		byte[] bufferAsByteArray = new byte[ chunkSize ];
		try {
			int numReadIn = 0;
			while (response.available() > 0 && numReadIn < maxChars) {
				int numRead = IOUtils.read( response, bufferAsByteArray );

				numReadIn += numRead;

				String stringReadIn = new String( bufferAsByteArray, 0, numRead );
				logwriter.write( stringReadIn );
				logger.debug( "numRead: {}, chunk: {}", numRead, stringReadIn );
				// LOG.info("line: " + line);
			}
			while (IOUtils.read( response, bufferAsByteArray ) > 0)
				;
			;
			// response.close();

		} catch (Exception e) {
			logger.error( "Failed to close: {}",
				CSAP.getCsapFilteredStackTrace( e ) );
			return "Failed";
		} finally {
			IOUtils.closeQuietly( response );
		}
		return logwriter.toString();
	}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:32,代码来源:Docker_Java.java

示例8: loadClock

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private void loadClock(long[] clockData, InputStream is) throws IOException {
    byte[] byteBuff = new byte[4 * clockData.length];
    IOUtils.read(is, byteBuff);
    ByteBuffer buff = ByteBuffer.wrap(byteBuff);
    buff.order(ByteOrder.LITTLE_ENDIAN);
    int i = 0;
    while (buff.hasRemaining()) {
        clockData[i++] = buff.getInt() & 0xffffffff;
    }
}
 
开发者ID:trekawek,项目名称:coffee-gb,代码行数:11,代码来源:FileBattery.java

示例9: loadRam

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private void loadRam(int[] ram, InputStream is, long length) throws IOException {
    byte[] buffer = new byte[ram.length];
    IOUtils.read(is, buffer, 0, Math.min((int) length, ram.length));
    for (int i = 0; i < ram.length; i++) {
        ram[i] = buffer[i] & 0xff;
    }
}
 
开发者ID:trekawek,项目名称:coffee-gb,代码行数:8,代码来源:FileBattery.java

示例10: readNextChunk

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
private int readNextChunk() throws IOException {
    final ByteBuffer ciphertextBuf = ByteBuffer.allocate(SDSSession.DEFAULT_CHUNKSIZE);
    final int read = IOUtils.read(proxy, ciphertextBuf.array());
    if(lastread == 0) {
        return IOUtils.EOF;
    }
    ciphertextBuf.position(read);
    ciphertextBuf.flip();
    try {
        final PlainDataContainer pDataContainer;
        if(read == 0) {
            final PlainDataContainer c1 = cipher.processBytes(createEncryptedDataContainer(ciphertextBuf.array(), read, null));
            final PlainDataContainer c2 = cipher.doFinal(new EncryptedDataContainer(null, tag));
            pDataContainer = new PlainDataContainer(ArrayUtils.addAll(c1.getContent(), c2.getContent()));
        }
        else {
            pDataContainer = cipher.processBytes(createEncryptedDataContainer(ciphertextBuf.array(), read, null));
        }
        final byte[] content = pDataContainer.getContent();
        buffer = ByteBuffer.allocate(content.length);
        buffer.put(content);
        buffer.flip();
        lastread = read;
        return content.length;
    }
    catch(CryptoException e) {
        throw new IOException(e);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:30,代码来源:CryptoInputStream.java

示例11: writeContainerFileToHttpResponse

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public void writeContainerFileToHttpResponse (	boolean isBinary,
												String name, String path,
												HttpServletResponse servletResponse,
												long maxEditSize, int chunkSize ) {

	logger.info( "Container: {}, path: {}, maxEditSize: {}", name, path, maxEditSize );
	Optional<Container> matchContainer = findContainerByName( name );

	if ( path.length() == 0 ) {
		containerTailStream( null, name, servletResponse, -1 );
		return;
	}
	byte[] bufferAsByteArray = new byte[ chunkSize ];
	try (
			InputStream dockerTarStream = dockerClient.copyArchiveFromContainerCmd( matchContainer.get().getId(), path ).exec();
			ServletOutputStream servletOutputStream = servletResponse.getOutputStream();) {
		int numReadIn = 0;
		try (TarArchiveInputStream tarInputStream = new TarArchiveInputStream( dockerTarStream )) {

			TarArchiveEntry tarEntry = tarInputStream.getNextTarEntry();
			long tarEntrySize = tarEntry.getSize();
			if ( isBinary ) {
				servletResponse.setContentLength( Math.toIntExact( tarEntrySize ) );
			}
			logger.info( "tar entry name: {}", tarEntry.getName() );

			if ( tarEntrySize > maxEditSize ) {
				servletOutputStream.println(
					"**** Warning: output truncated as max size reached: " + maxEditSize / 1024 +
							"Kb. \n\tView or download can be used to access entire file.\n=====================================" );
			}

			while (tarInputStream.available() > 0 && numReadIn < maxEditSize && numReadIn < tarEntrySize) {
				int numBytesRead = IOUtils.read( tarInputStream, bufferAsByteArray );
				numReadIn += numBytesRead;
				// String stringReadIn = new String( bufferAsByteArray,
				// 0,
				// numBytesRead );
				servletOutputStream.write( bufferAsByteArray, 0, numBytesRead );
				servletOutputStream.flush();
				// logger.debug( "numRead: {}, chunk: {}", numBytesRead,
				// stringReadIn );
			}

			while (IOUtils.read( dockerTarStream, bufferAsByteArray ) > 0) {
				// need to read fully or stream will leak
			}
			// response.close();

		}

		// response.close();

	} catch (Exception e) {
		logger.error( "Failed to close: {}",
			CSAP.getCsapFilteredStackTrace( e ) );

	}

}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:61,代码来源:DockerHelper.java

示例12: writeContainerFileToString

import org.apache.commons.io.IOUtils; //导入方法依赖的package包/类
public StringBuilder writeContainerFileToString (	String name, String path,
													long maxEditSize, int chunkSize ) {

	logger.info( "Container: {}, path: {}, maxEditSize: {}", name, path, maxEditSize );

	StringBuilder fileContents = new StringBuilder( "*WARNING: Docker Save to container not implemented yet\n" );
	Optional<Container> matchContainer = findContainerByName( name );

	byte[] bufferAsByteArray = new byte[ chunkSize ];
	try (
			InputStream dockerTarStream = dockerClient.copyArchiveFromContainerCmd( matchContainer.get().getId(), path ).exec();) {
		int numReadIn = 0;
		try (TarArchiveInputStream tarInputStream = new TarArchiveInputStream( dockerTarStream )) {

			TarArchiveEntry tarEntry = tarInputStream.getNextTarEntry();
			long tarEntrySize = tarEntry.getSize();

			logger.info( "tar entry name: {}", tarEntry.getName() );

			if ( tarEntrySize > maxEditSize ) {
				fileContents.append(
					"**** Warning: output truncated as max size reached: " + maxEditSize / 1024 +
							"Kb. \n\tView or download can be used to access entire file.\n=====================================" );
			}

			while (tarInputStream.available() > 0 && numReadIn < maxEditSize && numReadIn < tarEntrySize) {
				int numBytesRead = IOUtils.read( tarInputStream, bufferAsByteArray );
				numReadIn += numBytesRead;
				String stringReadIn = new String( bufferAsByteArray, 0, numBytesRead );
				fileContents.append( stringReadIn );
				// logger.debug( "numRead: {}, chunk: {}", numBytesRead,
				// stringReadIn );
			}

			while (IOUtils.read( dockerTarStream, bufferAsByteArray ) > 0) {
				// need to read fully or stream will leak
			}
			// response.close();

		}

		// response.close();

	} catch (Exception e) {
		logger.error( "Failed to close: {}",
			CSAP.getCsapFilteredStackTrace( e ) );

	}

	return fileContents;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:52,代码来源:DockerHelper.java


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