Example usage for java.lang String indexOf

List of usage examples for java.lang String indexOf

Introduction

In this page you can find the example usage for java.lang String indexOf.

Prototype

public int indexOf(String str) 

Source Link

Document

Returns the index within this string of the first occurrence of the specified substring.

Usage

From source file:org.eclipse.swt.snippets.Snippet356.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 356");
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 10;
    shell.setLayout(layout);//from  www.  j ava 2  s  . co  m

    String string = "This is sample text with a link and some other link here.";
    final StyledText styledText = new StyledText(shell, SWT.MULTI | SWT.BORDER);
    styledText.setText(string);

    String link1 = "link";
    String link2 = "here";
    StyleRange style = new StyleRange();
    style.underline = true;
    style.underlineStyle = SWT.UNDERLINE_LINK;

    int[] ranges = { string.indexOf(link1), link1.length(), string.indexOf(link2), link2.length() };
    StyleRange[] styles = { style, style };
    styledText.setStyleRanges(ranges, styles);

    styledText.addListener(SWT.MouseDown, event -> {
        // It is up to the application to determine when and how a link should be activated.
        // In this snippet links are activated on mouse down when the control key is held down
        if ((event.stateMask & SWT.MOD1) != 0) {
            int offset = styledText.getOffsetAtPoint(new Point(event.x, event.y));
            if (offset != -1) {
                StyleRange style1 = null;
                try {
                    style1 = styledText.getStyleRangeAtOffset(offset);
                } catch (IllegalArgumentException e) {
                    // no character under event.x, event.y
                }
                if (style1 != null && style1.underline && style1.underlineStyle == SWT.UNDERLINE_LINK) {
                    System.out.println("Click on a Link");
                }
            }
        }
    });
    shell.setSize(600, 400);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:com.glaf.jbpm.action.MultiPooledTaskInstanceAction.java

public static void main(String[] args) throws Exception {
    String actorIdxy = "{joy,sam},{pp,qq},{kit,cora},{eyb2000,huangcw}";
    StringTokenizer st2 = new StringTokenizer(actorIdxy, ";");
    while (st2.hasMoreTokens()) {
        String elem2 = st2.nextToken();
        if (StringUtils.isNotEmpty(elem2)) {
            elem2 = elem2.trim();//from  www  . jav  a 2s .co m
            if ((elem2.length() > 0 && elem2.charAt(0) == '{') && elem2.endsWith("}")) {
                elem2 = elem2.substring(elem2.indexOf("{") + 1, elem2.indexOf("}"));
                Set<String> actorIds = new HashSet<String>();
                StringTokenizer st4 = new StringTokenizer(elem2, ",");
                while (st4.hasMoreTokens()) {
                    String elem4 = st4.nextToken();
                    elem4 = elem4.trim();
                    if (elem4.length() > 0) {
                        actorIds.add(elem4);
                    }
                }
                System.out.println(actorIds);
            }
        }
    }
}

From source file:DateParse2.java

public static void main(String[] args) {

    //+/*from   w w w . j  a v a  2 s  .  c om*/
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    String input[] = { "BD: 1913-10-01 Vancouver, B.C.", "MD: 1948-03-01 Ottawa, ON",
            "DD: 1983-06-06 Toronto, ON" };
    for (int i = 0; i < input.length; i++) {
        String aLine = input[i];
        String action;
        switch (aLine.charAt(0)) {
        case 'B':
            action = "Born";
            break;
        case 'M':
            action = "Married";
            break;
        case 'D':
            action = "Died";
            break;
        // others...
        default:
            System.err.println("Invalid code in " + aLine);
            continue;
        }
        int p = aLine.indexOf(' ');
        ParsePosition pp = new ParsePosition(p);
        Date d = formatter.parse(aLine, pp);
        if (d == null) {
            System.err.println("Invalid date in " + aLine);
            continue;
        }
        String location = aLine.substring(pp.getIndex());
        System.out.println(action + " on " + d + " in " + location);
    }
    //-
}

From source file:ac.elements.parser.SimpleDBConverter.java

