semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void addForwardAddress(final List<NewUser> forwardAddresses) {
        try {
            final List<Integer> usersToRemoveFromCache = new ArrayList<Integer>();
            connection.setAutoCommit(false);
            new ProcessEnvelope().executeNull(new ExecuteProcessAbstractImpl(connection, false, false, true, true) {

                @Override
                public void executeProcessReturnNull() throws SQLException {
                    psImpl = connImpl.prepareStatement(sqlCommands.getProperty("userForwardAddresses.add"));
                    Iterator<NewUser> iter = forwardAddresses.iterator();
                    Iterator<String> iter2;
                    NewUser newUser;
                    while (iter.hasNext()) {
                        newUser = iter.next();
                        psImpl.setInt(1, newUser.userId);
                        iter2 = newUser.forwardAddresses.iterator();
                        while (iter2.hasNext()) {
                            psImpl.setString(2, iter2.next());
                            psImpl.executeUpdate();
                        }
                        usersToRemoveFromCache.add(newUser.userId);
                    }
                }
            });
            connection.commit();
            cmDB.removeUsers(usersToRemoveFromCache);
        } catch (SQLException sqle) {
            log.error(sqle);
            if (connection != null) {
                try {
                    connection.rollback();
                } catch (SQLException ex) {
                }
            }
        } finally {
            if (connection != null) {
                try {
                    connection.setAutoCommit(true);
                } catch (SQLException ex) {
                }
            }
        }
    }
public void removeForwardAddress(final List<NewUser> forwardAddresses) {
        try {
            final List<Integer> usersToRemoveFromCache = new ArrayList<Integer>();
            connection.setAutoCommit(false);
            new ProcessEnvelope().executeNull(new ExecuteProcessAbstractImpl(connection, false, false, true, true) {

                @Override
                public void executeProcessReturnNull() throws SQLException {
                    psImpl = connImpl.prepareStatement(sqlCommands.getProperty("userForwardAddresses.delete"));
                    Iterator<NewUser> iter = forwardAddresses.iterator();
                    Iterator<Integer> iter2;
                    NewUser newUser;
                    while (iter.hasNext()) {
                        newUser = iter.next();
                        iter2 = newUser.forwardAddressIds.iterator();
                        while (iter2.hasNext()) {
                            psImpl.setInt(1, iter2.next());
                            psImpl.executeUpdate();
                        }
                        usersToRemoveFromCache.add(newUser.userId);
                    }
                }
            });
            connection.commit();
            cmDB.removeUsers(usersToRemoveFromCache);
        } catch (SQLException sqle) {
            log.error(sqle);
            if (connection != null) {
                try {
                    connection.rollback();
                } catch (SQLException ex) {
                }
            }
        } finally {
            if (connection != null) {
                try {
                    connection.setAutoCommit(true);
                } catch (SQLException ex) {
                }
            }
        }
    }
public void setDefaultMailBox(final int domainId, final int userId) {
        final EmailAddress defaultMailbox = cmDB.getDefaultMailbox(domainId);
        try {
            connection.setAutoCommit(false);
            new ProcessEnvelope().executeNull(new ExecuteProcessAbstractImpl(connection, false, false, true, true) {

                @Override
                public void executeProcessReturnNull() throws SQLException {
                    psImpl = connImpl.prepareStatement(sqlCommands.getProperty(defaultMailbox == null ? "domain.setDefaultMailbox" : "domain.updateDefaultMailbox"));
                    if (defaultMailbox == null) {
                        psImpl.setInt(1, domainId);
                        psImpl.setInt(2, userId);
                    } else {
                        psImpl.setInt(1, userId);
                        psImpl.setInt(2, domainId);
                    }
                    psImpl.executeUpdate();
                }
            });
            connection.commit();
            cmDB.updateDomains(null, null);
        } catch (SQLException sqle) {
            log.error(sqle);
            if (connection != null) {
                try {
                    connection.rollback();
                } catch (SQLException ex) {
                }
            }
        } finally {
            if (connection != null) {
                try {
                    connection.setAutoCommit(true);
                } catch (SQLException ex) {
                }
            }
        }
    }
