// Path: src/main/java/io/jafka/utils/Utils.java
// public static int caculateShortString(String topic) {
//     return 2 + getBytes(topic).length;
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static long crc32(byte[] bytes) {
//     return crc32(bytes, 0, bytes.length);
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static boolean getBoolean(Properties props, String name, boolean defaultValue) {
//     if (!props.containsKey(name)) return defaultValue;
//     return "true".equalsIgnoreCase(props.getProperty(name));
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static int getInt(Properties props, String name) {
//     if (props.containsKey(name)) {
//         return getInt(props, name, -1);
//     }
//     throw new IllegalArgumentException("Missing required property '" + name + "'");
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static Properties getProps(Properties props, String name, Properties defaultProperties) {
//     final String propString = props.getProperty(name);
//     if (propString == null) return defaultProperties;
//     String[] propValues = propString.split(",");
//     if (propValues.length < 1) {
//         throw new IllegalArgumentException("Illegal format of specifying properties '" + propString + "'");
//     }
//     Properties properties = new Properties();
//     for (int i = 0; i < propValues.length; i++) {
//         String[] prop = propValues[i].split("=");
//         if (prop.length != 2) throw new IllegalArgumentException("Illegal format of specifying properties '" + propValues[i] + "'");
//         properties.put(prop[0], prop[1]);
//     }
//     return properties;
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static String getString(Properties props, String name, String defaultValue) {
//     return props.containsKey(name) ? props.getProperty(name) : defaultValue;
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static KV<String, Integer> getTopicPartition(String topicPartition) {
//     int index = topicPartition.lastIndexOf('-');
//     return new KV<String, Integer>(topicPartition.substring(0, index),//
//             Integer.valueOf(topicPartition.substring(index + 1)));
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static Map<String, Integer> getTopicRentionHours(String retentionHours) {
//     String exceptionMsg = "Malformed token for topic.log.retention.hours in server.properties: ";
//     String successMsg = "The retention hour for ";
//     return getCSVMap(retentionHours, exceptionMsg, successMsg);
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static Properties loadProps(String filename) {
//     Properties props = new Properties();
//     FileInputStream fis = null;
//     try {
//         fis = new FileInputStream(filename);
//         props.load(fis);
//         return props;
//     } catch (IOException ex) {
//         throw new RuntimeException(ex);
//     } finally {
//         Closer.closeQuietly(fis);
//     }
// 
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static String readShortString(ByteBuffer buffer) {
//     short size = buffer.getShort();
//     if (size < 0) {
//         return null;
//     }
//     byte[] bytes = new byte[size];
//     buffer.get(bytes);
//     return fromBytes(bytes);
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static void writeShortString(ByteBuffer buffer, String s) {
//     if (s == null) {
//         buffer.putShort((short) -1);
//     } else if (s.length() > Short.MAX_VALUE) {
//         throw new IllegalArgumentException("String exceeds the maximum size of " + Short.MAX_VALUE + ".");
//     } else {
//         byte[] data = getBytes(s); //topic support non-ascii character
//         buffer.putShort((short) data.length);
//         buffer.put(data);
//     }
// }


import org.junit.Test;
import static io.jafka.utils.Utils.caculateShortString;
import static io.jafka.utils.Utils.crc32;
import static io.jafka.utils.Utils.getBoolean;
import static io.jafka.utils.Utils.getInt;
import static io.jafka.utils.Utils.getProps;
import static io.jafka.utils.Utils.getString;
import static io.jafka.utils.Utils.getTopicPartition;
import static io.jafka.utils.Utils.getTopicRentionHours;
import static io.jafka.utils.Utils.loadProps;
import static io.jafka.utils.Utils.readShortString;
import static io.jafka.utils.Utils.writeShortString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.nio.ByteBuffer;
import java.util.Map;
import java.util.Properties;
        assertEquals("100",getString(System.getProperties(), "demo.count"));
    }

    /**
     * Test method for {@link Utils#getInt(java.util.Properties, java.lang.String)}.
     */
    @Test
    public void testGetIntPropertiesString() {
        System.setProperty("demo.count", "100");
        assertEquals(100,getInt(System.getProperties(), "demo.count"));
    }

    /**
     * Test method for {@link Utils#getInt(java.util.Properties, java.lang.String, int)}.
     */
    @Test
    public void testGetIntPropertiesStringInt() {
        System.setProperty("demo.count", "100");
        assertEquals(100,getInt(System.getProperties(), "demo.count",200));
        assertEquals(200,getInt(System.getProperties(), "demo.count.noexist",200));
    }


    /**
     * Test method for {@link Utils#getBoolean(java.util.Properties, java.lang.String, boolean)}.
     */
    @Test
    public void testGetBoolean() {
        System.setProperty("demo.boolean", "true");
        assertTrue(getBoolean(System.getProperties(), "demo.boolean", false));
// Path: src/main/java/io/jafka/utils/Utils.java
// public static int caculateShortString(String topic) {
//     return 2 + getBytes(topic).length;
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static long crc32(byte[] bytes) {
//     return crc32(bytes, 0, bytes.length);
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static boolean getBoolean(Properties props, String name, boolean defaultValue) {
//     if (!props.containsKey(name)) return defaultValue;
//     return "true".equalsIgnoreCase(props.getProperty(name));
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static int getInt(Properties props, String name) {
//     if (props.containsKey(name)) {
//         return getInt(props, name, -1);
//     }
//     throw new IllegalArgumentException("Missing required property '" + name + "'");
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static Properties getProps(Properties props, String name, Properties defaultProperties) {
//     final String propString = props.getProperty(name);
//     if (propString == null) return defaultProperties;
//     String[] propValues = propString.split(",");
//     if (propValues.length < 1) {
//         throw new IllegalArgumentException("Illegal format of specifying properties '" + propString + "'");
//     }
//     Properties properties = new Properties();
//     for (int i = 0; i < propValues.length; i++) {
//         String[] prop = propValues[i].split("=");
//         if (prop.length != 2) throw new IllegalArgumentException("Illegal format of specifying properties '" + propValues[i] + "'");
//         properties.put(prop[0], prop[1]);
//     }
//     return properties;
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static String getString(Properties props, String name, String defaultValue) {
//     return props.containsKey(name) ? props.getProperty(name) : defaultValue;
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static KV<String, Integer> getTopicPartition(String topicPartition) {
//     int index = topicPartition.lastIndexOf('-');
//     return new KV<String, Integer>(topicPartition.substring(0, index),//
//             Integer.valueOf(topicPartition.substring(index + 1)));
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static Map<String, Integer> getTopicRentionHours(String retentionHours) {
//     String exceptionMsg = "Malformed token for topic.log.retention.hours in server.properties: ";
//     String successMsg = "The retention hour for ";
//     return getCSVMap(retentionHours, exceptionMsg, successMsg);
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static Properties loadProps(String filename) {
//     Properties props = new Properties();
//     FileInputStream fis = null;
//     try {
//         fis = new FileInputStream(filename);
//         props.load(fis);
//         return props;
//     } catch (IOException ex) {
//         throw new RuntimeException(ex);
//     } finally {
//         Closer.closeQuietly(fis);
//     }
// 
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static String readShortString(ByteBuffer buffer) {
//     short size = buffer.getShort();
//     if (size < 0) {
//         return null;
//     }
//     byte[] bytes = new byte[size];
//     buffer.get(bytes);
//     return fromBytes(bytes);
// }
// 
// Path: src/main/java/io/jafka/utils/Utils.java
// public static void writeShortString(ByteBuffer buffer, String s) {
//     if (s == null) {
//         buffer.putShort((short) -1);
//     } else if (s.length() > Short.MAX_VALUE) {
//         throw new IllegalArgumentException("String exceeds the maximum size of " + Short.MAX_VALUE + ".");
//     } else {
//         byte[] data = getBytes(s); //topic support non-ascii character
//         buffer.putShort((short) data.length);
//         buffer.put(data);
//     }
// }


// Path: src/test/java/io/jafka/utils/UtilsTest.java
import org.junit.Test;
import static io.jafka.utils.Utils.caculateShortString;
import static io.jafka.utils.Utils.crc32;
import static io.jafka.utils.Utils.getBoolean;
import static io.jafka.utils.Utils.getInt;
import static io.jafka.utils.Utils.getProps;
import static io.jafka.utils.Utils.getString;
import static io.jafka.utils.Utils.getTopicPartition;
import static io.jafka.utils.Utils.getTopicRentionHours;
import static io.jafka.utils.Utils.loadProps;
import static io.jafka.utils.Utils.readShortString;
import static io.jafka.utils.Utils.writeShortString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.nio.ByteBuffer;
import java.util.Map;
import java.util.Properties;

        assertEquals("100",getString(System.getProperties(), "demo.count"));
    }

    /**
     * Test method for {@link Utils#getInt(java.util.Properties, java.lang.String)}.
     */
    @Test
    public void testGetIntPropertiesString() {
        System.setProperty("demo.count", "100");
        assertEquals(100,getInt(System.getProperties(), "demo.count"));
    }

    /**
     * Test method for {@link Utils#getInt(java.util.Properties, java.lang.String, int)}.
     */
    @Test
    public void testGetIntPropertiesStringInt() {
        System.setProperty("demo.count", "100");
        assertEquals(100,getInt(System.getProperties(), "demo.count",200));
        assertEquals(200,getInt(System.getProperties(), "demo.count.noexist",200));
    }


    /**
     * Test method for {@link Utils#getBoolean(java.util.Properties, java.lang.String, boolean)}.
     */
    @Test
    public void testGetBoolean() {
        System.setProperty("demo.boolean", "true");
        assertTrue(getBoolean(System.getProperties(), "demo.boolean", false));
        assertTrue(getBoolean(System.getProperties(), "demo.boolean.notexist", true));