BSD License
For Conceal software
Copyright (c) 2014, Facebook, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that...
If you think the Android project conceal listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (c) 2014, Facebook, Inc./*fromwww.java2s.com*/
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/package com.facebook.crypto.streams;
import com.facebook.crypto.mac.NativeMac;
import java.io.IOException;
import java.io.OutputStream;
publicclass NativeMacLayeredOutputStream extends OutputStream {
privatefinal NativeMac mMac;
privatefinal OutputStream mOutputDelegate;
/**
* Creates a new output stream to write to.
*
* @param mac The object used to compute the mac.
* @param outputDelegate The stream to write data to.
*/public NativeMacLayeredOutputStream(NativeMac mac, OutputStream outputDelegate) {
mMac = mac;
mOutputDelegate = outputDelegate;
}
@Override
publicvoid close() throws IOException {
try {
byte[] mac = mMac.doFinal();
mOutputDelegate.write(mac);
} finally {
try {
mOutputDelegate.close();
} finally {
mMac.destroy();
}
}
}
@Override
publicvoid flush() throws IOException {
mOutputDelegate.flush();
}
@Override
publicvoid write(byte[] buffer) throws IOException {
write(buffer, 0, buffer.length);
}
@Override
publicvoid write(byte[] buffer, int offset, int count) throws IOException {
mMac.update(buffer, offset, count);
mOutputDelegate.write(buffer, offset, count);
}
@Override
publicvoid write(int oneByte) throws IOException {
mMac.update((byte) oneByte);
mOutputDelegate.write(oneByte);
}
}