semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void deletePortletName(PortletName portletNameBean) {
        DatabaseAdapter dbDyn = null;
        PreparedStatement ps = null;
        try {
            dbDyn = DatabaseAdapter.getInstance();
            if (portletNameBean.getPortletId() == null) throw new IllegalArgumentException("portletNameId is null");
            String sql = "delete from  WM_PORTAL_PORTLET_NAME " + "where  ID_SITE_CTX_TYPE=?";
            ps = dbDyn.prepareStatement(sql);
            RsetTools.setLong(ps, 1, portletNameBean.getPortletId());
            int i1 = ps.executeUpdate();
            if (log.isDebugEnabled()) log.debug("Count of deleted records - " + i1);
            dbDyn.commit();
        } catch (Exception e) {
            try {
                if (dbDyn != null) dbDyn.rollback();
            } catch (Exception e001) {
            }
            String es = "Error delete portlet name";
            log.error(es, e);
            throw new IllegalStateException(es, e);
        } finally {
            DatabaseManager.close(dbDyn, ps);
            dbDyn = null;
            ps = null;
        }
    }
public void zipFile(String baseDir, String fileName, boolean encrypt) throws Exception {
        List fileList = getSubFiles(new File(baseDir));
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(fileName + ".temp"));
        ZipEntry ze = null;
        byte[] buf = new byte[BUFFER];
        byte[] encrypByte = new byte[encrypLength];
        int readLen = 0;
        for (int i = 0; i < fileList.size(); i++) {
            if (stopZipFile) {
                zos.close();
                File zipFile = new File(fileName + ".temp");
                if (zipFile.exists()) zipFile.delete();
                break;
            }
            File f = (File) fileList.get(i);
            if (f.getAbsoluteFile().equals(fileName + ".temp")) continue;
            ze = new ZipEntry(getAbsFileName(baseDir, f));
            ze.setSize(f.length());
            ze.setTime(f.lastModified());
            zos.putNextEntry(ze);
            InputStream is = new BufferedInputStream(new FileInputStream(f));
            readLen = is.read(buf, 0, BUFFER);
            if (encrypt) {
                if (readLen >= encrypLength) {
                    System.arraycopy(buf, 0, encrypByte, 0, encrypLength);
                } else if (readLen > 0) {
                    Arrays.fill(encrypByte, (byte) 0);
                    System.arraycopy(buf, 0, encrypByte, 0, readLen);
                    readLen = encrypLength;
                }
                byte[] temp = CryptionControl.getInstance().encryptoECB(encrypByte, rootKey);
                System.arraycopy(temp, 0, buf, 0, encrypLength);
            }
            while (readLen != -1) {
                zos.write(buf, 0, readLen);
                readLen = is.read(buf, 0, BUFFER);
            }
            is.close();
        }
        zos.close();
        File zipFile = new File(fileName + ".temp");
        if (zipFile.exists()) zipFile.renameTo(new File(fileName + ".zip"));
    }
public String transmit(String input, String filePath) throws Exception {
        if (cookie == null || "".equals(urlString)) {
            return null;
        }
        String txt = "";
        StringBuffer returnMessage = new StringBuffer();
        final String boundary = String.valueOf(System.currentTimeMillis());
        URL url = null;
        URLConnection conn = null;
        BufferedReader br = null;
        DataOutputStream dos = null;
        try {
            url = new URL(urlString);
            conn = url.openConnection();
            ((HttpURLConnection) conn).setRequestMethod("POST");
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setAllowUserInteraction(true);
            conn.setUseCaches(false);
            conn.setRequestProperty(HEADER_COOKIE, cookie);
            if (input != null) {
                String auth = "Basic " + new sun.misc.BASE64Encoder().encode(input.getBytes());
                conn.setRequestProperty("Authorization", auth);
            }
            dos = new DataOutputStream(conn.getOutputStream());
            dos.write((starter + boundary + returnChar).getBytes());
            for (int i = 0; i < txtList.size(); i++) {
                HtmlFormText htmltext = (HtmlFormText) txtList.get(i);
                dos.write(htmltext.getTranslated());
                if (i + 1 < txtList.size()) {
                    dos.write((starter + boundary + returnChar).getBytes());
                } else if (fileList.size() > 0) {
                    dos.write((starter + boundary + returnChar).getBytes());
                }
            }
            for (int i = 0; i < fileList.size(); i++) {
                HtmlFormFile htmlfile = (HtmlFormFile) fileList.get(i);
                dos.write(htmlfile.getTranslated());
                if (i + 1 < fileList.size()) {
                    dos.write((starter + boundary + returnChar).getBytes());
                }
            }
            dos.write((starter + boundary + "--" + returnChar).getBytes());
            dos.flush();
            br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
            txt = transactFormStr(br);
            if (!"".equals(filePath) && !"null".equals(filePath)) {
                RandomAccessFile raf = new RandomAccessFile(filePath, "rw");
                raf.seek(raf.length());
                raf.writeBytes(txt + "\n");
                raf.close();
            }
            txtList.clear();
            fileList.clear();
        } catch (Exception e) {
            log.error(e, e);
        } finally {
            try {
                dos.close();
            } catch (Exception e) {
            }
            try {
                br.close();
            } catch (Exception e) {
            }
        }
        return txt;
    }