public void insertRealm(final List<NewRealms> newRealms) {
        try {
            connection.setAutoCommit(false);
            new ProcessEnvelope().executeNull(new ExecuteProcessAbstractImpl(connection, false, false, true, true) {

                @Override
                public void executeProcessReturnNull() throws SQLException {
                    psImpl = connImpl.prepareStatement(sqlCommands.getProperty("realm.add"));
                    Iterator<NewRealms> iter = newRealms.iterator();
                    NewRealms newRealm;
                    String realm;
                    Iterator<String> iter2;
                    while (iter.hasNext()) {
                        newRealm = iter.next();
                        psImpl.setInt(3, newRealm.domainId);
                        iter2 = newRealm.realms.iterator();
                        while (iter2.hasNext()) {
                            realm = iter2.next();
                            psImpl.setString(1, realm);
                            psImpl.setString(2, realm.toLowerCase(locale));
                            psImpl.executeUpdate();
                        }
                    }
                }
            });
            connection.commit();
        } catch (SQLException sqle) {
            log.error(sqle);
            if (connection != null) {
                try {
                    connection.rollback();
                } catch (SQLException ex) {
                }
            }
        } finally {
            if (connection != null) {
                try {
                    connection.setAutoCommit(true);
                } catch (SQLException ex) {
                }
            }
        }
    }
public void removeRealm(final List<Integer> realmIds) {
        try {
            connection.setAutoCommit(false);
            new ProcessEnvelope().executeNull(new ExecuteProcessAbstractImpl(connection, false, false, true, true) {

                @Override
                public void executeProcessReturnNull() throws SQLException {
                    psImpl = connImpl.prepareStatement(sqlCommands.getProperty("realm.remove"));
                    Iterator<Integer> iter = realmIds.iterator();
                    int realmId;
                    while (iter.hasNext()) {
                        realmId = iter.next();
                        psImpl.setInt(1, realmId);
                        psImpl.executeUpdate();
                        cmDB.removeRealm(realmId);
                    }
                }
            });
            connection.commit();
        } catch (SQLException sqle) {
            log.error(sqle);
            if (connection != null) {
                try {
                    connection.rollback();
                } catch (SQLException ex) {
                }
            }
        } finally {
            if (connection != null) {
                try {
                    connection.setAutoCommit(true);
                } catch (SQLException ex) {
                }
            }
        }
    }
public void removeUserFromRealm(final List<NewUser> users) {
        try {
            connection.setAutoCommit(false);
            final List<Integer> removeFromNullRealm = (List<Integer>) new ProcessEnvelope().executeObject(new ExecuteProcessAbstractImpl(connection, false, false, true, true) {

                @Override
                public Object executeProcessReturnObject() throws SQLException {
                    psImpl = connImpl.prepareStatement(sqlCommands.getProperty("realm.removeUser"));
                    Iterator<NewUser> iter = users.iterator();
                    NewUser user;
                    int realmId;
                    Iterator<Integer> iter2;
                    List<Integer> removeFromNullRealm = new ArrayList<Integer>();
                    while (iter.hasNext()) {
                        user = iter.next();
                        psImpl.setInt(1, user.userId);
                        iter2 = user.realmIds.iterator();
                        while (iter2.hasNext()) {
                            realmId = iter2.next();
                            if (realmId == 0) {
                                removeFromNullRealm.add(user.userId);
                                continue;
                            }
                            psImpl.setInt(2, realmId);
                            psImpl.executeUpdate();
                        }
                        cmDB.removeUser(user.userId);
                    }
                    return removeFromNullRealm;
                }
            });
            if (!removeFromNullRealm.isEmpty()) {
                new ProcessEnvelope().executeNull(new ExecuteProcessAbstractImpl(connection, false, false, true, true) {

                    @Override
                    public void executeProcessReturnNull() throws SQLException {
                        psImpl = connImpl.prepareStatement(sqlCommands.getProperty("realm.removeUserFromNullRealm"));
                        Iterator<Integer> iter2 = removeFromNullRealm.iterator();
                        while (iter2.hasNext()) {
                            psImpl.setInt(1, iter2.next());
                            psImpl.executeUpdate();
                        }
                    }
                });
            }
            connection.commit();
        } catch (SQLException sqle) {
            log.error(sqle);
            if (connection != null) {
                try {
                    connection.rollback();
                } catch (SQLException ex) {
                }
            }
        } finally {
            if (connection != null) {
                try {
                    connection.setAutoCommit(true);
                } catch (SQLException ex) {
                }
            }
        }
    }
public void uploadFile(File inputFile, String targetFile) throws IOException {
        System.out.println("Uploading " + inputFile.getName() + " to " + targetFile);
        File outputFile = new File(targetFile);
        if (targetFile.endsWith("/")) {
            outputFile = new File(outputFile, inputFile.getName());
        } else if (outputFile.getParentFile().exists() == false) {
            outputFile.getParentFile().mkdirs();
        }
        if (inputFile.renameTo(outputFile) == false) {
            InputStream in = new FileInputStream(inputFile);
            OutputStream out = new FileOutputStream(outputFile);
            byte[] line = new byte[16384];
            int bytes = -1;
            while ((bytes = in.read(line)) != -1) out.write(line, 0, bytes);
            in.close();
            out.close();
        }
    }
