semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Override
    public void run() {
        Shell currentShell = Display.getCurrent().getActiveShell();
        if (DMManager.getInstance().getOntology() == null) return;
        DataRecordSet data = DMManager.getInstance().getOntology().getDataView().dataset();
        InputDialog input = new InputDialog(currentShell, Resources.I18N.getString("vikamine.dtp.title"), Resources.I18N.getString("vikamine.dtp.export.tablename"), data.getRelationName(), null);
        input.open();
        String tablename = input.getValue();
        if (tablename == null) return;
        super.getProfile().connect();
        IManagedConnection mc = super.getProfile().getManagedConnection("java.sql.Connection");
        java.sql.Connection sql = (java.sql.Connection) mc.getConnection().getRawConnection();
        try {
            sql.setAutoCommit(false);
            DatabaseMetaData dbmd = sql.getMetaData();
            ResultSet tables = dbmd.getTables(null, null, tablename, new String[] { "TABLE" });
            if (tables.next()) {
                if (!MessageDialog.openConfirm(currentShell, Resources.I18N.getString("vikamine.dtp.title"), Resources.I18N.getString("vikamine.dtp.export.overwriteTable"))) return;
                Statement statement = sql.createStatement();
                statement.executeUpdate("DROP TABLE " + tablename);
                statement.close();
            }
            String createTableQuery = null;
            for (int i = 0; i < data.getNumAttributes(); i++) {
                if (DMManager.getInstance().getOntology().isIDAttribute(data.getAttribute(i))) continue;
                if (createTableQuery == null) createTableQuery = ""; else createTableQuery += ",";
                createTableQuery += getColumnDefinition(data.getAttribute(i));
            }
            Statement statement = sql.createStatement();
            statement.executeUpdate("CREATE TABLE " + tablename + "(" + createTableQuery + ")");
            statement.close();
            exportRecordSet(data, sql, tablename);
            sql.commit();
            sql.setAutoCommit(true);
            MessageDialog.openInformation(currentShell, Resources.I18N.getString("vikamine.dtp.title"), Resources.I18N.getString("vikamine.dtp.export.successful"));
        } catch (SQLException e) {
            try {
                sql.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            MessageDialog.openError(currentShell, Resources.I18N.getString("vikamine.dtp.title"), Resources.I18N.getString("vikamine.dtp.export.failed"));
            e.printStackTrace();
        }
    }
public String encryptStringWithKey(String to_be_encrypted, String aKey) {
        String encrypted_value = "";
        char xdigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
        MessageDigest messageDigest;
        try {
            messageDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException exc) {
            globalErrorDictionary.takeValueForKey(("Security package does not contain appropriate algorithm"), ("Security package does not contain appropriate algorithm"));
            log.error("Security package does not contain appropriate algorithm");
            return encrypted_value;
        }
        if (to_be_encrypted != null) {
            byte digest[];
            byte fudge_constant[];
            try {
                fudge_constant = ("X#@!").getBytes("UTF8");
            } catch (UnsupportedEncodingException uee) {
                fudge_constant = ("X#@!").getBytes();
            }
            byte fudgetoo_part[] = { (byte) xdigit[(int) (MSiteConfig.myrand() % 16)], (byte) xdigit[(int) (MSiteConfig.myrand() % 16)], (byte) xdigit[(int) (MSiteConfig.myrand() % 16)], (byte) xdigit[(int) (MSiteConfig.myrand() % 16)] };
            int i = 0;
            if (aKey != null) {
                try {
                    fudgetoo_part = aKey.getBytes("UTF8");
                } catch (UnsupportedEncodingException uee) {
                    fudgetoo_part = aKey.getBytes();
                }
            }
            messageDigest.update(fudge_constant);
            try {
                messageDigest.update(to_be_encrypted.getBytes("UTF8"));
            } catch (UnsupportedEncodingException uee) {
                messageDigest.update(to_be_encrypted.getBytes());
            }
            messageDigest.update(fudgetoo_part);
            digest = messageDigest.digest();
            encrypted_value = new String(fudgetoo_part);
            for (i = 0; i < digest.length; i++) {
                int mashed;
                char temp[] = new char[2];
                if (digest[i] < 0) {
                    mashed = 127 + (-1 * digest[i]);
                } else {
                    mashed = digest[i];
                }
                temp[0] = xdigit[mashed / 16];
                temp[1] = xdigit[mashed % 16];
                encrypted_value = encrypted_value + (new String(temp));
            }
        }
        return encrypted_value;
    }
protected void processAnnotationsJar(URL url) {
        JarFile jarFile = null;
        try {
            URLConnection urlConn = url.openConnection();
            JarURLConnection jarUrlConn;
            if (!(urlConn instanceof JarURLConnection)) {
                sm.getString("contextConfig.jarUrl", url);
                return;
            }
            jarUrlConn = (JarURLConnection) urlConn;
            jarUrlConn.setUseCaches(false);
            jarFile = jarUrlConn.getJarFile();
            Enumeration<JarEntry> jarEntries = jarFile.entries();
            while (jarEntries.hasMoreElements()) {
                JarEntry jarEntry = jarEntries.nextElement();
                String entryName = jarEntry.getName();
                if (entryName.endsWith(".class")) {
                    InputStream is = null;
                    try {
                        is = jarFile.getInputStream(jarEntry);
                        processAnnotationsStream(is);
                    } catch (IOException e) {
                        logger.error(sm.getString("contextConfig.inputStreamJar", entryName, url), e);
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (Throwable t) {
                                ExceptionUtils.handleThrowable(t);
                            }
                        }
                    }
                }
            }
        } catch (IOException e) {
            logger.error(sm.getString("contextConfig.jarFile", url), e);
        } finally {
            if (jarFile != null) {
                try {
                    jarFile.close();
                } catch (Throwable t) {
                    ExceptionUtils.handleThrowable(t);
                }
            }
        }
    }
