<commit_before>
/*
 * Copyright (C) 2009 <NAME>. All rights reserved.
 *
 * $Id$
 */

package org.dellroad.lzma.demo.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
//import com.google.gwt.event.dom.client.ChangeEvent;
//import com.google.gwt.event.dom.client.ChangeHandler;
//import com.google.gwt.event.dom.client.ClickEvent;
//import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.CommandCanceledException;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.IncrementalCommand;
//import com.google.gwt.user.client.ui.Button;
//import com.google.gwt.user.client.ui.HorizontalPanel;
//import com.google.gwt.user.client.ui.Label;
//import com.google.gwt.user.client.ui.ListBox;
//import com.google.gwt.user.client.ui.RootPanel;
//import com.google.gwt.user.client.ui.SimplePanel;
//import com.google.gwt.user.client.ui.TextArea;
//import com.google.gwt.user.client.ui.VerticalPanel;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.dellroad.lzma.client.CompressionMode;
import org.dellroad.lzma.client.LZMAByteArrayCompressor;
import org.dellroad.lzma.client.LZMAByteArrayDecompressor;
import org.dellroad.lzma.client.UTF8;

public class LZMADemo implements EntryPoint {

    private static final CompressionMode DEFAULT_COMPRESSION_MODE = CompressionMode.MODE_1;

//    private final TextArea leftWindow = new TextArea();
//    private final TextArea rightWindow = new TextArea();

//    private final SimplePanel leftSizePanel = new SimplePanel();
//    private final SimplePanel rightSizePanel = new SimplePanel();

    private CompressionMode mode = DEFAULT_COMPRESSION_MODE;

    private boolean compressing;

    public LZMADemo() {
//        this.leftWindow.setCharacterWidth(70);
//        this.leftWindow.setVisibleLines(25);
//        this.rightWindow.setCharacterWidth(70);
//        this.rightWindow.setVisibleLines(25);
    }


    public void compress() {
//        this.rightWindow.setText("");
//        updateSizes(false);
//        this.rightSizePanel.setWidget(new Label("Compressing... 0%"));
//        this.compressing = true;
        DeferredCommand.addCommand(new IncrementalCommand() {
            LZMAByteArrayCompressor c;
            public boolean execute() {
                if (c == null) {
                    //c = new LZMAByteArrayCompressor(UTF8.encode(LZMADemo.this.leftWindow.getText()), LZMADemo.this.mode);
                    c = new LZMAByteArrayCompressor(UTF8.encode("sample_enc"), LZMADemo.this.mode);
                    return true;
                }
                if (c.execute()) {
//                    int pcent = (int)(c.getProgress() * 100.0);
//                    LZMADemo.this.rightSizePanel.setWidget(new Label("Compressing... " + pcent + "%"));
                    return true;
                }
//                setRightData(c.getCompressedData());
//                updateSizes(true);
                alert(c.getCompressedData());
                return false;
            }
        });
    }

