Skip to content

Commit

Permalink
Added API functions to get the URL as a String and the data as an Inp…
Browse files Browse the repository at this point in the history
…utStream
  • Loading branch information
abradle committed Sep 14, 2016
1 parent 8d4fb0f commit 0393c84
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -71,3 +71,8 @@ All notable changes to this project will be documented in this file, following t
- Cleanup of WriterUtils
- Updated version string in MmtfStructure
- Updated test data


## v1.0.3 - 2016-09-13
### Added
- API functions to get the URL as a string and the data as an inputstream
6 changes: 3 additions & 3 deletions README.md
@@ -1,7 +1,7 @@
[![Build Status](https://travis-ci.org/rcsb/mmtf-java.svg?branch=master)](https://travis-ci.org/rcsb/mmtf-java)
[![Coverage Status](https://coveralls.io/repos/github/rcsb/mmtf-java/badge.svg?branch=master)](https://coveralls.io/github/rcsb/mmtf-java?branch=master)
[![Dependency Status](https://www.versioneye.com/user/projects/56feb8e5fcd19a0039f1553c/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56feb8e5fcd19a0039f1553c)
[![Version](http://img.shields.io/badge/version-1.0.2-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/) [![License](http://img.shields.io/badge/license-Apache 2.0-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/blob/master/LICENSE.txt)
[![Version](http://img.shields.io/badge/version-1.0.3-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/) [![License](http://img.shields.io/badge/license-Apache 2.0-blue.svg?style=flat)](https://github.com/rcsb/mmtf-java/blob/master/LICENSE.txt)
[![Changelog](https://img.shields.io/badge/changelog--lightgrey.svg?style=flat)](https://github.com/rcsb/mmtf-java/blob/master/CHANGELOG.md)


Expand All @@ -16,12 +16,12 @@ The alpha release is available on Maven central.
<dependency>
<groupId>org.rcsb</groupId>
<artifactId>mmtf-codec</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.rcsb</groupId>
<artifactId>mmtf-api</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</dependency>
```

Expand Down
25 changes: 22 additions & 3 deletions mmtf-codec/src/main/java/org/rcsb/mmtf/decoder/ReaderUtils.java
Expand Up @@ -47,7 +47,7 @@ public static MmtfStructure getDataFromUrl(String pdbCode) throws IOException {
public static byte[] getByteArrayFromUrl(String pdbCode) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream inputStream = null;
URL url = new URL(CodecUtils.BASE_URL + pdbCode);
URL url = new URL(getUrl(pdbCode));
try {
inputStream = url.openStream();
byte[] byteChunk = new byte[BYTE_BUFFER_CHUNK_SIZE]; // Or whatever size you want to read in at a time.
Expand Down Expand Up @@ -103,8 +103,7 @@ public static byte[] deflateGzip(byte[] inputBytes) throws IOException {
*/
public static MmtfStructure getDataFromFile(Path filePath) throws IOException {
// Now return the gzip deflated and deserialized byte array
MessagePackSerialization mmtfBeanSeDeMessagePackImpl = new MessagePackSerialization();
return mmtfBeanSeDeMessagePackImpl.deserialize(new ByteArrayInputStream(readFile(filePath)));
return getDataFromInputStream(new ByteArrayInputStream(readFile(filePath)));
}

/**
Expand All @@ -117,4 +116,24 @@ private static byte[] readFile(Path path) throws IOException {
byte[] data = Files.readAllBytes(path);
return data;
}

/**
* Read an input stream to an {@link MmtfStructure} object.
* @param inStream the {@link InputStream} to read.
* @return the {@link MmtfStructure} to be returned
*/
public static MmtfStructure getDataFromInputStream(InputStream inStream) {
MessagePackSerialization mmtfBeanSeDeMessagePackImpl = new MessagePackSerialization();
return mmtfBeanSeDeMessagePackImpl.deserialize(inStream);

}

/**
* Get the URL to return a given PDB id
* @param pdbId the input PDB id
* @return the URL {@link String} to get data from
*/
public static String getUrl(String pdbId) {
return CodecUtils.BASE_URL + pdbId;
}
}

0 comments on commit 0393c84

Please sign in to comment.