protected void processAnnotationsJndi(URL url) {
        try {
            URLConnection urlConn = url.openConnection();
            DirContextURLConnection dcUrlConn;
            if (!(urlConn instanceof DirContextURLConnection)) {
                sm.getString("contextConfig.jndiUrlNotDirContextConn", url);
                return;
            }
            dcUrlConn = (DirContextURLConnection) urlConn;
            dcUrlConn.setUseCaches(false);
            String type = dcUrlConn.getHeaderField(ResourceAttributes.TYPE);
            if (ResourceAttributes.COLLECTION_TYPE.equals(type)) {
                Enumeration<String> dirs = dcUrlConn.list();
                while (dirs.hasMoreElements()) {
                    String dir = dirs.nextElement();
                    URL dirUrl = new URL(url.toString() + '/' + dir);
                    processAnnotationsJndi(dirUrl);
                }
            } else {
                if (url.getPath().endsWith(".class")) {
                    InputStream is = null;
                    try {
                        is = dcUrlConn.getInputStream();
                        processAnnotationsStream(is);
                    } catch (IOException e) {
                        logger.error(sm.getString("contextConfig.inputStreamJndi", url), e);
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (Throwable t) {
                                ExceptionUtils.handleThrowable(t);
                            }
                        }
                    }
                }
            }
        } catch (IOException e) {
            logger.error(sm.getString("contextConfig.jndiUrl", url), e);
        }
    }
