semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void trainDepParser(byte flag, JarArchiveOutputStream zout) throws Exception {
        AbstractDepParser parser = null;
        OneVsAllDecoder decoder = null;
        if (flag == ShiftPopParser.FLAG_TRAIN_LEXICON) {
            System.out.println("\n* Save lexica");
            if (s_depParser.equals(AbstractDepParser.ALG_SHIFT_EAGER)) parser = new ShiftEagerParser(flag, s_featureXml); else if (s_depParser.equals(AbstractDepParser.ALG_SHIFT_POP)) parser = new ShiftPopParser(flag, s_featureXml);
        } else if (flag == ShiftPopParser.FLAG_TRAIN_INSTANCE) {
            System.out.println("\n* Print training instances");
            System.out.println("- loading lexica");
            if (s_depParser.equals(AbstractDepParser.ALG_SHIFT_EAGER)) parser = new ShiftEagerParser(flag, t_xml, ENTRY_LEXICA); else if (s_depParser.equals(AbstractDepParser.ALG_SHIFT_POP)) parser = new ShiftPopParser(flag, t_xml, ENTRY_LEXICA);
        } else if (flag == ShiftPopParser.FLAG_TRAIN_BOOST) {
            System.out.println("\n* Train conditional");
            decoder = new OneVsAllDecoder(m_model);
            if (s_depParser.equals(AbstractDepParser.ALG_SHIFT_EAGER)) parser = new ShiftEagerParser(flag, t_xml, t_map, decoder); else if (s_depParser.equals(AbstractDepParser.ALG_SHIFT_POP)) parser = new ShiftPopParser(flag, t_xml, t_map, decoder);
        }
        AbstractReader<DepNode, DepTree> reader = null;
        DepTree tree;
        int n;
        if (s_format.equals(AbstractReader.FORMAT_DEP)) reader = new DepReader(s_trainFile, true); else if (s_format.equals(AbstractReader.FORMAT_CONLLX)) reader = new CoNLLXReader(s_trainFile, true);
        parser.setLanguage(s_language);
        reader.setLanguage(s_language);
        for (n = 0; (tree = reader.nextTree()) != null; n++) {
            parser.parse(tree);
            if (n % 1000 == 0) System.out.printf("\r- parsing: %dK", n / 1000);
        }
        System.out.println("\r- parsing: " + n);
        if (flag == ShiftPopParser.FLAG_TRAIN_LEXICON) {
            System.out.println("- saving");
            parser.saveTags(ENTRY_LEXICA);
            t_xml = parser.getDepFtrXml();
        } else if (flag == ShiftPopParser.FLAG_TRAIN_INSTANCE || flag == ShiftPopParser.FLAG_TRAIN_BOOST) {
            a_yx = parser.a_trans;
            zout.putArchiveEntry(new JarArchiveEntry(ENTRY_PARSER));
            PrintStream fout = new PrintStream(zout);
            fout.print(s_depParser);
            fout.flush();
            zout.closeArchiveEntry();
            zout.putArchiveEntry(new JarArchiveEntry(ENTRY_FEATURE));
            IOUtils.copy(new FileInputStream(s_featureXml), zout);
            zout.closeArchiveEntry();
            zout.putArchiveEntry(new JarArchiveEntry(ENTRY_LEXICA));
            IOUtils.copy(new FileInputStream(ENTRY_LEXICA), zout);
            zout.closeArchiveEntry();
            if (flag == ShiftPopParser.FLAG_TRAIN_INSTANCE) t_map = parser.getDepFtrMap();
        }
    }