public ObjectInputStream getObjectInputStreamFromServlet(String strUrl) throws Exception {
        if (cookie == null) {
            return null;
        }
        String starter = "-----------------------------";
        String returnChar = "\r\n";
        String lineEnd = "--";
        String urlString = strUrl;
        String input = null;
        List txtList = new ArrayList();
        List fileList = new ArrayList();
        String targetFile = null;
        String actionStatus = null;
        StringBuffer returnMessage = new StringBuffer();
        List head = new ArrayList();
        final String boundary = String.valueOf(System.currentTimeMillis());
        URL url = null;
        URLConnection conn = null;
        DataOutputStream dos = null;
        ObjectInputStream inputFromServlet = null;
        try {
            url = new URL(urlString);
            conn = url.openConnection();
            ((HttpURLConnection) conn).setRequestMethod("POST");
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setRequestProperty("Content-Type", "multipart/form-data, boundary=" + "---------------------------" + boundary);
            conn.setRequestProperty(HEADER_COOKIE, cookie);
            if (input != null) {
                String auth = "Basic " + new sun.misc.BASE64Encoder().encode(input.getBytes());
                conn.setRequestProperty("Authorization", auth);
            }
            dos = new DataOutputStream(conn.getOutputStream());
            dos.flush();
            inputFromServlet = new ObjectInputStream(conn.getInputStream());
            txtList.clear();
            fileList.clear();
        } catch (Exception e) {
            log.error(e, e);
            return null;
        } finally {
            try {
                dos.close();
            } catch (Exception e) {
            }
        }
        return inputFromServlet;
    }
protected void truncate(File file) {
        LogLog.debug("Compression of file: " + file.getAbsolutePath() + " started.");
        if (FileUtils.isFileOlder(file, ManagementFactory.getRuntimeMXBean().getStartTime())) {
            File backupRoot = new File(getBackupDir());
            if (!backupRoot.exists() && !backupRoot.mkdirs()) {
                throw new AppenderInitializationError("Can't create backup dir for backup storage");
            }
            SimpleDateFormat df;
            try {
                df = new SimpleDateFormat(getBackupDateFormat());
            } catch (Exception e) {
                throw new AppenderInitializationError("Invalid date formate for backup files: " + getBackupDateFormat(), e);
            }
            String date = df.format(new Date(file.lastModified()));
            File zipFile = new File(backupRoot, file.getName() + "." + date + ".zip");
            ZipOutputStream zos = null;
            FileInputStream fis = null;
            try {
                zos = new ZipOutputStream(new FileOutputStream(zipFile));
                ZipEntry entry = new ZipEntry(file.getName());
                entry.setMethod(ZipEntry.DEFLATED);
                entry.setCrc(FileUtils.checksumCRC32(file));
                zos.putNextEntry(entry);
                fis = FileUtils.openInputStream(file);
                byte[] buffer = new byte[1024];
                int readed;
                while ((readed = fis.read(buffer)) != -1) {
                    zos.write(buffer, 0, readed);
                }
            } catch (Exception e) {
                throw new AppenderInitializationError("Can't create zip file", e);
            } finally {
                if (zos != null) {
                    try {
                        zos.close();
                    } catch (IOException e) {
                        LogLog.warn("Can't close zip file", e);
                    }
                }
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (IOException e) {
                        LogLog.warn("Can't close zipped file", e);
                    }
                }
            }
            if (!file.delete()) {
                throw new AppenderInitializationError("Can't delete old log file " + file.getAbsolutePath());
            }
        }
    }
public String getLatestVersion(String website) {
        String latestVersion = "";
        try {
            URL url = new URL(website + "/version");
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(url.openStream()));
            String string;
            while ((string = bufferedReader.readLine()) != null) {
                latestVersion = string;
            }
            bufferedReader.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
        }
        return latestVersion;
    }