public void update() {
        if (!updatable) {
            Main.fenetre().erreur(Fenetre.OLD_VERSION);
            return;
        }
        try {
            Main.fenetre().update();
            Element remoteRoot = new SAXBuilder().build(xml).getRootElement();
            addPackages = new HashMap<Integer, PackageVersion>();
            Iterator<?> iterElem = remoteRoot.getChildren().iterator();
            while (iterElem.hasNext()) {
                PackageVersion pack = new PackageVersion((Element) iterElem.next());
                addPackages.put(pack.id(), pack);
            }
            removePackages = new HashMap<Integer, PackageVersion>();
            iterElem = root.getChildren("package").iterator();
            while (iterElem.hasNext()) {
                PackageVersion pack = new PackageVersion((Element) iterElem.next());
                int id = pack.id();
                if (!addPackages.containsKey(id)) {
                    removePackages.put(id, pack);
                } else if (addPackages.get(id).version().equals(pack.version())) {
                    addPackages.remove(id);
                } else {
                    addPackages.get(id).ecrase();
                }
            }
            Iterator<PackageVersion> iterPack = addPackages.values().iterator();
            while (iterPack.hasNext()) {
                install(iterPack.next());
            }
            iterPack = removePackages.values().iterator();
            while (iterPack.hasNext()) {
                remove(iterPack.next());
            }
            if (offline) {
                Runtime.getRuntime().addShutdownHook(new AddPackage(xml, "versions.xml"));
                Main.fenetre().erreur(Fenetre.UPDATE_TERMINE_RESTART);
            } else {
                File oldXML = new File("versions.xml");
                oldXML.delete();
                oldXML.createNewFile();
                FileChannel out = new FileOutputStream(oldXML).getChannel();
                FileChannel in = new FileInputStream(xml).getChannel();
                in.transferTo(0, in.size(), out);
                in.close();
                out.close();
                xml.delete();
                if (restart) {
                    Main.fenetre().erreur(Fenetre.UPDATE_TERMINE_RESTART);
                } else {
                    Main.updateVersion();
                }
            }
        } catch (Exception e) {
            Main.fenetre().erreur(Fenetre.ERREUR_UPDATE, e);
        }
    }
private static String readStreamToString(InputStream is, boolean passInVelocity, String tplName, Map<String, Object> templateVarsMap) throws IOException {
        StringWriter sw = new StringWriter();
        IOUtils.copy(is, sw, "UTF-8");
        if (passInVelocity) {
            return tpl.formatStr(sw.toString(), templateVarsMap, tplName);
        }
        return sw.toString();
    }
