New class FileRotatingStreamReader
When landed, the FileRotatingStream class can be made write-only. Bug: webrtc:7811 Change-Id: I6dcd2a869301b9b8273b48d47df51a1065767ffd Reviewed-on: https://webrtc-review.googlesource.com/c/115302 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26126}
This commit is contained in:
@ -50,23 +50,17 @@ JNI_CallSessionFileRotatingLogSink_GetLogData(
|
||||
JNIEnv* jni,
|
||||
const JavaParamRef<jstring>& j_dirPath) {
|
||||
std::string dir_path = JavaToStdString(jni, j_dirPath);
|
||||
std::unique_ptr<rtc::CallSessionFileRotatingStream> stream(
|
||||
new rtc::CallSessionFileRotatingStream(dir_path));
|
||||
if (!stream->Open()) {
|
||||
RTC_LOG_V(rtc::LoggingSeverity::LS_WARNING)
|
||||
<< "Failed to open CallSessionFileRotatingStream for path " << dir_path;
|
||||
return ScopedJavaLocalRef<jbyteArray>(jni, jni->NewByteArray(0));
|
||||
}
|
||||
size_t log_size = 0;
|
||||
if (!stream->GetSize(&log_size) || log_size == 0) {
|
||||
rtc::CallSessionFileRotatingStreamReader file_reader(dir_path);
|
||||
size_t log_size = file_reader.GetSize();
|
||||
if (log_size == 0) {
|
||||
RTC_LOG_V(rtc::LoggingSeverity::LS_WARNING)
|
||||
<< "CallSessionFileRotatingStream returns 0 size for path " << dir_path;
|
||||
return ScopedJavaLocalRef<jbyteArray>(jni, jni->NewByteArray(0));
|
||||
}
|
||||
|
||||
size_t read = 0;
|
||||
// TODO(nisse, sakal): To avoid copying, change api to use ByteBuffer.
|
||||
std::unique_ptr<jbyte> buffer(static_cast<jbyte*>(malloc(log_size)));
|
||||
stream->ReadAll(buffer.get(), log_size, &read, nullptr);
|
||||
size_t read = file_reader.ReadAll(buffer.get(), log_size);
|
||||
|
||||
ScopedJavaLocalRef<jbyteArray> result =
|
||||
ScopedJavaLocalRef<jbyteArray>(jni, jni->NewByteArray(read));
|
||||
|
||||
Reference in New Issue
Block a user