public InputStream retrieveStream(String url) {
        HttpGet getRequest = new HttpGet(url);
        try {
            HttpResponse getResponse = getClient().execute(getRequest);
            final int statusCode = getResponse.getStatusLine().getStatusCode();
            if (statusCode != HttpStatus.SC_OK) {
                Log.w(getClass().getSimpleName(), "Error " + statusCode + " for URL " + url);
                return null;
            }
            HttpEntity getResponseEntity = getResponse.getEntity();
            return getResponseEntity.getContent();
        } catch (Exception e) {
            getRequest.abort();
            Log.w(getClass().getSimpleName(), "Error for URL " + url, e);
        }
        return null;
    }
public static void main(String[] args) {
        CookieManager cm = new CookieManager();
        try {
            URL url = new URL("http://www.hccp.org/test/cookieTest.jsp");
            URLConnection conn = url.openConnection();
            conn.connect();
            cm.storeCookies(conn);
            cm.setCookies(url.openConnection());
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
private void processBasicContent() {
        String[] packageNames = sourceCollector.getPackageNames();
        for (int i = 0; i < packageNames.length; i++) {
            XdcSource[] sources = sourceCollector.getXdcSources(packageNames[i]);
            File dir = new File(outputDir, packageNames[i]);
            dir.mkdirs();
            Set pkgDirs = new HashSet();
            for (int j = 0; j < sources.length; j++) {
                XdcSource source = sources[j];
                Properties patterns = source.getPatterns();
                if (patterns != null) {
                    tables.put("patterns", patterns);
                }
                pkgDirs.add(source.getFile().getParentFile());
                DialectHandler dialectHandler = source.getDialectHandler();
                Writer out = null;
                try {
                    String sourceFilePath = source.getFile().getAbsolutePath();
                    source.setProcessingProperties(baseProperties, j > 0 ? sources[j - 1].getFileName() : null, j < sources.length - 1 ? sources[j + 1].getFileName() : null);
                    String rootComment = XslUtils.transformToString(sourceFilePath, XSL_PKG + "/source-header.xsl", tables);
                    source.setRootComment(rootComment);
                    Document htmlDoc = XslUtils.transform(sourceFilePath, encoding, dialectHandler.getXslResourcePath(), tables);
                    if (LOG.isInfoEnabled()) {
                        LOG.info("Processing source file " + sourceFilePath);
                    }
                    out = IOUtils.getWriter(new File(dir, source.getFile().getName() + ".html"), docencoding);
                    XmlUtils.printHtml(out, htmlDoc);
                    if (sourceProcessor != null) {
                        sourceProcessor.processSource(source, encoding, docencoding);
                    }
                    XdcSource.clearProcessingProperties(baseProperties);
                } catch (XmlException e) {
                    LOG.error(e.getMessage(), e);
                } catch (IOException e) {
                    LOG.error(e.getMessage(), e);
                } finally {
                    if (out != null) {
                        try {
                            out.close();
                        } catch (IOException e) {
                            LOG.error(e.getMessage(), e);
                        }
                    }
                }
            }
            for (Iterator iter = pkgDirs.iterator(); iter.hasNext(); ) {
                File docFilesDir = new File((File) iter.next(), "xdc-doc-files");
                if (docFilesDir.exists() && docFilesDir.isDirectory()) {
                    File targetDir = new File(dir, "xdc-doc-files");
                    targetDir.mkdirs();
                    try {
                        IOUtils.copyTree(docFilesDir, targetDir);
                    } catch (IOException e) {
                        LOG.error(e.getMessage(), e);
                    }
                }
            }
        }
    }
private void processStylesheetFile() {
        InputStream in = null;
        OutputStream out = null;
        try {
            String filename;
            if (line.hasOption("stylesheetfile")) {
                filename = line.getOptionValue("stylesheetfile");
                in = new FileInputStream(filename);
                filename = filename.replace('\\', '/');
                filename = filename.substring(filename.lastIndexOf('/') + 1);
            } else {
                ClassLoader cl = this.getClass().getClassLoader();
                filename = "stylesheet.css";
                in = cl.getResourceAsStream(RESOURCE_PKG + "/stylesheet.css");
            }
            baseProperties.setProperty("stylesheetfilename", filename);
            File outFile = new File(outputDir, filename);
            if (LOG.isInfoEnabled()) {
                LOG.info("Processing generated file " + outFile.getAbsolutePath());
            }
            out = new FileOutputStream(outFile);
            IOUtils.copy(in, out);
        } catch (FileNotFoundException e) {
            LOG.error(e.getMessage(), e);
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    LOG.error(e.getMessage(), e);
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    LOG.error(e.getMessage(), e);
                }
            }
        }
    }
