Skip to content

Commit

Permalink
MOD_OG_20150620
Browse files Browse the repository at this point in the history
small enhancements in the utilities lib :
- suppress double calls
- share methods by placing them in CXResource
  • Loading branch information
ogattaz committed Jun 22, 2015
1 parent 1ff8e54 commit e875971
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 175 deletions.
85 changes: 51 additions & 34 deletions org.cohorte.utilities/src/org/psem2m/utilities/CXBytesUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/**
* @author isandlatech (www.isandlatech.com) - ogattaz
*
*
*/
public final class CXBytesUtils {

Expand Down Expand Up @@ -93,7 +93,7 @@ public final class CXBytesUtils {

/**
* ajoute la representation HEXA d'un octet dans un StringBuilder
*
*
* @param aSB
* @param mybyte
* @return
Expand All @@ -108,7 +108,7 @@ public static StringBuilder addByte2DecimalInSB(final StringBuilder aSB,

/**
* ajoute la representation HEXA d'un octet dans un CStringBuilder
*
*
* @param aCSB
* @param mybyte
* @return
Expand All @@ -124,7 +124,7 @@ public static StringBuilder addByte2HexaInCSB(final StringBuilder aSB,

/**
* ajoute la representation HEXA d'un octet dans un StringBuilder
*
*
* @param aSB
* @param mybyte
* @return
Expand All @@ -140,7 +140,7 @@ public static StringBuilder addByte2HexaInSB(final StringBuilder aSB,

/**
* Ajoute un "byte" (1) octets au buffer.
*
*
* @param aBuffer
* @param aPos
* @param aValue
Expand All @@ -161,7 +161,7 @@ public static int appendByteInBuffer(final byte[] aBuffer, final int aPos,

/**
* Ajoute un "short" 2 octets au buffer
*
*
* @param aBuffer
* @param aPos
* @param aInfo
Expand All @@ -177,7 +177,7 @@ public static int appendBytesInBuffer(final byte[] aBuffer, final int aPos,

/**
* Ajoute un "entier" 4 octets au buffer.
*
*
* @param aBuffer
* @param aPos
* @param aValue
Expand All @@ -198,7 +198,7 @@ public static int appendBytetInBuffer(final byte[] aBuffer, final int aPos,
}

/**
*
*
* @param aDestBuffer
* @param aDestPos
* @param aAddedBuffer
Expand All @@ -215,7 +215,7 @@ public static byte[] appendInExpendableBuffer(final byte[] aDestBuffer,
/**
* Ajoute aAddedLen octets du aAddedBuffer a partir de aAddedOffset dans le
* buffer "extensible" aDestBuffer en position aDestPos
*
*
* @param aDestBuffer
* @param aDestPos
* @param aAddedBuffer
Expand Down Expand Up @@ -243,7 +243,7 @@ public static byte[] appendInExpendableBuffer(final byte[] aDestBuffer,

/**
* Ajoute un "entier" 4 octets au buffer.
*
*
* @return la nouvelle position
* @param aBuffer
* @param aPos
Expand All @@ -266,7 +266,7 @@ public static int appendIntInBuffer(final byte[] aBuffer, final int aPos,

/**
* Ajoute un "long" 8 octets au buffer.
*
*
* @param aBuffer
* @param aPos
* @param aValue
Expand All @@ -288,7 +288,7 @@ public static int appendLongInBuffer(final byte[] aBuffer, final int aPos,

/**
* Ajoute un n octets contenant la valeur "aValue" au buffer.
*
*
* @param aBuffer
* @param aPos
* @param aValue
Expand All @@ -313,7 +313,7 @@ public static int appendNBytesInBuffer(final byte[] aBuffer, int aPos,

/**
* Ajoute un "short" 2 octets au buffer
*
*
* @param aBuffer
* @param aPos
* @param aValue
Expand Down Expand Up @@ -376,7 +376,7 @@ static private char[] byte2HexaInChars(final byte mybyte) {

/**
* dump d'un buffer sous forme d'une chaine Decimale : .d001.d255 ...
*
*
* @param aBuffer
* @param aOffset
* @param aLong
Expand All @@ -392,7 +392,7 @@ public static String byteBufferBin2Decimal(final byte[] aBuffer,

/**
* dump d'un buffer sous forme d'une chaine Hexa : .xFF.xFE ...
*
*
* @param aBuffer
* @return
* @deprecated
Expand All @@ -404,7 +404,7 @@ public static String byteBufferBin2Hexa(final byte[] aBuffer) {

/**
* dump d'un buffer sous forme d'une chaine Hexa : .xFF.xFE ...
*
*
* @param aBuffer
* @param aOffset
* @param aLong
Expand All @@ -419,7 +419,7 @@ public static String byteBufferBin2Hexa(final byte[] aBuffer,

/**
* dump d'un buffer sous forme d'une chaine Decimale : .d001.d255 ...
*
*
* @param aBuffer
* @return
*/
Expand All @@ -429,7 +429,7 @@ public static String bytesToDecimalString(final byte[] aBuffer) {

/**
* dump d'un buffer sous forme d'une chaine Decimale : .d001.d255 ...
*
*
* @param aBuffer
* @param aOffset
* @param aLong
Expand Down Expand Up @@ -464,7 +464,7 @@ public static String bytesToDecimalString(final byte[] aBuffer,

/**
* dump d'un buffer sous forme d'une chaine Hexa : .xFF.xFE ...
*
*
* @param aBuffer
* @return
*/
Expand All @@ -474,7 +474,7 @@ public static String bytesToHexaString(final byte[] aBuffer) {

/**
* dump d'un buffer sous forme d'une chaine Hexa : .xFF.xFE ...
*
*
* @param aBuffer
* @param aOffset
* @param aLong
Expand Down Expand Up @@ -629,7 +629,7 @@ public static byte[] byteToBytes(final byte aByte) {
}

/**
*
*
* @param aBuffer
* @param aBomRef
* @return
Expand All @@ -646,7 +646,7 @@ private static boolean checkBOM(final byte[] aBuffer, final byte[] aBomRef) {
/**
* Computes the failure function using a boot-strapping process, where the
* pattern is matched against itself.
*
*
* @param pattern
* @return
*/
Expand Down Expand Up @@ -739,13 +739,13 @@ public static int getBomLength(final String aEncoding) {
}

/**
*
*
* The Java I/O classes will read and write Unicode data in the
* "default character encoding" by default. The default encoding depends on
* some combination of the JVM, the underlying OS, and the OS-level locale
* settings. For example, on my Windows 2000 computer, the default encoding
* is CP-1252, a Microsoft-specific variant of Latin-1.
*
*
* @param aBuffer
* @return
*/
Expand Down Expand Up @@ -867,7 +867,7 @@ public static byte[] intToOneByte(final int aValue) {
}

/**
*
*
* @param aHexaBuffer
* @return
* @throws IllegalArgumentException
Expand All @@ -888,7 +888,7 @@ public static byte[] longToBytes(final long aLong) {

/**
* One byte oo Int
*
*
* @param aBuffer
* @return
* @throws IllegalArgumentException
Expand All @@ -899,26 +899,43 @@ public static int oneByteToInt(final byte[] aBuffer, final int aPos)
}

/**
* MOD_OG_20150620
*
* @param aInputStream
* @return
* @throws Exception
*/
public static byte[] readAllBytes(InputStream aInputStream)
public static byte[] readAllBytes(final InputStream aInputStream)
throws Exception {
return readBytes(aInputStream, aInputStream.available());
return readBytesImpl(aInputStream, aInputStream.available());
}

/**
* MOD_OG_20150620
*
* @param aInputStream
* @param aSize
* @return
* @throws Exception
*/
public static byte[] readBytes(InputStream aInputStream, int aSize)
throws Exception {
public static byte[] readBytes(final InputStream aInputStream,
final int aSize) throws Exception {

int wMax = Math.min(aSize, aInputStream.available());
byte[] wData = new byte[wMax];
return readBytesImpl(aInputStream,
Math.min(aSize, aInputStream.available()));
}

/**
* MOD_OG_20150620
*
* @param aInputStream
* @param aSize
* @return
* @throws Exception
*/
private static byte[] readBytesImpl(final InputStream aInputStream,
final int aSize) throws Exception {
byte[] wData = new byte[aSize];
aInputStream.read(wData);
aInputStream.close();
return wData;
Expand Down Expand Up @@ -984,7 +1001,7 @@ public static boolean startWith(final byte[] aBuffer,
}

/**
*
*
* @param aHexaBuffer
* @param aThrowingException
* @return
Expand Down Expand Up @@ -1013,7 +1030,7 @@ private static boolean testCharsOfHexaBufferBytes(final String aHexaBuffer,
}

/**
*
*
* @param aHexaBuffer
* @param aThrowingException
* @return true si la chaine est de la forme ".x00.x01.xE5 etc..."
Expand Down
Loading

0 comments on commit e875971

Please sign in to comment.