    public void decompress() {

        // Get binary data
//        this.leftWindow.setText("");
//        updateSizes(false);
        final byte[] data = new byte[] {93, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 48, (byte)193, (byte)251, (byte)255, (byte)255, (byte)255, (byte)224, 0, 0, 0};
        //if (data == null)
        //    return;

        // Decompress it
        //this.leftSizePanel.setWidget(new Label("Decompressing... 0%"));
        //this.compressing = false;
        DeferredCommand.addCommand(new IncrementalCommand() {
            LZMAByteArrayDecompressor d;
            public boolean execute() {
                if (d == null) {
                    try {
                        d = new LZMAByteArrayDecompressor(data);
                    } catch (IOException e) {
                        //LZMADemo.this.leftSizePanel.setWidget(new Label("Decompression failed: " + e.getMessage()));
                        alert("Decompression failed: " + e.getMessage());
                        return false;
                    }
                    return true;
                }
                if (d.execute()) {
                    //int pcent = (int)(d.getProgress() * 100.0);
                    //LZMADemo.this.leftSizePanel.setWidget(new Label("Decompressing... " + pcent + "%"));
                    return true;
                }
                IOException ioe = d.getException();
                if (ioe != null) {
                    //LZMADemo.this.leftSizePanel.setWidget(new Label("Decompression failed: " + ioe.getMessage()));
                    alert("Decompression failed: " + ioe.getMessage());
                    return false;
                }
                String text;
                try {
                    text = UTF8.decode(d.getUncompressedData());
                } catch (IllegalArgumentException e) {
                    //LZMADemo.this.leftSizePanel.setWidget(new Label("Decompression failed: " + e.getMessage()));
                    alert("Decompression failed: " + ioe.getMessage());
                    return false;
                }
                //LZMADemo.this.leftWindow.setText(text);
                alert(text);
                //updateSizes(true);
                return false;<commit_msg>Fixed minor bug.<commit_after>
/*
 * Copyright (C) 2009 <NAME>. All rights reserved.
 *
 * $Id$
 */

package org.dellroad.lzma.demo.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
//import com.google.gwt.event.dom.client.ChangeEvent;
//import com.google.gwt.event.dom.client.ChangeHandler;
//import com.google.gwt.event.dom.client.ClickEvent;
//import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.CommandCanceledException;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.IncrementalCommand;
//import com.google.gwt.user.client.ui.Button;
//import com.google.gwt.user.client.ui.HorizontalPanel;
//import com.google.gwt.user.client.ui.Label;
//import com.google.gwt.user.client.ui.ListBox;
//import com.google.gwt.user.client.ui.RootPanel;
//import com.google.gwt.user.client.ui.SimplePanel;
//import com.google.gwt.user.client.ui.TextArea;
//import com.google.gwt.user.client.ui.VerticalPanel;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.dellroad.lzma.client.CompressionMode;
import org.dellroad.lzma.client.LZMAByteArrayCompressor;
import org.dellroad.lzma.client.LZMAByteArrayDecompressor;
import org.dellroad.lzma.client.UTF8;

public class LZMADemo implements EntryPoint {

    private static final CompressionMode DEFAULT_COMPRESSION_MODE = CompressionMode.MODE_1;

//    private final TextArea leftWindow = new TextArea();
//    private final TextArea rightWindow = new TextArea();

//    private final SimplePanel leftSizePanel = new SimplePanel();
//    private final SimplePanel rightSizePanel = new SimplePanel();

    private CompressionMode mode = DEFAULT_COMPRESSION_MODE;

    private boolean compressing;

    public LZMADemo() {
//        this.leftWindow.setCharacterWidth(70);
//        this.leftWindow.setVisibleLines(25);
//        this.rightWindow.setCharacterWidth(70);
//        this.rightWindow.setVisibleLines(25);
    }


    public void compress() {
//        this.rightWindow.setText("");
//        updateSizes(false);
//        this.rightSizePanel.setWidget(new Label("Compressing... 0%"));
//        this.compressing = true;
        DeferredCommand.addCommand(new IncrementalCommand() {
            LZMAByteArrayCompressor c;
            public boolean execute() {
                if (c == null) {
                    //c = new LZMAByteArrayCompressor(UTF8.encode(LZMADemo.this.leftWindow.getText()), LZMADemo.this.mode);
                    c = new LZMAByteArrayCompressor(UTF8.encode("sample_enc"), LZMADemo.this.mode);
                    return true;
                }
                if (c.execute()) {
//                    int pcent = (int)(c.getProgress() * 100.0);
//                    LZMADemo.this.rightSizePanel.setWidget(new Label("Compressing... " + pcent + "%"));
                    return true;
                }
//                setRightData(c.getCompressedData());
//                updateSizes(true);
                alert(c.getCompressedData());
                return false;
            }
        });
    }

    public void decompress() {

        // Get binary data
//        this.leftWindow.setText("");
//        updateSizes(false);
        final byte[] data = new byte[] {93, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 48, (byte)193, (byte)251, (byte)255, (byte)255, (byte)255, (byte)224, 0, 0, 0};
        //if (data == null)
        //    return;

        // Decompress it
        //this.leftSizePanel.setWidget(new Label("Decompressing... 0%"));
        //this.compressing = false;
        DeferredCommand.addCommand(new IncrementalCommand() {
            LZMAByteArrayDecompressor d;
            public boolean execute() {
                if (d == null) {
                    try {
                        d = new LZMAByteArrayDecompressor(data);
                    } catch (IOException e) {
                        //LZMADemo.this.leftSizePanel.setWidget(new Label("Decompression failed: " + e.getMessage()));
                        alert("Decompression failed: " + e.getMessage());
                        return false;
                    }
                    return true;
                }
                if (d.execute()) {
                    //int pcent = (int)(d.getProgress() * 100.0);
                    //LZMADemo.this.leftSizePanel.setWidget(new Label("Decompressing... " + pcent + "%"));
                    return true;
                }
                IOException ioe = d.getException();
                if (ioe != null) {
                    //LZMADemo.this.leftSizePanel.setWidget(new Label("Decompression failed: " + ioe.getMessage()));
                    alert("Decompression failed: " + ioe.getMessage());
                    return false;
                }
                String text;
                try {
                    text = UTF8.decode(d.getUncompressedData());
                } catch (IllegalArgumentException e) {
                    //LZMADemo.this.leftSizePanel.setWidget(new Label("Decompression failed: " + e.getMessage()));
                    alert("Decompression failed: " + e.getMessage());
                    return false;
                }
                //LZMADemo.this.leftWindow.setText(text);
                alert(text);
                //updateSizes(true);
                return false;
{'fraction_non_alphanumeric': 0.1280470720089661, 'fraction_numerical': 0.012141589614271038, 'mean_word_length': 1.9727928928373126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2554901', 'n_tokens_mistral': 3290, 'n_tokens_neox': 3092, 'n_words': 551}