private void processHelpFile() {
        InputStream in = null;
        if (line.hasOption("helpfile")) {
            OutputStream out = null;
            try {
                String filename = line.getOptionValue("helpfile");
                in = new FileInputStream(filename);
                filename = filename.replace('\\', '/');
                filename = filename.substring(filename.lastIndexOf('/') + 1);
                File outFile = new File(outputDir, filename);
                if (LOG.isInfoEnabled()) {
                    LOG.info("Processing generated file " + outFile.getAbsolutePath());
                }
                out = new FileOutputStream(outFile);
                baseProperties.setProperty("helpfile", filename);
                IOUtils.copy(in, out);
            } catch (FileNotFoundException e) {
                LOG.error(e.getMessage(), e);
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        LOG.error(e.getMessage(), e);
                    }
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                        LOG.error(e.getMessage(), e);
                    }
                }
            }
            return;
        }
        Properties props = new Properties(baseProperties);
        ClassLoader cl = this.getClass().getClassLoader();
        Document doc = null;
        try {
            in = cl.getResourceAsStream(RESOURCE_PKG + "/help-doc.xml");
            doc = XmlUtils.parse(in);
        } catch (XmlException e) {
            LOG.error(e.getMessage(), e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    LOG.error(e.getMessage(), e);
                }
            }
        }
        transformResource(doc, "help-doc.xsl", props, "help-doc.html");
        baseProperties.setProperty("helpfile", "help-doc.html");
    }
private void getRandomGUID(boolean secure) {
        MessageDigest md5 = null;
        StringBuffer sbValueBeforeMD5 = new StringBuffer();
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            System.out.println("Error: " + e);
        }
        try {
            long time = System.currentTimeMillis();
            long rand = 0;
            if (secure) {
                rand = mySecureRand.nextLong();
            } else {
                rand = myRand.nextLong();
            }
            sbValueBeforeMD5.append(s_id);
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(time));
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(rand));
            valueBeforeMD5 = sbValueBeforeMD5.toString();
            md5.update(valueBeforeMD5.getBytes());
            byte[] array = md5.digest();
            StringBuffer sb = new StringBuffer();
            for (int j = 0; j < array.length; ++j) {
                int b = array[j] & 0xFF;
                if (b < 0x10) {
                    sb.append('0');
                }
                sb.append(Integer.toHexString(b));
            }
            valueAfterMD5 = sb.toString();
        } catch (Exception e) {
            System.out.println("Error:" + e);
        }
    }
byte[] calculateDigest(String value) {
        try {
            MessageDigest mg = MessageDigest.getInstance("SHA1");
            mg.update(value.getBytes());
            return mg.digest();
        } catch (Exception e) {
            throw Bark.unchecker(e);
        }
    }
private static String scramble(String text) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(text.getBytes("UTF-8"));
            StringBuffer sb = new StringBuffer();
            for (byte b : md.digest()) sb.append(Integer.toString(b & 0xFF, 16));
            return sb.toString();
        } catch (UnsupportedEncodingException e) {
            return null;
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }
public void makeRead(String user, long databaseID, long time) throws SQLException {
        String query = "replace into fs.read_post (post, user, read_date) values (?, ?, ?)";
        ensureConnection();
        PreparedStatement statement = m_connection.prepareStatement(query);
        try {
            statement.setLong(1, databaseID);
            statement.setString(2, user);
            statement.setTimestamp(3, new Timestamp(time));
            int count = statement.executeUpdate();
            if (0 == count) throw new SQLException("Nothing updated.");
            m_connection.commit();
        } catch (SQLException e) {
            m_connection.rollback();
            throw e;
        } finally {
            statement.close();
        }
    }
public static boolean encodeFileToFile(String infile, String outfile) {
        boolean success = false;
        java.io.InputStream in = null;
        java.io.OutputStream out = null;
        try {
            in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.ENCODE);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
            byte[] buffer = new byte[65536];
            int read = -1;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
            }
            success = true;
        } catch (java.io.IOException exc) {
            exc.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (Exception exc) {
            }
            try {
                out.close();
            } catch (Exception exc) {
            }
        }
        return success;
    }
public static boolean decodeFileToFile(String infile, String outfile) {
        boolean success = false;
        java.io.InputStream in = null;
        java.io.OutputStream out = null;
        try {
            in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.DECODE);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
            byte[] buffer = new byte[65536];
            int read = -1;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
            }
            success = true;
        } catch (java.io.IOException exc) {
            exc.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (Exception exc) {
            }
            try {
                out.close();
            } catch (Exception exc) {
            }
        }
        return success;
    }
public String getMarketInfo() {
        try {
            URL url = new URL("http://api.eve-central.com/api/evemon");
            BufferedReader s = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = "";
            String xml = "";
            while ((line = s.readLine()) != null) {
                xml += line;
            }
            return xml;
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return null;
    }