public String getTags(URL url) {
        StringBuffer xml = new StringBuffer();
        OutputStreamWriter osw = null;
        BufferedReader br = null;
        try {
            String reqData = URLEncoder.encode(paramName, "UTF-8") + "=" + URLEncoder.encode(url.toString(), "UTF-8");
            URL service = new URL(cmdUrl);
            URLConnection urlConn = service.openConnection();
            urlConn.setDoOutput(true);
            urlConn.connect();
            osw = new OutputStreamWriter(urlConn.getOutputStream());
            osw.write(reqData);
            osw.flush();
            br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
            String line = null;
            while ((line = br.readLine()) != null) {
                xml.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (osw != null) {
                    osw.close();
                }
                if (br != null) {
                    br.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return xml.toString();
    }
public String getTags(String content) {
        StringBuffer xml = new StringBuffer();
        OutputStreamWriter osw = null;
        BufferedReader br = null;
        try {
            String reqData = URLEncoder.encode(paramName, "UTF-8") + "=" + URLEncoder.encode(content, "UTF-8");
            URL service = new URL(cmdUrl);
            URLConnection urlConn = service.openConnection();
            urlConn.setDoOutput(true);
            urlConn.connect();
            osw = new OutputStreamWriter(urlConn.getOutputStream());
            osw.write(reqData);
            osw.flush();
            br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
            String line = null;
            while ((line = br.readLine()) != null) {
                xml.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (osw != null) {
                    osw.close();
                }
                if (br != null) {
                    br.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return xml.toString();
    }
public static long download(String address, String localFileName) throws Exception {
        OutputStream out = null;
        URLConnection conn = null;
        InputStream in = null;
        long numWritten = 0;
        try {
            URL url = new URL(address);
            out = new BufferedOutputStream(new FileOutputStream(localFileName));
            conn = url.openConnection();
            in = conn.getInputStream();
            byte[] buffer = new byte[1024];
            int numRead;
            while ((numRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, numRead);
                numWritten += numRead;
            }
            System.out.println(localFileName + "\t" + numWritten);
        } catch (Exception exception) {
            System.out.println("Error: " + exception);
            throw exception;
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException ioe) {
            }
            return numWritten;
        }
    }
public void copiarMidias(final File vidDir, final File imgDir) {
        for (int i = 0; i < getMidias().size(); i++) {
            try {
                FileChannel src = new FileInputStream(getMidias().get(i).getUrl().trim()).getChannel();
                FileChannel dest;
                if (getMidias().get(i).getTipo().equals("video")) {
                    FileChannel vidDest = new FileOutputStream(vidDir + "/" + processaString(getMidias().get(i).getTitulo()) + "." + retornaExtensaoMidia(getMidias().get(i))).getChannel();
                    dest = vidDest;
                } else {
                    FileChannel midDest = new FileOutputStream(imgDir + "/" + processaString(getMidias().get(i).getTitulo()) + "." + retornaExtensaoMidia(getMidias().get(i))).getChannel();
                    dest = midDest;
                }
                dest.transferFrom(src, 0, src.size());
                src.close();
                dest.close();
            } catch (Exception e) {
                System.err.print(e.getMessage());
                e.printStackTrace();
            }
        }
    }
private static String hashToMD5(String sig) {
        try {
            MessageDigest lDigest = MessageDigest.getInstance("MD5");
            lDigest.update(sig.getBytes());
            BigInteger lHashInt = new BigInteger(1, lDigest.digest());
            return String.format("%1$032X", lHashInt).toLowerCase();
        } catch (NoSuchAlgorithmException lException) {
            throw new RuntimeException(lException);
        }
    }
public String mdHesla(String password) {
        String hashword = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(password.getBytes());
            BigInteger hash = new BigInteger(1, md5.digest());
            hashword = hash.toString(16);
        } catch (NoSuchAlgorithmException nsae) {
        }
        return hashword;
    }
public String readURL(URL url) throws JasenException {
        OutputStream out = new ByteArrayOutputStream();
        InputStream in = null;
        String html = null;
        NonBlockingStreamReader reader = null;
        try {
            in = url.openStream();
            reader = new NonBlockingStreamReader();
            reader.read(in, out, readBufferSize, readTimeout, null);
            html = new String(((ByteArrayOutputStream) out).toByteArray());
        } catch (IOException e) {
            throw new JasenException(e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ignore) {
                }
            }
        }
        return html;
    }
public static String hashSHA1(String value) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            digest.update(value.getBytes());
            BigInteger hash = new BigInteger(1, digest.digest());
            return hash.toString(16);
        } catch (NoSuchAlgorithmException e) {
        }
        return null;
    }
private static void addFromResource(String resource, OutputStream out) {
        URL url = OpenOfficeDocumentCreator.class.getResource(resource);
        try {
            InputStream in = url.openStream();
            byte[] buffer = new byte[256];
            synchronized (in) {
                synchronized (out) {
                    while (true) {
                        int bytesRead = in.read(buffer);
                        if (bytesRead == -1) break;
                        out.write(buffer, 0, bytesRead);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public void process(String number) {
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(Constants.TRAIN_INFO_URL.value());
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair(Constants.TRAIN_NUMBER_POST_PARAM_NAME.value(), number));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httpPost);
            InputStream is = response.getEntity().getContent();
            Document doc = getDocument(is);
            XPathFactory factory = XPathFactory.newInstance();
            XPath xpath = factory.newXPath();
            XPathExpression expr = xpath.compile(Constants.XPATH_TRAIN_STOPS_INFO.value());
            Object result = expr.evaluate(doc, XPathConstants.NODESET);
            NodeList nodes = (NodeList) result;
            List<String> list = new ArrayList<String>();
            for (int i = 0; i < nodes.getLength(); i++) {
                list.add(nodes.item(i).getNodeValue());
            }
            parse(list);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XPathExpressionException e) {
            e.printStackTrace();
        }
    }
@SuppressWarnings("unchecked")
    protected void processTransformAction(HttpServletRequest request, HttpServletResponse response, String action) throws Exception {
        File transformationFile = null;
        String tr = request.getParameter(Definitions.REQUEST_PARAMNAME_XSLT);
        if (StringUtils.isNotBlank(tr)) {
            transformationFile = new File(xslBase, tr);
            if (!transformationFile.isFile()) {
                response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter \"" + Definitions.REQUEST_PARAMNAME_XSLT + "\" " + "with value \"" + tr + "\" refers to non existing file");
                return;
            }
        }
        StreamResult result;
        ByteArrayOutputStream baos = null;
        if (isDevelopmentMode) {
            baos = new ByteArrayOutputStream();
            if (StringUtils.equals(action, "get")) {
                result = new StreamResult(new Base64.OutputStream(baos, Base64.DECODE));
            } else {
                result = new StreamResult(baos);
            }
        } else {
            if (StringUtils.equals(action, "get")) {
                result = new StreamResult(new Base64.OutputStream(response.getOutputStream(), Base64.DECODE));
            } else {
                result = new StreamResult(response.getOutputStream());
            }
        }
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.putAll(request.getParameterMap());
        params.put("{" + Definitions.CONFIGURATION_NAMESPACE + "}configuration", configuration);
        params.put("{" + Definitions.REQUEST_NAMESPACE + "}request", request);
        params.put("{" + Definitions.RESPONSE_NAMESPACE + "}response", response);
        params.put("{" + Definitions.SESSION_NAMESPACE + "}session", request.getSession());
        params.put("{" + Definitions.INFOFUZE_NAMESPACE + "}development-mode", new Boolean(Config.getInstance().isDevelopmentMode()));
        Transformer transformer = new Transformer();
        transformer.setTransformationFile(transformationFile);
        transformer.setParams(params);
        transformer.setTransformMode(TransformMode.NORMAL);
        transformer.setConfiguration(configuration);
        transformer.setErrorListener(new TransformationErrorListener(response));
        transformer.setLogInfo(false);
        String method = transformer.getOutputProperties().getProperty(OutputKeys.METHOD, "xml");
        String contentType;
        if (method.endsWith("html")) {
            contentType = Definitions.MIMETYPE_HTML;
        } else if (method.equals("xml")) {
            contentType = Definitions.MIMETYPE_XML;
        } else {
            contentType = Definitions.MIMETYPE_TEXTPLAIN;
        }
        String encoding = transformer.getOutputProperties().getProperty(OutputKeys.ENCODING, "UTF-8");
        response.setContentType(contentType + ";charset=" + encoding);
        DataSourceIf dataSource = new NullSource();
        transformer.transform((Source) dataSource, result);
        if (isDevelopmentMode) {
            IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), response.getOutputStream());
        }
    }
private boolean copyOldSetupClass(File lastVerPath, File destPath) throws java.io.FileNotFoundException, IOException {
        byte[] buf;
        File oldClass = new File(lastVerPath.getAbsolutePath() + File.separator + installClassName_ + ".class");
        if (oldClass.exists()) {
            FileOutputStream out = new FileOutputStream(destPath.getAbsolutePath() + File.separator + installClassName_ + ".class");
            FileInputStream in = new FileInputStream(oldClass);
            buf = new byte[(new Long(oldClass.length())).intValue()];
            int read = in.read(buf, 0, buf.length);
            out.write(buf, 0, read);
            out.close();
            in.close();
            return true;
        }
        return false;
    }