Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

THRIFT-4945 Log output mode is not standardized #1862

Merged
merged 1 commit into from Oct 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 12 additions & 9 deletions lib/java/src/org/apache/thrift/transport/TFileTransport.java
Expand Up @@ -26,6 +26,9 @@
import java.io.IOException;
import java.util.Random;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* FileTransport implementation of the TTransport interface.
* Currently this is a straightforward port of the cpp implementation
Expand All @@ -36,6 +39,8 @@
*/
public class TFileTransport extends TTransport {

private static final Logger LOGGER = LoggerFactory.getLogger(TFileTransport.class.getName());

public static class TruncableBufferedInputStream extends BufferedInputStream {
public void trunc() {
pos = count = 0;
Expand Down Expand Up @@ -211,7 +216,6 @@ private InputStream createInputStream() throws TTransportException {
is = new TruncableBufferedInputStream(inputFile_.getInputStream());
}
} catch (IOException iox) {
System.err.println("createInputStream: "+iox.getMessage());
throw new TTransportException(iox.getMessage(), iox);
}
return(is);
Expand Down Expand Up @@ -380,7 +384,7 @@ public void close() {
try {
inputFile_.close();
} catch (IOException iox) {
System.err.println("WARNING: Error closing input file: " +
LOGGER.warn("WARNING: Error closing input file: " +
iox.getMessage());
}
inputFile_ = null;
Expand All @@ -389,7 +393,7 @@ public void close() {
try {
outputStream_.close();
} catch (IOException iox) {
System.err.println("WARNING: Error closing output stream: " +
LOGGER.warn("WARNING: Error closing output stream: " +
iox.getMessage());
}
outputStream_ = null;
Expand Down Expand Up @@ -525,7 +529,6 @@ public void seekToChunk(int chunk) throws TTransportException {
if(chunk*cs.getChunkSize() != cs.getOffset()) {
try { inputFile_.seek((long)chunk*cs.getChunkSize()); }
catch (IOException iox) {
System.err.println("createInputStream: "+iox.getMessage());
throw new TTransportException("Seek to chunk " +
chunk + " " +iox.getMessage(), iox);
}
Expand Down Expand Up @@ -591,20 +594,20 @@ public static void main(String[] args) throws Exception {
try {
num_chunks = Integer.parseInt(args[1]);
} catch (Exception e) {
System.err.println("Cannot parse " + args[1]);
LOGGER.error("Cannot parse " + args[1]);
printUsage();
}
}

TFileTransport t = new TFileTransport(args[0], true);
t.open();
System.out.println("NumChunks="+t.getNumChunks());
LOGGER.info("NumChunks="+t.getNumChunks());

Random r = new Random();
for(int j=0; j<num_chunks; j++) {
byte[] buf = new byte[4096];
int cnum = r.nextInt(t.getNumChunks()-1);
System.out.println("Reading chunk "+cnum);
LOGGER.info("Reading chunk "+cnum);
t.seekToChunk(cnum);
for(int i=0; i<4096; i++) {
t.read(buf, 0, 4096);
Expand All @@ -613,8 +616,8 @@ public static void main(String[] args) throws Exception {
}

private static void printUsage() {
System.err.println("Usage: TFileTransport <filename> [num_chunks]");
System.err.println(" (Opens and reads num_chunks chunks from file randomly)");
LOGGER.error("Usage: TFileTransport <filename> [num_chunks]");
LOGGER.error(" (Opens and reads num_chunks chunks from file randomly)");
System.exit(1);
}

Expand Down