本文整理匯總了Java中com.google.common.io.ByteSource類的典型用法代碼示例。如果您正苦於以下問題:Java ByteSource類的具體用法?Java ByteSource怎麽用?Java ByteSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ByteSource類屬於com.google.common.io包,在下文中一共展示了ByteSource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: encodeTicket
import com.google.common.io.ByteSource; //導入依賴的package包/類
/**
* Encode ticket.
*
* @param ticket the ticket
* @return the ticket
*/
protected Ticket encodeTicket(final Ticket ticket) {
if (this.cipherExecutor == null) {
logger.trace("Ticket encryption is not enabled. Falling back to default behavior");
return ticket;
}
if (ticket == null) {
return ticket;
}
logger.info("Encoding [{}]", ticket);
final byte[] encodedTicketObject = CompressionUtils.serializeAndEncodeObject(
this.cipherExecutor, ticket);
final String encodedTicketId = encodeTicketId(ticket.getId());
final Ticket encodedTicket = new EncodedTicket(
ByteSource.wrap(encodedTicketObject), encodedTicketId);
logger.info("Created [{}]", encodedTicket);
return encodedTicket;
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:26,代碼來源:AbstractCrypticTicketRegistry.java
示例2: getGraphics
import com.google.common.io.ByteSource; //導入依賴的package包/類
@Override
public ByteSource getGraphics(final String username) {
try {
final GraphicalUserAuthenticationProperties gua = casProperties.getAuthn().getGua();
final Response<SearchResult> response = searchForId(username);
if (LdapUtils.containsResultEntry(response)) {
final LdapEntry entry = response.getResult().getEntry();
final LdapAttribute attribute = entry.getAttribute(gua.getLdap().getImageAttribute());
if (attribute != null && attribute.isBinary()) {
return ByteSource.wrap(attribute.getBinaryValue());
}
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return ByteSource.empty();
}
示例3: encodeTicket
import com.google.common.io.ByteSource; //導入依賴的package包/類
/**
* Encode ticket.
*
* @param ticket the ticket
* @return the ticket
*/
protected Ticket encodeTicket(final Ticket ticket) {
if (!isCipherExecutorEnabled()) {
LOGGER.trace(MESSAGE);
return ticket;
}
if (ticket == null) {
LOGGER.debug("Ticket passed is null and cannot be encoded");
return null;
}
LOGGER.debug("Encoding ticket [{}]", ticket);
final byte[] encodedTicketObject = SerializationUtils.serializeAndEncodeObject(this.cipherExecutor, ticket);
final String encodedTicketId = encodeTicketId(ticket.getId());
final Ticket encodedTicket = new EncodedTicket(ByteSource.wrap(encodedTicketObject), encodedTicketId);
LOGGER.debug("Created encoded ticket [{}]", encodedTicket);
return encodedTicket;
}
示例4: testGet_io
import com.google.common.io.ByteSource; //導入依賴的package包/類
public void testGet_io() throws IOException {
assertEquals(-1, ArbitraryInstances.get(InputStream.class).read());
assertEquals(-1, ArbitraryInstances.get(ByteArrayInputStream.class).read());
assertEquals(-1, ArbitraryInstances.get(Readable.class).read(CharBuffer.allocate(1)));
assertEquals(-1, ArbitraryInstances.get(Reader.class).read());
assertEquals(-1, ArbitraryInstances.get(StringReader.class).read());
assertEquals(0, ArbitraryInstances.get(Buffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(CharBuffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(ByteBuffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(ShortBuffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(IntBuffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(LongBuffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(FloatBuffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(DoubleBuffer.class).capacity());
ArbitraryInstances.get(PrintStream.class).println("test");
ArbitraryInstances.get(PrintWriter.class).println("test");
assertNotNull(ArbitraryInstances.get(File.class));
assertFreshInstanceReturned(
ByteArrayOutputStream.class, OutputStream.class,
Writer.class, StringWriter.class,
PrintStream.class, PrintWriter.class);
assertEquals(ByteSource.empty(), ArbitraryInstances.get(ByteSource.class));
assertEquals(CharSource.empty(), ArbitraryInstances.get(CharSource.class));
assertNotNull(ArbitraryInstances.get(ByteSink.class));
assertNotNull(ArbitraryInstances.get(CharSink.class));
}
示例5: saveFiles
import com.google.common.io.ByteSource; //導入依賴的package包/類
protected void saveFiles(final ItemId itemId, File filesDir) throws IOException
{
ObjectNode files = itemRequests.listFiles(itemId);
ArrayNode fileList = files.withArray("files");
if( fileList.size() > 0 )
{
filesDir.mkdirs();
for( JsonNode file : fileList )
{
final String name = file.get("name").asText();
ByteSource src = new ByteSource()
{
@Override
public InputStream openStream() throws IOException
{
return itemRequests.file(itemRequests.successfulRequest(), itemId, name).body().asInputStream();
}
};
File destFile = new File(filesDir, name);
destFile.getParentFile().mkdirs();
src.copyTo(Files.asByteSink(destFile));
}
}
}
示例6: getSnapshotManager
import com.google.common.io.ByteSource; //導入依賴的package包/類
@Override
public SnapshotManager getSnapshotManager() {
SnapshotManager snapshotManager = super.getSnapshotManager();
snapshotManager.setCreateSnapshotConsumer(createSnapshotProcedure);
snapshotManager.setSnapshotCohort(new RaftActorSnapshotCohort() {
@Override
public State deserializeSnapshot(final ByteSource snapshotBytes) throws IOException {
return ByteState.of(snapshotBytes.read());
}
@Override
public void createSnapshot(final ActorRef actorRef, final Optional<OutputStream> installSnapshotStream) {
}
@Override
public void applySnapshot(final State snapshotState) {
}
});
return snapshotManager;
}
示例7: setSnapshotBytes
import com.google.common.io.ByteSource; //導入依賴的package包/類
void setSnapshotBytes(final ByteSource snapshotBytes) throws IOException {
if (this.snapshotBytes != null) {
return;
}
snapshotSize = snapshotBytes.size();
snapshotInputStream = snapshotBytes.openStream();
this.snapshotBytes = snapshotBytes;
totalChunks = (int) (snapshotSize / snapshotChunkSize + (snapshotSize % snapshotChunkSize > 0 ? 1 : 0));
LOG.debug("{}: Snapshot {} bytes, total chunks to send: {}", logName, snapshotSize, totalChunks);
replyReceivedForOffset = -1;
chunkIndex = FIRST_CHUNK_INDEX;
}
示例8: testGetExistingYangTextSchemaSource
import com.google.common.io.ByteSource; //導入依賴的package包/類
@Test
public void testGetExistingYangTextSchemaSource() throws Exception {
String source = "Test source.";
YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource(
ID, ByteSource.wrap(source.getBytes()));
Mockito.when(mockedLocalRepository.getSchemaSource(ID, YangTextSchemaSource.class)).thenReturn(
Futures.immediateCheckedFuture(schemaSource));
Future<YangTextSchemaSourceSerializationProxy> retrievedSourceFuture =
remoteRepository.getYangTextSchemaSource(ID);
assertTrue(retrievedSourceFuture.isCompleted());
YangTextSchemaSource resultSchemaSource = Await.result(retrievedSourceFuture,
Duration.Zero()).getRepresentation();
assertEquals(resultSchemaSource.getIdentifier(), schemaSource.getIdentifier());
assertArrayEquals(resultSchemaSource.read(), schemaSource.read());
}
示例9: consumeByteSourceOrNull
import com.google.common.io.ByteSource; //導入依賴的package包/類
/**
* Read the contents of the source into a byte array.
* @param source the byte array source
* @return the byte[] read from the source or null
*/
private byte[] consumeByteSourceOrNull(final ByteSource source) {
try {
if (source == null || source.isEmpty()) {
return null;
}
return source.read();
} catch (final IOException e) {
logger.warn("Could not consume the byte array source", e);
return null;
}
}
示例10: getSalt
import com.google.common.io.ByteSource; //導入依賴的package包/類
/**
* Get salt.
*
* @return the byte[] for the salt or null
*/
@JsonIgnore
public byte[] getSalt() {
try {
return ByteSource.wrap(convertSaltToByteArray()).read();
} catch (final IOException e) {
LOGGER.warn("Salt cannot be read because the byte array from source could not be consumed");
}
return null;
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:15,代碼來源:ShibbolethCompatiblePersistentIdGenerator.java
示例11: EncodedTicket
import com.google.common.io.ByteSource; //導入依賴的package包/類
/**
* Creates a new encoded ticket using the given encoder to encode the given
* source ticket.
*
* @param encodedTicket the encoded ticket
* @param encodedTicketId the encoded ticket id
*/
public EncodedTicket(final ByteSource encodedTicket, final String encodedTicketId) {
try {
this.id = encodedTicketId;
this.encodedTicket = encodedTicket.read();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
示例12: isTokenNtlm
import com.google.common.io.ByteSource; //導入依賴的package包/類
/**
* Checks if is token ntlm.
*
* @param tokenSource the token
* @return true, if token ntlm
*/
private boolean isTokenNtlm(final ByteSource tokenSource) {
final byte[] token = consumeByteSourceOrNull(tokenSource);
if (token == null || token.length < NTLM_TOKEN_MAX_LENGTH) {
return false;
}
for (int i = 0; i < NTLM_TOKEN_MAX_LENGTH; i++) {
if (NTLMSSP_SIGNATURE[i].byteValue() != token[i]) {
return false;
}
}
return true;
}
示例13: getSalt
import com.google.common.io.ByteSource; //導入依賴的package包/類
/**
* Get salt.
*
* @return the byte[] for the salt or null
*/
public byte[] getSalt() {
try {
return ByteSource.wrap(this.salt).read();
} catch (final IOException e) {
LOGGER.warn("Salt cannot be read because the byte array from source could not be consumed");
}
return null;
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:14,代碼來源:ShibbolethCompatiblePersistentIdGenerator.java
示例14: EncryptedMapDecorator
import com.google.common.io.ByteSource; //導入依賴的package包/類
/**
* Decorates a map using the provided algorithms.
* <p>Takes a salt and secretKey so that it can work with a distributed cache.
*
* @param decoratedMap the map to decorate. CANNOT be NULL.
* @param hashAlgorithm the algorithm to use for hashing. CANNOT BE NULL.
* @param salt the salt, as a String. Gets converted to bytes. CANNOT be NULL.
* @param secretKeyAlgorithm the encryption algorithm. CANNOT BE NULL.
* @param secretKey the secret to use. CANNOT be NULL.
* @throws RuntimeException if the algorithm cannot be found or the iv size cant be determined.
*/
public EncryptedMapDecorator(final Map<String, String> decoratedMap, final String hashAlgorithm, final byte[] salt,
final String secretKeyAlgorithm, final Key secretKey) {
try {
this.decoratedMap = decoratedMap;
this.key = secretKey;
this.salt = ByteSource.wrap(salt);
this.secretKeyAlgorithm = secretKeyAlgorithm;
this.messageDigest = MessageDigest.getInstance(hashAlgorithm);
this.ivSize = getIvSize();
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
示例15: reAssembleMessage
import com.google.common.io.ByteSource; //導入依賴的package包/類
private static Object reAssembleMessage(final AssembledMessageState state) throws MessageSliceException {
try {
final ByteSource assembledBytes = state.getAssembledBytes();
try (ObjectInputStream in = new ObjectInputStream(assembledBytes.openStream())) {
return in.readObject();
}
} catch (IOException | ClassNotFoundException e) {
throw new MessageSliceException(String.format("Error re-assembling bytes for identifier %s",
state.getIdentifier()), e);
}
}