Prechádzať zdrojové kódy

remove automatic printing of execute command

Gary Paduana 8 rokov pred
rodič
commit
b844db9d4a

+ 2 - 3
.idea/modules/groovy-tools_main.iml

@@ -1,13 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <module external.linked.project.id="groovy-tools:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
   <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
-    <output url="file://$MODULE_DIR$/../../build/classes/main" />
+    <output url="file://$MODULE_DIR$/../../out/production/classes" />
     <exclude-output />
     <content url="file://$MODULE_DIR$/../../src/main">
       <sourceFolder url="file://$MODULE_DIR$/../../src/main/groovy" isTestSource="false" />
       <sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
-      <sourceFolder url="file://$MODULE_DIR$/../../src/test" isTestSource="true" />
-      <sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" type="java-resource" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />

+ 1 - 1
.idea/modules/groovy-tools_test.iml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <module external.linked.project.id="groovy-tools:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
   <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
-    <output-test url="file://$MODULE_DIR$/../../build/classes/test" />
+    <output-test url="file://$MODULE_DIR$/../../out/test/classes" />
     <exclude-output />
     <content url="file://$MODULE_DIR$/../../src/test">
       <sourceFolder url="file://$MODULE_DIR$/../../src/test/groovy" isTestSource="true" />

+ 33 - 28
src/main/groovy/com/garypaduana/groovytools/formatting/StringCleaner.groovy

@@ -4,8 +4,37 @@ import java.text.DecimalFormat
 
 class StringCleaner {
 
-    static def stripNonHexCharacters(String text){
-        return text.replaceAll("[^0-9ABCDEFabcdef]", '')
+    static def customFormat(String pattern, int value){
+        DecimalFormat decimalFormat = new DecimalFormat(pattern);
+        return decimalFormat.format(value);
+    }
+
+    static def customFormat(String pattern, double value){
+        DecimalFormat decimalFormat = new DecimalFormat(pattern);
+        return decimalFormat.format(value);
+    }
+
+    /**
+     *
+     * @param text
+     * @return
+     */
+    static byte[] decodeMessyHexToByteArray(String text){
+        text = stripNonHexCharacters(text)
+
+        int bitCount = text.length() * 4
+        int byteCount = bitCount % 8 == 0 ? (bitCount / 8) : (bitCount / 8 + 1)
+
+        byte[] bytes = new byte[byteCount]
+
+        int j = 0
+        for(int i = 0; i < text.length(); i += 2){
+            int end = (i + 2) <= text.length() ? (i + 2) : text.length()
+            bytes[j] = 0xFF & Integer.valueOf(text.substring(i, end), 16)
+            j++
+        }
+
+        return bytes
     }
 
     /**
@@ -85,31 +114,7 @@ class StringCleaner {
         return str.substring(start, end)
     }
 
-    static def customFormat(String pattern, int value){
-        DecimalFormat decimalFormat = new DecimalFormat(pattern);
-        return decimalFormat.format(value);
-    }
-
-    static def customFormat(String pattern, double value){
-        DecimalFormat decimalFormat = new DecimalFormat(pattern);
-        return decimalFormat.format(value);
-    }
-
-    static byte[] decodeMessyHexToByteArray(String text){
-        text = stripNonHexCharacters(text)
-
-        int bitCount = text.length() * 4
-        int byteCount = bitCount % 8 == 0 ? (bitCount / 8) : (bitCount / 8 + 1)
-
-        byte[] bytes = new byte[byteCount]
-
-        int j = 0
-        for(int i = 0; i < text.length(); i += 2){
-            int end = (i + 2) <= text.length() ? (i + 2) : text.length()
-            bytes[j] = 0xFF & Integer.valueOf(text.substring(i, end), 16)
-            j++
-        }
-
-        return bytes
+    static def stripNonHexCharacters(String text){
+        return text.replaceAll("[^0-9ABCDEFabcdef]", '')
     }
 }

+ 4 - 4
src/main/groovy/com/garypaduana/groovytools/system/Files.groovy

@@ -1,7 +1,5 @@
 package com.garypaduana.groovytools.system
 
-import java.awt.image.BufferedImage
-import java.io.File
 import javax.imageio.ImageIO
 import java.security.MessageDigest
 
@@ -19,7 +17,7 @@ class Files{
         }
     }
 
-    static def generateDigest(File file, String digest, int paddedLength){
+    static def generateDigest(File file, String digest, long maxLength, int paddedLength){
         MessageDigest md = MessageDigest.getInstance(digest)
         md.reset()
         def files = []
@@ -47,8 +45,10 @@ class Files{
             f.withInputStream(){is ->
                 byte[] buffer = new byte[8192]
                 int read = 0
-                while((read = is.read(buffer)) > 0){
+                long totalRead = 0
+                while((read = is.read(buffer)) > 0 && totalRead <= maxLength){
                     md.update(buffer, 0, read)
+                    totalRead += read
                 }
             }
         }

+ 10 - 8
src/main/groovy/com/garypaduana/groovytools/system/Process.groovy

@@ -1,18 +1,18 @@
 package com.garypaduana.groovytools.system
 
-class Process{
+class Process {
 
     /**
      * Convenience method wrapper for execute(String command, boolean print)
      */
-    static def execute(String command){
+    static def execute(String command) {
         return execute(command, true)
     }
 
     /**
      * Convenience method wrapper for execute(List<String> command, boolean print)
      */
-    static def execute(List<String> command){
+    static def execute(List<String> command) {
         return execute(command, true)
     }
 
@@ -22,7 +22,7 @@ class Process{
      * @param print - should the output be printed to console line by line?
      * @return String - the complete output
      */
-    static def execute(String command, boolean print){
+    static def execute(String command, boolean print) {
         return execute(new ArrayList<String>(Arrays.asList(command.split(" "))), print)
     }
 
@@ -32,12 +32,14 @@ class Process{
      * @param print - should the output be printed to console line by line?
      * @return String - the complete output
      */
-    static def execute(List<String> command, boolean print){
+    static def execute(List<String> command, boolean print) {
         StringBuilder sb = new StringBuilder()
-        println "Executing: ${command.join(' ')}"
+        if (print) {
+            println "Executing: ${command.join(' ')}"
+        }
         def process = new ProcessBuilder(command).redirectErrorStream(true).start()
-        process.inputStream.eachLine{
-            if(print){
+        process.inputStream.eachLine {
+            if (print) {
                 println it
             }
             sb.append(it).append("\n")