public static void main(String[] args) {
    String date = SimpleDBConverter.encodeDate(new Date(3453l));
    System.out.println(date);// www  . j a  v  a2 s.c o m
    System.out.println(date.indexOf('-'));
    System.out.println(date.indexOf('-', 5));
    System.out.println(date.indexOf('T'));
    System.out.println(date.indexOf(':'));
    System.out.println(date.indexOf(':', 14));
    System.out.println(date.indexOf('.'));
    System.out.println(date.indexOf('+'));
    boolean boodate = false;
    if (date.indexOf('-') == 4 && date.indexOf('-', 5) == 7 && date.indexOf('T') == 10
            && date.indexOf(':') == 13 && date.indexOf(':', 14) == 16 && date.indexOf('.') == 19
            && date.indexOf('+') == 23) {
        boodate = true;
    }
    System.out.println(boodate);

    System.out.println(getStringOrNumber("00.4") instanceof Float);
    System.out.println(getStringOrNumber("00.4d") instanceof Double);
    System.out.println(getStringOrNumber("4d") instanceof Double);
    System.out.println(getStringOrNumber("4f") instanceof Float);
    System.out.println(getStringOrNumber("4L") instanceof Long);
    System.out.println(getStringOrNumber("4l") instanceof Long);
    System.out.println(getStringOrNumber("4") instanceof Integer);
    System.out.println(getStringOrNumber("213 maximind") instanceof String);

}

From source file:net.sourceforge.doddle_owl.data.JpnWordNetDic.java

public static void main(String[] args) throws Exception {
    JpnWordNetDic.initJPNWNDic();/*from   w ww.j  a va  2s .  c om*/
    String id1 = "08675967-n";
    // String id1 = "JPNWN_ROOT";

    Concept c = JpnWordNetDic.getConcept(id1);
    System.out.println(c);

    Set<String> idSet = new HashSet<String>();
    BufferedReader reader = new BufferedReader(
            new InputStreamReader(new FileInputStream(DODDLEConstants.JPWN_HOME + "tree.data"), "UTF-8"));
    while (reader.ready()) {
        String line = reader.readLine();
        if (line.indexOf(id1) != -1) {
            String id = line.split("\t\\|")[0];
            idSet.add(id);
        }
    }
    System.out.println(idSet);
    for (String id : idSet) {
        c = JpnWordNetDic.getConcept(id);
        System.out.println(c);
    }
}

From source file:com.joliciel.frenchTreebank.FrenchTreebank.java

/**
 * @param args/*from ww w  .  ja  v a 2s .  c o  m*/
 */
