자바를 사용하여 읽을 수있는 gtfs 실시간 데이터 (프로토콜 버퍼 형식)를 다운로드하려고하므로 텍스트 파일로 볼 수 있습니다.gtfs 실시간 데이터를 사람이 읽을 수있는 형식으로 스트리밍
접근 # 1 :
나는 방법의 몇 가지 시도URL url = new URL(uri);
byte[] buffer = new byte[4096];
InputStream is = url.openStream();
byte[] buffer = new byte[4096];
InputStream is = url.openStream();
File file = new File("c:/protobuf_data.txt");
OutputStream output = new FileOutputStream(file);
int numOfBytesReadIntoBuffer = -1;
while((numOfBytesReadIntoBuffer = is.read(buffer)) != -1){
output.write(buffer, 0, numOfBytesReadIntoBuffer);
}
results (snippet):
099700_L..S20150102*LÊ>0L 1637 8AV/RPY!¯¬œ¥¾¬œ¥"L22S(
접근 # 2 (접근 번호와 같은 동일한 결과를 1) : 수입 org.apache.commons.io.IOUtils;
URL url = new URL(uri);
InputStream is = url.openStream();
File file = new File("c:/protobuf_data.txt");
OutputStream output = new FileOutputStream(file);
byte[] bytes = IOUtils.toByteArray(is);
output.write(bytes);
같은 방식으로 OutputStream에 모두 쓰기 때문에 결과는 같습니다. When using google protocol buffers to transfer String character,got messy code
내가 프로토콜 버퍼 문서를 읽을 수 있지만 좀 더 혼란 가지고 :
는 또한 제안은 여기 있지만 난 그냥 점점 오류를 종료했습니다. https://developers.google.com/protocol-buffers/docs/encoding
com.sun.org.apache.xml.internal.security.utils.Base64를 사용했지만 오류가 발생합니다. 접근법 # 3
URL url = new URL(uri);
InputStream is = url.openStream();
File file = new File("c:/users/Workstation/protobuf_data_bytes.txt");
OutputStream output = new FileOutputStream(file);
byte[] bytes = IOUtils.toByteArray(is);
Init.init();
byte[] decoded_bytes = Base64.decode(bytes);
error:
Exception in thread "main" com.sun.org.apache.xml.internal.security.exceptions.Base64DecodingException: Error while decoding
I는 Base64로 인코딩 된 바이트 스트림을 디코딩하기위한 InputStream를 만들 java.util.Base64의 포장 방법을 이용하려고하지만, 데이터는 단지 더 혼용 얻었다.
프로토콜 버퍼는 바이너리 메시지 형식이며 .proto 파일은 읽고있는 메시지의 필드와 데이터 형식을 설명합니다. https://developers.google.com/transit/gtfs-realtime/gtfs-realtime-proto의 GTFS 프로토콜 메시지 정의 파일이 필요합니다.이 파일은 GTFS 메시지를 인코딩하고 디코딩하는 방법을 설명합니다 (내가 GTFS의 올바른 의미를 짐작할 수 있습니다.) 프로토콜 버퍼 컴파일러 https://developers.google.com/protocol-buffers/docs/downloads도 필요합니다.이 파일은 .proto 파일을 입력으로 사용하고 해당 메시지를 인코딩하고 디코딩 할 Java 클래스를 생성합니다. –