src/main/java/j2html/utils/CSSMin.java
public static String compressCss(String input) {
        try {
            int k,
                j, // Number of open braces
                n; // Current position in stream
            char curr;

            BufferedReader br = new BufferedReader(new StringReader(input));
            StringBuilder sb = new StringBuilder();

            if (debugLogging) {
                LOG.info("Reading file into StringBuffer...");
            }
            String s;
            while ((s = br.readLine()) != null) {
                if (s.trim().equals("")) {
                    continue;
                }
                sb.append(s);
            }

            if (debugLogging) {
                LOG.info("Removing comments...");
            }
            // Find the start of the comment
            n = 0;
            while ((n = sb.indexOf("/*", n)) != -1) {
                if (sb.charAt(n + 2) == '*') { // Retain special comments
                    n += 2;
                    continue;
                }
                k = sb.indexOf("*/", n + 2);
                if (k == -1) {
                    throw new UnterminatedCommentException();
                }
                sb.delete(n, k + 2);
            }
            if (debugLogging) {
                LOG.info(sb.toString());
                LOG.info("\n\n");
            }

            if (debugLogging) {
                LOG.info("Parsing and processing selectors...");
            }
            Vector<Selector> selectors = new Vector<>();
            n = 0;
            j = 0;
            for (int i = 0; i < sb.length(); i++) {
                curr = sb.charAt(i);
                if (j < 0) {
                    throw new UnbalancedBracesException();
                }
                if (curr == '{') {
                    j++;
                } else if (curr == '}') {
                    j--;
                    if (j == 0) {
                        try {
                            selectors.addElement(new Selector(sb.substring(n, i + 1)));
                        } catch (UnterminatedSelectorException usex) {
                            LOG.warning("Unterminated selector: " + usex.getMessage());
                        } catch (EmptySelectorBodyException ebex) {
                            if (debugLogging) {
                                LOG.warning("Empty selector body: " + ebex.getMessage());
                            }
                        }
                        n = i + 1;
                    }
                }
            }

            StringBuilder result = new StringBuilder();

            for (Selector selector : selectors) {
                result.append(selector);
            }

            if (debugLogging) {
                LOG.info("Process completed successfully.");
            }

            return result.toString();

        } catch (UnterminatedCommentException ucex) {
            LOG.warning("Unterminated comment.");
        } catch (UnbalancedBracesException ubex) {
            LOG.warning("Unbalanced braces.");
        } catch (Exception ex) {
            LOG.warning(ex.getMessage());
        }

        return null;

    }
public static String compressCss(String input) {
        try {
            int k,
                j, // Number of open braces
                n; // Current position in stream
            char curr;

            BufferedReader br = new BufferedReader(new StringReader(input));
            StringBuilder sb = new StringBuilder();

            if (debugLogging) {
                LOG.info("Reading file into StringBuffer...");
            }
            String s;
            while ((s = br.readLine()) != null) {
                if (s.trim().equals("")) {
                    continue;
                }
                sb.append(s);
            }

            if (debugLogging) {
                LOG.info("Removing comments...");
            }
            // Find the start of the comment
            n = 0;
            while ((n = sb.indexOf("/*", n)) != -1) {
                if (sb.charAt(n + 2) == '*') { // Retain special comments
                    n += 2;
                    continue;
                }
                k = sb.indexOf("*/", n + 2);
                if (k == -1) {
                    throw new UnterminatedCommentException();
                }
                sb.delete(n, k + 2);
            }
            if (debugLogging) {
                LOG.info(sb.toString());
                LOG.info("\n\n");
            }

            if (debugLogging) {
                LOG.info("Parsing and processing selectors...");
            }
            Vector<Selector> selectors = new Vector<>();
            n = 0;
            j = 0;
            for (int i = 0; i < sb.length(); i++) {
                curr = sb.charAt(i);
                if (j < 0) {
                    throw new UnbalancedBracesException();
                }
                if (curr == '{') {
                    j++;
                } else if (curr == '}') {
                    j--;
                    if (j == 0) {
                        try {
                            selectors.addElement(new Selector(sb.substring(n, i + 1)));
                        } catch (UnterminatedSelectorException usex) {
                            LOG.warning("Unterminated selector: " + usex.getMessage());
                        } catch (EmptySelectorBodyException ebex) {
                            if (debugLogging) {
                                LOG.warning("Empty selector body: " + ebex.getMessage());
                            }
                        }
                        n = i + 1;
                    }
                }
            }

            StringBuilder result = new StringBuilder();

            for (Selector selector : selectors) {
                result.append(selector);
            }

            if (debugLogging) {
                LOG.info("Process completed successfully.");
            }

            return result.toString();

        } catch (UnterminatedCommentException ucex) {
            LOG.warning("Unterminated comment.");
        } catch (UnbalancedBracesException ubex) {
            LOG.warning("Unbalanced braces.");
        } catch (Exception ex) {
            LOG.warning(ex.getMessage());
        }

        return null;

    }
Minify supplied CSS.

@param input the CSS
@return the compressed version