public static void main(String[] args) throws Exception {
    String command = args[0];

    String outFilePath = "";
    String outDirPath = "";
    String treebankPath = "";
    String ftbFileName = "";
    String rawTextDir = "";
    String queryPath = "";
    String sentenceNumber = null;
    boolean firstArg = true;
    for (String arg : args) {
        if (firstArg) {
            firstArg = false;
            continue;
        }
        int equalsPos = arg.indexOf('=');
        String argName = arg.substring(0, equalsPos);
        String argValue = arg.substring(equalsPos + 1);
        if (argName.equals("outfile"))
            outFilePath = argValue;
        else if (argName.equals("outdir"))
            outDirPath = argValue;
        else if (argName.equals("ftbFileName"))
            ftbFileName = argValue;
        else if (argName.equals("treebank"))
            treebankPath = argValue;
        else if (argName.equals("sentence"))
            sentenceNumber = argValue;
        else if (argName.equals("query"))
            queryPath = argValue;
        else if (argName.equals("rawTextDir"))
            rawTextDir = argValue;
        else
            throw new RuntimeException("Unknown argument: " + argName);
    }

    TalismaneServiceLocator talismaneServiceLocator = TalismaneServiceLocator.getInstance();

    TreebankServiceLocator locator = TreebankServiceLocator.getInstance(talismaneServiceLocator);

    if (treebankPath.length() == 0)
        locator.setDataSourcePropertiesFile("jdbc-live.properties");

    if (command.equals("search")) {
        final SearchService searchService = locator.getSearchService();
        final XmlPatternSearch search = searchService.newXmlPatternSearch();
        search.setXmlPatternFile(queryPath);
        List<SearchResult> searchResults = search.perform();

        FileWriter fileWriter = new FileWriter(outFilePath);
        for (SearchResult searchResult : searchResults) {
            String lineToWrite = "";
            Sentence sentence = searchResult.getSentence();
            Phrase phrase = searchResult.getPhrase();
            lineToWrite += sentence.getFile().getFileName() + "|";
            lineToWrite += sentence.getSentenceNumber() + "|";
            List<PhraseUnit> phraseUnits = searchResult.getPhraseUnits();
            LOG.debug("Phrase: " + phrase.getId());
            for (PhraseUnit phraseUnit : phraseUnits)
                lineToWrite += phraseUnit.getLemma().getText() + "|";
            lineToWrite += phrase.getText();
            fileWriter.write(lineToWrite + "\n");
        }
        fileWriter.flush();
        fileWriter.close();
    } else if (command.equals("load")) {
        final TreebankService treebankService = locator.getTreebankService();
        final TreebankSAXParser parser = new TreebankSAXParser();
        parser.setTreebankService(treebankService);
        parser.parseDocument(treebankPath);
    } else if (command.equals("loadAll")) {
        final TreebankService treebankService = locator.getTreebankService();

        File dir = new File(treebankPath);

        String firstFile = null;
        if (args.length > 2)
            firstFile = args[2];
        String[] files = dir.list();
        if (files == null) {
            throw new RuntimeException("Not a directory or no children: " + treebankPath);
        } else {
            boolean startProcessing = true;
            if (firstFile != null)
                startProcessing = false;
            for (int i = 0; i < files.length; i++) {
                if (!startProcessing && files[i].equals(firstFile))
                    startProcessing = true;
                if (startProcessing) {
                    String filePath = args[1] + "/" + files[i];
                    LOG.debug(filePath);
                    final TreebankSAXParser parser = new TreebankSAXParser();
                    parser.setTreebankService(treebankService);
                    parser.parseDocument(filePath);
                }
            }
        }
    } else if (command.equals("loadRawText")) {
        final TreebankService treebankService = locator.getTreebankService();
        final TreebankRawTextAssigner assigner = new TreebankRawTextAssigner();
        assigner.setTreebankService(treebankService);
        assigner.setRawTextDirectory(rawTextDir);
        assigner.loadRawText();
    } else if (command.equals("tokenize")) {
        Writer csvFileWriter = null;
        if (outFilePath != null && outFilePath.length() > 0) {
            if (outFilePath.lastIndexOf("/") > 0) {
                String outputDirPath = outFilePath.substring(0, outFilePath.lastIndexOf("/"));
                File outputDir = new File(outputDirPath);
                outputDir.mkdirs();
            }

            File csvFile = new File(outFilePath);
            csvFile.delete();
            csvFile.createNewFile();
            csvFileWriter = new BufferedWriter(
                    new OutputStreamWriter(new FileOutputStream(csvFile, false), "UTF8"));
        }
        try {

            final TreebankService treebankService = locator.getTreebankService();
            TreebankExportService treebankExportService = locator.getTreebankExportServiceLocator()
                    .getTreebankExportService();
            TreebankUploadService treebankUploadService = locator.getTreebankUploadServiceLocator()
                    .getTreebankUploadService();
            TreebankReader treebankReader = null;

            if (treebankPath.length() > 0) {
                File treebankFile = new File(treebankPath);
                if (sentenceNumber != null)
                    treebankReader = treebankUploadService.getXmlReader(treebankFile, sentenceNumber);
                else
                    treebankReader = treebankUploadService.getXmlReader(treebankFile);

            } else {
                treebankReader = treebankService.getDatabaseReader(TreebankSubSet.ALL, 0);
            }

            TokeniserAnnotatedCorpusReader reader = treebankExportService
                    .getTokeniserAnnotatedCorpusReader(treebankReader, csvFileWriter);

            while (reader.hasNextTokenSequence()) {
                TokenSequence tokenSequence = reader.nextTokenSequence();
                List<Integer> tokenSplits = tokenSequence.getTokenSplits();
                String sentence = tokenSequence.getText();
                LOG.debug(sentence);
                int currentPos = 0;
                StringBuilder sb = new StringBuilder();
                for (int split : tokenSplits) {
                    if (split == 0)
                        continue;
                    String token = sentence.substring(currentPos, split);
                    sb.append('|');
                    sb.append(token);
                    currentPos = split;
                }
                LOG.debug(sb.toString());
            }
        } finally {
            csvFileWriter.flush();
            csvFileWriter.close();
        }
    } else if (command.equals("export")) {
        if (outDirPath.length() == 0)
            throw new RuntimeException("Parameter required: outdir");
        File outDir = new File(outDirPath);
        outDir.mkdirs();

        final TreebankService treebankService = locator.getTreebankService();
        FrenchTreebankXmlWriter xmlWriter = new FrenchTreebankXmlWriter();
        xmlWriter.setTreebankService(treebankService);

        if (ftbFileName.length() == 0) {
            xmlWriter.write(outDir);
        } else {
            TreebankFile ftbFile = treebankService.loadTreebankFile(ftbFileName);
            String fileName = ftbFileName.substring(ftbFileName.lastIndexOf('/') + 1);
            File xmlFile = new File(outDir, fileName);
            xmlFile.delete();
            xmlFile.createNewFile();

            Writer xmlFileWriter = new BufferedWriter(
                    new OutputStreamWriter(new FileOutputStream(xmlFile, false), "UTF8"));
            xmlWriter.write(xmlFileWriter, ftbFile);
            xmlFileWriter.flush();
            xmlFileWriter.close();
        }
    } else {
        throw new RuntimeException("Unknown command: " + command);
    }
    LOG.debug("========== END ============");
}

