Skip to content

Commit

Permalink
Refactored variables to mmtf-common.
Browse files Browse the repository at this point in the history
  • Loading branch information
abradle committed Apr 20, 2016
1 parent c68ff53 commit 4cd80bb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
11 changes: 10 additions & 1 deletion mmtf-common/src/main/java/org/rcsb/mmtf/utils/CodecUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
import java.util.List;

/**
* A utility class of static methods for the codec project.
* A utility class of static methods and constants
* for the codec project.
* @author Anthony Bradley
*
*/
public class CodecUtils {


/** The base url. */
public static final String BASE_URL = "http://mmtf.rcsb.org/v0/full/";


/** The maximum number of chars in a chain entry. */
public static final int MAX_CHARS_PER_CHAIN_ENTRY= 4;

/**
* Convert an integer list to an integer array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.nio.ByteBuffer;

import org.rcsb.mmtf.utils.CodecUtils;

/**
* Class of functions to convert arrays to readable types.
* e.g. byte arrays to integer arrays.
Expand All @@ -10,9 +12,6 @@
*/
public class ArrayConverters {

/** The maximum number of chars in a chain entry. */
private static final int MAX_CHARS_PER_CHAIN_ENTRY = 4;

/**
* Find all the chain ids from a single byte array. Each byte encodes a different ASCII character.
* @param currentChainList the byte array of the chain list input. Each chain takes up 4 bytes.
Expand Down Expand Up @@ -144,21 +143,21 @@ public static char[] convertIntegerToChar(int[] integerArray) {
private static String getChainId(byte[] byteArr, int chainIndex) {
int incrementor = 0;
StringBuilder sb = new StringBuilder();
byte chainIdOne = byteArr[chainIndex * MAX_CHARS_PER_CHAIN_ENTRY + incrementor];
byte chainIdOne = byteArr[chainIndex * CodecUtils.MAX_CHARS_PER_CHAIN_ENTRY + incrementor];
sb.append((char) chainIdOne);
// Now get the next byte
incrementor += 1;
byte chainIdTwo = byteArr[chainIndex * MAX_CHARS_PER_CHAIN_ENTRY + incrementor];
byte chainIdTwo = byteArr[chainIndex * CodecUtils.MAX_CHARS_PER_CHAIN_ENTRY + incrementor];
if (chainIdTwo != (byte) 0) {
sb.append((char) chainIdTwo);
}
incrementor += 1;
byte chainIdThree = byteArr[chainIndex * MAX_CHARS_PER_CHAIN_ENTRY + incrementor];
byte chainIdThree = byteArr[chainIndex * CodecUtils.MAX_CHARS_PER_CHAIN_ENTRY + incrementor];
if (chainIdThree != (byte) 0) {
sb.append((char) chainIdThree);
}
incrementor += 1;
byte chainIdFour = byteArr[chainIndex * MAX_CHARS_PER_CHAIN_ENTRY + incrementor];
byte chainIdFour = byteArr[chainIndex * CodecUtils.MAX_CHARS_PER_CHAIN_ENTRY + incrementor];
if (chainIdFour != (byte) 0) {
sb.append((char) chainIdFour);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public DecoderToReader(StructureDataInterface inputApi, StructureAdapterInterfac
/**
* Add the main atomic information to the data model
*/
private final void addAtomicInformation() {
private void addAtomicInformation() {
for (int modelChains: dataApi.getChainsPerModel()) {
structInflator.setModelInfo(modelCounter, modelChains);
int totChainsThisModel = chainCounter + modelChains;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@

import org.rcsb.mmtf.dataholders.MmtfBean;
import org.rcsb.mmtf.deserializers.MessagePackDeserializer;
import org.rcsb.mmtf.utils.CodecUtils;

/**
* A class of static utility methods for reading data.
* @author Anthony Bradley
*
*/
public class ReaderUtils {

/** The base url. */
public static final String BASE_URL = "http://mmtf.rcsb.org/v0/full/";

/** The size of a chunk for a byte buffer. */
private static final int BYTE_BUFFER_CHUNK_SIZE = 4096;

Expand All @@ -35,7 +34,7 @@ public static MmtfBean getDataFromUrl(String pdbCode) throws IOException {
// Get these as an inputstream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = null;
URL url = new URL(BASE_URL + pdbCode);
URL url = new URL(CodecUtils.BASE_URL + pdbCode);
try {
is = url.openStream();
byte[] byteChunk = new byte[BYTE_BUFFER_CHUNK_SIZE]; // Or whatever size you want to read in at a time.
Expand Down

0 comments on commit 4cd80bb

Please sign in to comment.