private StringBuffer hashPassword(StringBuffer password, String mode) {
        MessageDigest m = null;
        StringBuffer hash = new StringBuffer();
        try {
            m = MessageDigest.getInstance(mode);
            m.update(password.toString().getBytes("UTF8"));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        byte[] digest = m.digest();
        for (int i = 0; i < digest.length; i++) {
            String hex = Integer.toHexString(digest[i]);
            if (hex.length() == 1) hex = "0" + hex;
            hex = hex.substring(hex.length() - 2);
            hash.append(hex);
        }
        return hash;
    }
public String getMD5(String password) throws NoSuchAlgorithmException {
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.update(password.getBytes());
		byte byteData[] = md.digest();
		StringBuffer sb = new StringBuffer();
		for(int i = 0; i < byteData.length; i++) {
			sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
		}
		return sb.toString();
	}
private ScrollingGraphicalViewer createGraphicalViewer(final Composite parent) {
        final ScrollingGraphicalViewer viewer = new ScrollingGraphicalViewer();
        viewer.createControl(parent);
        _root = new ScalableRootEditPart();
        viewer.setRootEditPart(_root);
        getEditDomain().addViewer(viewer);
        getSite().setSelectionProvider(viewer);
        viewer.setEditPartFactory(getEditPartFactory());
        viewer.setContents(getEditorInput().getAdapter(ScannedMap.class));
        return viewer;
    }
public static void main(String[] args) {
        try {
            boolean readExp = Utils.getFlag('l', args);
            final boolean writeExp = Utils.getFlag('s', args);
            final String expFile = Utils.getOption('f', args);
            if ((readExp || writeExp) && (expFile.length() == 0)) {
                throw new Exception("A filename must be given with the -f option");
            }
            Experiment exp = null;
            if (readExp) {
                FileInputStream fi = new FileInputStream(expFile);
                ObjectInputStream oi = new ObjectInputStream(new BufferedInputStream(fi));
                exp = (Experiment) oi.readObject();
                oi.close();
            } else {
                exp = new Experiment();
            }
            System.err.println("Initial Experiment:\n" + exp.toString());
            final JFrame jf = new JFrame("Weka Experiment Setup");
            jf.getContentPane().setLayout(new BorderLayout());
            final SetupPanel sp = new SetupPanel();
            jf.getContentPane().add(sp, BorderLayout.CENTER);
            jf.addWindowListener(new WindowAdapter() {

                public void windowClosing(WindowEvent e) {
                    System.err.println("\nFinal Experiment:\n" + sp.m_Exp.toString());
                    if (writeExp) {
                        try {
                            FileOutputStream fo = new FileOutputStream(expFile);
                            ObjectOutputStream oo = new ObjectOutputStream(new BufferedOutputStream(fo));
                            oo.writeObject(sp.m_Exp);
                            oo.close();
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            System.err.println("Couldn't write experiment to: " + expFile + '\n' + ex.getMessage());
                        }
                    }
                    jf.dispose();
                    System.exit(0);
                }
            });
            jf.pack();
            jf.setVisible(true);
            System.err.println("Short nap");
            Thread.currentThread().sleep(3000);
            System.err.println("Done");
            sp.setExperiment(exp);
        } catch (Exception ex) {
            ex.printStackTrace();
            System.err.println(ex.getMessage());
        }
    }
public File nextEntry() {
            try {
                while (hasNext()) {
                    String name = waitingArchEntry.getName();
                    name = name.substring(name.indexOf("/") + 1);
                    File file = new File(targetDir.getAbsolutePath() + "/" + name);
                    if (waitingArchEntry.isDirectory()) {
                        file.mkdirs();
                        waitingArchEntry = ais.getNextEntry();
                    } else {
                        OutputStream os = new FileOutputStream(file);
                        try {
                            IOUtils.copy(ais, os);
                        } finally {
                            IOUtils.closeQuietly(os);
                        }
                        return file;
                    }
                }
            } catch (IOException e) {
                return null;
            }
            return null;
        }
private Document getDocument(URL url) throws SAXException, IOException {
        InputStream is;
        try {
            is = url.openStream();
        } catch (IOException io) {
            System.out.println("parameter error : The specified reading data is mistaken.");
            System.out.println(" Request URL is " + sourceUri);
            throw new IOException("\t" + io.toString());
        }
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        try {
            builder = factory.newDocumentBuilder();
        } catch (ParserConfigurationException pce) {
            System.out.println("error : The error of DocumentBuilder instance generation");
            throw new RuntimeException(pce.toString());
        }
        Document doc;
        try {
            doc = builder.parse(is);
        } catch (Exception e) {
            System.out.println("error : parse of reading data went wrong.");
            System.out.println(" Request URL is " + sourceUri);
            throw new RuntimeException(e.toString());
        }
        return doc;
    }
public static GCalendar getNewestCalendar(Calendar startDate) throws IOException {
        GCalendar hoge = null;
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpClient http = new DefaultHttpClient();
            HttpGet method = new HttpGet("http://localhost:8080/GoogleCalendar/select");
            HttpResponse response = http.execute(method);
            String jsonstr = response.getEntity().toString();
            System.out.println("jsonstr = " + jsonstr);
            hoge = JSON.decode(jsonstr, GCalendar.class);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return hoge;
    }
private void nioBuild() {
        try {
            final ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 4);
            final FileChannel out = new FileOutputStream(dest).getChannel();
            for (File part : parts) {
                setState(part.getName(), BUILDING);
                FileChannel in = new FileInputStream(part).getChannel();
                while (in.read(buffer) > 0) {
                    buffer.flip();
                    written += out.write(buffer);
                    buffer.clear();
                }
                in.close();
            }
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static void compressFile(File orig) throws IOException {
        File file = new File(INPUT + orig.toString());
        File target = new File(OUTPUT + orig.toString().replaceAll(".xml", ".xml.gz"));
        System.out.println("    Compressing \"" + file.getName() + "\" into \"" + target + "\"");
        long l = file.length();
        FileInputStream fileinputstream = new FileInputStream(file);
        GZIPOutputStream gzipoutputstream = new GZIPOutputStream(new FileOutputStream(target));
        byte abyte0[] = new byte[1024];
        int i;
        while ((i = fileinputstream.read(abyte0)) != -1) gzipoutputstream.write(abyte0, 0, i);
        fileinputstream.close();
        gzipoutputstream.close();
        long l1 = target.length();
        System.out.println("    Initial size: " + l + "; Compressed size: " + l1 + ".");
        System.out.println("    Done.");
        System.out.println();
    }
public static void decompressFile(File orig) throws IOException {
        File file = new File(INPUT + orig.toString());
        File target = new File(OUTPUT + orig.toString().replaceAll(".xml.gz", ".xml"));
        System.out.println("    Decompressing \"" + file.getName() + "\" into \"" + target + "\"");
        long l = file.length();
        GZIPInputStream gzipinputstream = new GZIPInputStream(new FileInputStream(file));
        FileOutputStream fileoutputstream = new FileOutputStream(target);
        byte abyte0[] = new byte[1024];
        int i;
        while ((i = gzipinputstream.read(abyte0)) != -1) fileoutputstream.write(abyte0, 0, i);
        fileoutputstream.close();
        gzipinputstream.close();
        long l1 = target.length();
        System.out.println("    Initial size: " + l + "; Decompressed size: " + l1 + ".");
        System.out.println("    Done.");
        System.out.println();
    }
public ByteArrayOutputStream download(final String contentUuid) throws WebServiceClientException {
        try {
            URL url = new URL(getPath("/download/" + contentUuid));
            URLConnection connection = url.openConnection();
            InputStream inputStream = connection.getInputStream();
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            int c;
            while ((c = inputStream.read()) != -1) {
                outputStream.write(c);
            }
            inputStream.close();
            return outputStream;
        } catch (Exception ex) {
            throw new WebServiceClientException("Could not download content from web service.", ex);
        }
    }
public void download(String contentUuid, File path) throws WebServiceClientException {
        try {
            URL url = new URL(getPath("/download/" + contentUuid));
            URLConnection connection = url.openConnection();
            InputStream inputStream = connection.getInputStream();
            OutputStream output = new FileOutputStream(path);
            IoUtils.copyBytes(inputStream, output);
            IoUtils.close(inputStream);
            IoUtils.close(output);
        } catch (IOException ioex) {
            throw new WebServiceClientException("Could not download or saving content to path [" + path.getAbsolutePath() + "]", ioex);
        } catch (Exception ex) {
            throw new WebServiceClientException("Could not download content from web service.", ex);
        }
    }
private void serveRedir(OutputStream os, IRequest req) throws IOException {
        String urlString = req.getParameter("url");
        URL url = new URL(urlString);
        URLConnection con = url.openConnection();
        InputStream is = new BufferedInputStream(con.getInputStream());
        String ct = con.getContentType();
        int cl = con.getContentLength();
        String jsLink = "<script language=\"JavaScript1.2\" src=\"/tddt.js\" type='text/javascript'></script>\n";
        int i;
        String head = getHead("HTTP/1.0 200 OK", "Content-Type: " + ct + "\nContent-Length: -1");
        os.write(head.getBytes());
        if (ct != null && ct.indexOf("html") != -1) {
            os.write(jsLink.getBytes());
            NetUtils.saveChangeLink(url, os);
        } else {
            int len;
            byte[] b = new byte[1024];
            while ((len = is.read(b)) >= 0) {
                os.write(b, 0, len);
            }
        }
        os.flush();
    }