From source file:fr.jayasoft.ivy.Main.java

public static void main(String[] args) throws Exception {
    Options options = getOptions();//from   www. j a  v a 2s. c  o  m

    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("?")) {
            usage(options);
            return;
        }

        if (line.hasOption("debug")) {
            Message.init(new DefaultMessageImpl(Message.MSG_DEBUG));
        } else if (line.hasOption("verbose")) {
            Message.init(new DefaultMessageImpl(Message.MSG_VERBOSE));
        } else if (line.hasOption("warn")) {
            Message.init(new DefaultMessageImpl(Message.MSG_WARN));
        } else if (line.hasOption("error")) {
            Message.init(new DefaultMessageImpl(Message.MSG_ERR));
        } else {
            Message.init(new DefaultMessageImpl(Message.MSG_INFO));
        }

        boolean validate = line.hasOption("novalidate") ? false : true;

        Ivy ivy = new Ivy();
        ivy.addAllVariables(System.getProperties());
        if (line.hasOption("m2compatible")) {
            ivy.setVariable("ivy.default.configuration.m2compatible", "true");
        }

        configureURLHandler(line.getOptionValue("realm", null), line.getOptionValue("host", null),
                line.getOptionValue("username", null), line.getOptionValue("passwd", null));

        String confPath = line.getOptionValue("conf", "");
        if ("".equals(confPath)) {
            ivy.configureDefault();
        } else {
            File conffile = new File(confPath);
            if (!conffile.exists()) {
                error(options, "ivy configuration file not found: " + conffile);
            } else if (conffile.isDirectory()) {
                error(options, "ivy configuration file is not a file: " + conffile);
            }
            ivy.configure(conffile);
        }

        File cache = new File(
                ivy.substitute(line.getOptionValue("cache", ivy.getDefaultCache().getAbsolutePath())));
        if (!cache.exists()) {
            cache.mkdirs();
        } else if (!cache.isDirectory()) {
            error(options, cache + " is not a directory");
        }

        String[] confs;
        if (line.hasOption("confs")) {
            confs = line.getOptionValues("confs");
        } else {
            confs = new String[] { "*" };
        }

        File ivyfile;
        if (line.hasOption("dependency")) {
            String[] dep = line.getOptionValues("dependency");
            if (dep.length != 3) {
                error(options,
                        "dependency should be expressed with exactly 3 arguments: organisation module revision");
            }
            ivyfile = File.createTempFile("ivy", ".xml");
            ivyfile.deleteOnExit();
            DefaultModuleDescriptor md = DefaultModuleDescriptor
                    .newDefaultInstance(ModuleRevisionId.newInstance(dep[0], dep[1] + "-caller", "working"));
            DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md,
                    ModuleRevisionId.newInstance(dep[0], dep[1], dep[2]), false, false, true);
            for (int i = 0; i < confs.length; i++) {
                dd.addDependencyConfiguration("default", confs[i]);
            }
            md.addDependency(dd);
            XmlModuleDescriptorWriter.write(md, ivyfile);
            confs = new String[] { "default" };
        } else {
            ivyfile = new File(ivy.substitute(line.getOptionValue("ivy", "ivy.xml")));
            if (!ivyfile.exists()) {
                error(options, "ivy file not found: " + ivyfile);
            } else if (ivyfile.isDirectory()) {
                error(options, "ivy file is not a file: " + ivyfile);
            }
        }

        ResolveReport report = ivy.resolve(ivyfile.toURL(), null, confs, cache, null, validate, false, true,
                line.hasOption("useOrigin"), null);
        if (report.hasError()) {
            System.exit(1);
        }
        ModuleDescriptor md = report.getModuleDescriptor();

        if (confs.length == 1 && "*".equals(confs[0])) {
            confs = md.getConfigurationsNames();
        }
        if (line.hasOption("retrieve")) {
            String retrievePattern = ivy.substitute(line.getOptionValue("retrieve"));
            if (retrievePattern.indexOf("[") == -1) {
                retrievePattern = retrievePattern + "/lib/[conf]/[artifact].[ext]";
            }
            ivy.retrieve(md.getModuleRevisionId().getModuleId(), confs, cache, retrievePattern, null, null,
                    line.hasOption("sync"), line.hasOption("useOrigin"));
        }
        if (line.hasOption("cachepath")) {
            outputCachePath(ivy, cache, md, confs, line.getOptionValue("cachepath", "ivycachepath.txt"));
        }

        if (line.hasOption("revision")) {
            ivy.deliver(md.getResolvedModuleRevisionId(), ivy.substitute(line.getOptionValue("revision")),
                    cache, ivy.substitute(line.getOptionValue("deliverto", "ivy-[revision].xml")),
                    ivy.substitute(line.getOptionValue("status", "release")), null,
                    new DefaultPublishingDRResolver(), validate);
            if (line.hasOption("publish")) {
                ivy.publish(md.getResolvedModuleRevisionId(), ivy.substitute(line.getOptionValue("revision")),
                        cache,
                        ivy.substitute(line.getOptionValue("publishpattern",
                                "distrib/[type]s/[artifact]-[revision].[ext]")),
                        line.getOptionValue("publish"),
                        ivy.substitute(line.getOptionValue("deliverto", "ivy-[revision].xml")), validate);

            }
        }
        if (line.hasOption("main")) {
            invoke(ivy, cache, md, confs, line.getOptionValue("main"), line.getOptionValues("args"));
        }
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());

        usage(options);
    }
}