@Override
    public void run() {
        try {
            FileChannel out = new FileOutputStream(outputfile).getChannel();
            long pos = 0;
            status.setText("Slučovač: Proces Slučování spuštěn.. Prosím čekejte..");
            for (int i = 1; i <= noofparts; i++) {
                FileChannel in = new FileInputStream(originalfilename.getAbsolutePath() + "." + "v" + i).getChannel();
                status.setText("Slučovač: Slučuji část " + i + "..");
                this.splitsize = in.size();
                out.transferFrom(in, pos, splitsize);
                pos += splitsize;
                in.close();
                if (deleteOnFinish) new File(originalfilename + ".v" + i).delete();
                pb.setValue(100 * i / noofparts);
            }
            out.close();
            status.setText("Slučovač: Hotovo..");
            JOptionPane.showMessageDialog(null, "Sloučeno!", "Slučovač", JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception e) {
        }
    }
public int create(BusinessObject o) throws DAOException {
        int insert = 0;
        int id = 0;
        Bill bill = (Bill) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("INSERT_BILL"));
            pst.setDate(1, new java.sql.Date(bill.getDate().getTime()));
            pst.setInt(2, bill.getIdAccount());
            insert = pst.executeUpdate();
            if (insert <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (insert > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            Statement st = connection.createStatement();
            ResultSet rs = st.executeQuery("select max(id) from bill");
            rs.next();
            id = rs.getInt(1);
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return id;
    }
public int delete(BusinessObject o) throws DAOException {
        int delete = 0;
        Bill bill = (Bill) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("DELETE_BILL"));
            pst.setInt(1, bill.getId());
            delete = pst.executeUpdate();
            if (delete <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (delete > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return delete;
    }
public int update(BusinessObject o) throws DAOException {
        int update = 0;
        Bill bill = (Bill) o;
        try {
            PreparedStatement pst = connection.prepareStatement(XMLGetQuery.getQuery("UPDATE_BILL"));
            pst.setInt(1, bill.getId());
            update = pst.executeUpdate();
            if (update <= 0) {
                connection.rollback();
                throw new DAOException("Number of rows <= 0");
            } else if (update > 1) {
                connection.rollback();
                throw new DAOException("Number of rows > 1");
            }
            connection.commit();
        } catch (SQLException e) {
            Log.write(e.getMessage());
            throw new DAOException("A SQLException has occured");
        } catch (NullPointerException npe) {
            Log.write(npe.getMessage());
            throw new DAOException("Connection null");
        }
        return update;
    }
public static String encryptPassword(String originalPassword) {
        if (!StringUtils.hasText(originalPassword)) {
            originalPassword = randomPassword();
        }
        try {
            MessageDigest md5 = MessageDigest.getInstance(PASSWORD_ENCRYPTION_TYPE);
            md5.update(originalPassword.getBytes());
            byte[] bytes = md5.digest();
            int value;
            StringBuilder buf = new StringBuilder();
            for (byte aByte : bytes) {
                value = aByte;
                if (value < 0) {
                    value += 256;
                }
                if (value < 16) {
                    buf.append("0");
                }
                buf.append(Integer.toHexString(value));
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            log.debug("Do not encrypt password,use original password", e);
            return originalPassword;
        }
    }
public String readFile(String filename) throws UnsupportedEncodingException, FileNotFoundException, IOException {
        File f = new File(baseDir);
        f = new File(f, filename);
        StringWriter w = new StringWriter();
        Reader fr = new InputStreamReader(new FileInputStream(f), "UTF-8");
        IOUtils.copy(fr, w);
        fr.close();
        w.close();
        String contents = w.toString();
        return contents;
    }
public byte[] getResponseContent() throws IOException {
        if (responseContent == null) {
            InputStream is = getResponseStream();
            if (is == null) {
                responseContent = new byte[0];
            } else {
                ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
                IOUtils.copy(is, baos);
                responseContent = baos.toByteArray();
            }
        }
        return responseContent;
    }
public static byte[] generateHash(String strPassword, byte[] salt) {
        try {
            MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM);
            md.update(strPassword.getBytes(CHAR_ENCODING));
            md.update(salt);
            return md.digest();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
public void bindDownload(Download download) throws BindingException {
        List<ChunkDownload> chunks = download.getChunks();
        File destination = download.getFile();
        FileOutputStream fos = null;
        try {
            fos = FileUtils.openOutputStream(destination);
            for (ChunkDownload chunk : chunks) {
                String filePath = chunk.getChunkFilePath();
                InputStream ins = null;
                try {
                    File chunkFile = new File(filePath);
                    ins = FileUtils.openInputStream(chunkFile);
                    IOUtils.copy(ins, fos);
                    chunkFile.delete();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    ins.close();
                }
            }
            download.getWorkDir().delete();
            download.complete();
        } catch (IOException e) {
            logger.error("IO Exception while copying the chunk " + e.getMessage(), e);
            e.printStackTrace();
            throw new BindingException("IO Exception while copying the chunk " + e.getMessage(), e);
        } finally {
            try {
                fos.close();
            } catch (IOException e) {
                logger.error("IO Exception while copying closing stream of the target file " + e.getMessage(), e);
                e.printStackTrace();
                throw new BindingException("IO Exception while copying closing stream of the target file " + e.getMessage(), e);
            }
        }
    }
private void createTab2(TabLayoutPanel tab) {
        ScrollingGraphicalViewer viewer;
        try {
            viewer = new ScrollingGraphicalViewer();
            viewer.createControl();
            ScalableFreeformRootEditPart root = new ScalableFreeformRootEditPart();
            viewer.setRootEditPart(root);
            viewer.setEditDomain(new EditDomain());
            viewer.setEditPartFactory(new org.drawx.gef.sample.client.tool.example.editparts.MyEditPartFactory());
            CanvasModel model = new CanvasModel();
            for (int i = 0; i < 1; i++) {
                MyConnectionModel conn = new MyConnectionModel();
                OrangeModel m1 = new OrangeModel(new Point(30, 230));
                OrangeModel m2 = new OrangeModel(new Point(0, 0));
                model.addChild(m1);
                model.addChild(m2);
                m1.addSourceConnection(conn);
                m2.addTargetConnection(conn);
                viewer.setContents(model);
            }
            DiagramEditor p = new DiagramEditor(viewer);
            viewer.setContextMenu(new MyContextMenuProvider(viewer, p.getActionRegistry()));
            VerticalPanel panel = new VerticalPanel();
            addToolbox(viewer.getEditDomain(), viewer, panel);
            panel.add(viewer.getControl().getWidget());
            tab.add(panel, "Fixed Size Canvas(+Overview)");
            addOverview(viewer, panel);
            viewer.getControl().setSize(400, 300);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
public int read(String name) {
        status = STATUS_OK;
        try {
            name = name.trim().toLowerCase();
            if ((name.indexOf("file:") >= 0) || (name.indexOf(":/") > 0)) {
                URL url = new URL(name);
                in = new BufferedInputStream(url.openStream());
            } else {
                in = new BufferedInputStream(new FileInputStream(name));
            }
            status = read(in);
        } catch (IOException e) {
            status = STATUS_OPEN_ERROR;
        }
        return status;
    }
public static void gunzip(File gzippedFile, File destinationFile) throws IOException {
        int buffer = 2048;
        FileInputStream in = new FileInputStream(gzippedFile);
        GZIPInputStream zipin = new GZIPInputStream(in);
        byte[] data = new byte[buffer];
        FileOutputStream out = new FileOutputStream(destinationFile);
        int length;
        while ((length = zipin.read(data, 0, buffer)) != -1) out.write(data, 0, length);
        out.close();
        zipin.close();
    }
@Override
    protected String getFormat(String path) {
        String contentType = null;
        try {
            URL url = new URL(path);
            URLConnection connection = url.openConnection();
            connection.connect();
            contentType = connection.getContentType();
        } catch (Exception ex) {
            throw new RuntimeException("Connection to the url failed", ex);
        }
        if (contentType == null) {
            throw new RuntimeException("Problem getting url contentType is null!");
        }
        String format = contentType.toLowerCase().trim().replace("image/", "");
        if (format == null || format.length() == 0) {
            throw new RuntimeException("Unknow image mime type");
        }
        if (format.contains(";")) {
            format = format.split(";")[0];
        }
        if (format == null || format.length() == 0) {
            throw new RuntimeException("Unknow image mime type");
        }
        System.out.println("the format is: " + format);
        return format;
    }
public static String doGet(String http_url, String get_data) {
        URL url;
        try {
            if ((get_data != "") && (get_data != null)) {
                url = new URL(http_url + "?" + get_data);
            } else {
                url = new URL(http_url);
            }
            URLConnection conn = url.openConnection();
            InputStream stream = new BufferedInputStream(conn.getInputStream());
            try {
                StringBuffer b = new StringBuffer();
                int ch;
                while ((ch = stream.read()) != -1) b.append((char) ch);
                return b.toString();
            } finally {
                stream.close();
            }
        } catch (IOException e) {
            ;
        } catch (ClassCastException e) {
            e.printStackTrace();
        }
        return null;
    }
public static String doPost(String http_url, String post_data) {
        if (post_data == null) {
            post_data = "";
        }
        try {
            URLConnection conn = new URL(http_url).openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            DataOutputStream out = new DataOutputStream(conn.getOutputStream());
            out.writeBytes(post_data);
            out.flush();
            out.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            StringBuffer buffer = new StringBuffer();
            while ((line = in.readLine()) != null) {
                buffer.append(line);
                buffer.append("\n");
            }
            return buffer.toString();
        } catch (IOException e) {
            ;
        } catch (ClassCastException e) {
            e.printStackTrace();
        }
        return null;
    }
public static Properties loadProperties() {
        try {
            if (url == null) url = ClassLoader.getSystemResource("application.properties");
            if (url == null) throw new FileNotFoundException("application.properties");
            props = new Properties();
            props.load(url.openStream());
            Enumeration e = System.getProperties().propertyNames();
            String key;
            while (e.hasMoreElements()) {
                key = (String) e.nextElement();
                props.setProperty(key, System.getProperty(key));
            }
            return props;
        } catch (Exception e) {
            logger.log(Level.SEVERE, e.toString(), e);
        }
        return null;
    }
private static void prepare() {
        System.err.println("PREPARING-----------------------------------------");
        deleteHome();
        InputStream configStream = null;
        FileOutputStream tempStream = null;
        try {
            configStream = AllTests.class.getClassLoader().getResourceAsStream("net/sf/archimede/test/resources/repository.xml");
            new File("temp").mkdir();
            tempStream = new FileOutputStream(new File("temp/repository.xml"));
            IOUtils.copy(configStream, tempStream);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (configStream != null) {
                    configStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (tempStream != null) {
                    try {
                        tempStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        String repositoryName = "jackrabbit.repository";
        Properties jndiProperties = new Properties();
        jndiProperties.put("java.naming.provider.url", "http://sf.net/projects/archimede#1");
        jndiProperties.put("java.naming.factory.initial", "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
        startupUtil = new StartupJcrUtil(REPOSITORY_HOME, "temp/repository.xml", repositoryName, jndiProperties);
        startupUtil.init();
    }
public void run() {
            URLConnection con = null;
            try {
                con = url.openConnection();
                if ("HTTPS".equalsIgnoreCase(url.getProtocol())) {
                    HttpsURLConnection scon = (HttpsURLConnection) con;
                    try {
                        scon.setSSLSocketFactory(SSLUtil.getSSLSocketFactory(clientCertAlias));
                        HostnameVerifier hv = SSLUtil.getHostnameVerifier(hostCertLevel);
                        if (hv != null) {
                            scon.setHostnameVerifier(hv);
                        }
                    } catch (GeneralSecurityException e) {
                        Debug.logError(e, module);
                    } catch (GenericConfigException e) {
                        Debug.logError(e, module);
                    }
                }
            } catch (IOException e) {
                Debug.logError(e, module);
            }
            synchronized (URLConnector.this) {
                if (timedOut && con != null) {
                    close(con);
                } else {
                    connection = con;
                    URLConnector.this.notify();
                }
            }
        }
private void SaveToArchive(Layer layer, String layerFileName) throws Exception {
        Object archiveObj = layer.getBlackboard().get("ArchiveFileName");
        Object entryObj = layer.getBlackboard().get("ArchiveEntryPrefix");
        if ((archiveObj == null) || (entryObj == null)) return;
        String archiveName = archiveObj.toString();
        String entryPrefix = entryObj.toString();
        if ((archiveName == "") || (entryPrefix == "")) return;
        File tempZip = File.createTempFile("tmp", ".zip");
        InputStream in = new BufferedInputStream(new FileInputStream(archiveName));
        OutputStream out = new BufferedOutputStream(new FileOutputStream(tempZip));
        copy(in, out);
        in.close();
        out.close();
        ZipFile zipFile = new ZipFile(tempZip);
        ZipOutputStream zout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(archiveName)));
        ZipInputStream zin = new ZipInputStream(new FileInputStream(tempZip));
        ZipEntry entry = zin.getNextEntry();
        while (entry != null) {
            String entryName = entry.getName();
            String en = GUIUtil.nameWithoutExtension(new File(entryName));
            if (en.equalsIgnoreCase(entryPrefix)) {
                if (entryName.endsWith(".jmp")) {
                    String layerTaskPath = CreateArchivePlugIn.createLayerTask(layer, archiveName, entryPrefix);
                    CreateArchivePlugIn.WriteZipEntry(layerTaskPath, entryPrefix, zout);
                } else if ((!entryName.endsWith(".shx")) && (!entryName.endsWith(".dbf")) && (!entryName.endsWith(".shp.xml")) && (!entryName.endsWith(".prj"))) {
                    CreateArchivePlugIn.WriteZipEntry(layerFileName, entryPrefix, zout);
                }
            } else {
                zout.putNextEntry(entry);
                copy(zin, zout);
            }
            entry = zin.getNextEntry();
        }
        zin.close();
        zout.close();
        zipFile.close();
        tempZip.delete();
    }
public HttpResponseExchange execute() throws Exception {
            HttpResponseExchange forwardResponse = null;
            int fetchSizeLimit = Config.getInstance().getFetchLimitSize();
            while (null != lastContentRange) {
                forwardRequest.setBody(new byte[0]);
                ContentRangeHeaderValue old = lastContentRange;
                long sendSize = fetchSizeLimit;
                if (old.getInstanceLength() - old.getLastBytePos() - 1 < fetchSizeLimit) {
                    sendSize = (old.getInstanceLength() - old.getLastBytePos() - 1);
                }
                if (sendSize <= 0) {
                    break;
                }
                lastContentRange = new ContentRangeHeaderValue(old.getLastBytePos() + 1, old.getLastBytePos() + sendSize, old.getInstanceLength());
                forwardRequest.setHeader(HttpHeaders.Names.CONTENT_RANGE, lastContentRange);
                forwardRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(sendSize));
                forwardResponse = syncFetch(forwardRequest);
                if (sendSize < fetchSizeLimit) {
                    lastContentRange = null;
                }
            }
            return forwardResponse;
        }
public HttpResponse execute(HttpRequest request) throws IOException {
        this.request = request;
        buildParams();
        String l = request.getUrl();
        if (request instanceof HttpGet) {
            l = l + "?" + params;
        }
        URL url = new URL(l);
        conn = (HttpURLConnection) url.openConnection();
        conn.setConnectTimeout(connectTimeout);
        conn.setReadTimeout(readTimeout);
        buildHeader();
        if (request instanceof HttpPost) {
            sendRequest();
        }
        readResponse();
        return this.response;
    }