From source file:SyntaxColoring.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);

    final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);

    final String PUNCTUATION = "(){}";
    styledText.addExtendedModifyListener(new ExtendedModifyListener() {
        public void modifyText(ExtendedModifyEvent event) {
            int end = event.start + event.length - 1;

            if (event.start <= end) {
                String text = styledText.getText(event.start, end);
                java.util.List ranges = new java.util.ArrayList();

                for (int i = 0, n = text.length(); i < n; i++) {
                    if (PUNCTUATION.indexOf(text.charAt(i)) > -1) {
                        ranges.add(new StyleRange(event.start + i, 1, display.getSystemColor(SWT.COLOR_BLUE),
                                null, SWT.BOLD));
                    }/*from  ww w. j  a  v  a 2s . com*/
                }
                if (!ranges.isEmpty()) {
                    styledText.replaceStyleRanges(event.start, event.length,
                            (StyleRange[]) ranges.toArray(new StyleRange[0]));
                }
            }
        }
    });

    styledText.setBounds(10, 10, 500, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:com.recomdata.datasetexplorer.proxy.XmlHttpProxy.java

/**
*
* CLI to the XmlHttpProxy//from  ww w  .  j  a  va2 s. co  m
*/
public static void main(String[] args) throws IOException, MalformedURLException {

    getLogger().info("XmlHttpProxy 1.1");
    XmlHttpProxy xhp = new XmlHttpProxy();

    if (args.length == 0) {
        System.out.println(USAGE);
    }

    InputStream xslInputStream = null;
    String serviceKey = null;
    String urlString = null;
    String xslURLString = null;
    String format = "xml";
    String callback = null;
    String urlParams = null;
    String configURLString = "xhp.json";
    String resourceBase = "file:src/conf/META-INF/resources/xsl/";

    // read in the arguments
    int index = 0;
    while (index < args.length) {
        if (args[index].toLowerCase().equals("-url") && index + 1 < args.length) {
            urlString = args[++index];
        } else if (args[index].toLowerCase().equals("-key") && index + 1 < args.length) {
            serviceKey = args[++index];
        } else if (args[index].toLowerCase().equals("-id") && index + 1 < args.length) {
            serviceKey = args[++index];
        } else if (args[index].toLowerCase().equals("-callback") && index + 1 < args.length) {
            callback = args[++index];
        } else if (args[index].toLowerCase().equals("-xslurl") && index + 1 < args.length) {
            xslURLString = args[++index];
        } else if (args[index].toLowerCase().equals("-urlparams") && index + 1 < args.length) {
            urlParams = args[++index];
        } else if (args[index].toLowerCase().equals("-config") && index + 1 < args.length) {
            configURLString = args[++index];
        } else if (args[index].toLowerCase().equals("-resources") && index + 1 < args.length) {
            resourceBase = args[++index];
        }
        index++;
    }

    if (serviceKey != null) {
        try {
            InputStream is = (new URL(configURLString)).openStream();
            JSONObject services = loadServices(is);
            JSONObject service = services.getJSONObject(serviceKey);
            // default to the service default if no url parameters are specified
            if (urlParams == null && service.has("defaultURLParams")) {
                urlParams = service.getString("defaultURLParams");
            }
            String serviceURL = service.getString("url");
            // build the URL properly
            if (urlParams != null && serviceURL.indexOf("?") == -1) {
                serviceURL += "?";
            } else if (urlParams != null) {
                serviceURL += "&";
            }
            urlString = serviceURL + service.getString("apikey") + "&" + urlParams;
            if (service.has("xslStyleSheet")) {
                xslURLString = service.getString("xslStyleSheet");
                // check if the url is correct of if to load from the classpath

            }
        } catch (Exception ex) {
            getLogger().severe("XmlHttpProxy Error loading service: " + ex);
            System.exit(1);
        }
    } else if (urlString == null) {
        System.out.println(USAGE);
        System.exit(1);
    }
    // The parameters are feed to the XSL Stylsheet during transformation.
    // These parameters can provided data or conditional information.
    Map paramsMap = new HashMap();
    if (format != null) {
        paramsMap.put("format", format);
    }
    if (callback != null) {
        paramsMap.put("callback", callback);
    }

    if (xslURLString != null) {
        URL xslURL = new URL(xslURLString);
        if (xslURL != null) {
            xslInputStream = xslURL.openStream();
        } else {
            getLogger().severe("Error: Unable to locate XSL at URL " + xslURLString);
        }
    }
    xhp.doGet(urlString, System.out, xslInputStream, paramsMap);
}

From source file:Hex.java

public static void main(String[] args) {
    boolean printData = false;
    int randomLimit = 500;

    for (int myCount = 0; myCount < 10000; myCount++) {
        byte raw[] = new byte[(int) (Math.random() * randomLimit)];

        for (int i = 0; i < raw.length; ++i) {
            if ((i % 1024) < 256)
                raw[i] = (byte) (i % 1024);
            else/*from   w  w  w. j  a  v a  2  s  .  c  o m*/
                raw[i] = (byte) ((int) (Math.random() * 255) - 128);
        }
        Hex.Encoder encoder = new Hex.Encoder(100);
        encoder.encode(raw);

        String encoded = encoder.drain();

        Hex.Decoder decoder = new Hex.Decoder();
        decoder.decode(encoded);
        byte check[] = decoder.flush();

        String mesg = "Success!";
        if (check.length != raw.length) {
            mesg = "***** length mismatch!";
        } else {
            for (int i = 0; i < check.length; ++i) {
                if (check[i] != raw[i]) {
                    mesg = "***** data mismatch!";
                    break;
                }
            }
        }
        if (mesg.indexOf("Success") == -1) {
            System.out.println(mesg + myCount);
            break;
        }

        if (printData) {
            System.out.println("Decoded: " + new String(raw));
            System.out.println("Encoded: " + encoded);
            System.out.println("Decoded: " + new String(check));
        }
    }
}