semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void execute() {
        try {
            if (methods == null) {
                return;
            }
            List<Resource> resources = new ArrayList<Resource>();
            for (Iterator<Resource> i = classFiles.iterator(); i.hasNext(); ) {
                final Resource classFile = i.next();
                if (!classFile.getName().equals(CALLSTACK_FILE)) {
                    try {
                        InputStream inputStream = classFile.getInputStream();
                        ClassReader reader = new ClassReader(inputStream);
                        reader.accept(new MethodAnalyzer(), 0);
                        resources.add(classFile);
                        oldSize += classFile.getSize();
                    } catch (IllegalStateException e) {
                    }
                }
            }
            for (Iterator<Resource> i = resources.iterator(); i.hasNext(); ) {
                final Resource classFile = i.next();
                try {
                    InputStream inputStream = classFile.getInputStream();
                    ClassReader reader = new ClassReader(inputStream);
                    ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_MAXS);
                    if (!classFile.getName().startsWith(CALLSTACK_FILE.substring(0, CALLSTACK_FILE.indexOf('.')))) {
                        reader.accept(new MethodInjector(writer), 0);
                        byte[] b = writer.toByteArray();
                        inputStream.close();
                        OutputStream outputStream = classFile.getOutputStream();
                        outputStream.write(b);
                        outputStream.close();
                        injectedClasses++;
                    }
                } catch (IllegalStateException e) {
                }
                newSize += classFile.getSize();
            }
            File classFile = new File(classFiles.getDir(), CALLSTACK_FILE);
            if (!classFile.exists()) {
                throw new BuildException("Missing net.yura.mobile.logging.CallStack class");
            }
            InputStream inputStream = new FileInputStream(classFile);
            ClassReader reader = new ClassReader(inputStream);
            ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_MAXS);
            try {
                reader.accept(new PushMethodGenerator(writer), 0);
            } finally {
                inputStream.close();
            }
            byte[] b = writer.toByteArray();
            inputStream.close();
            OutputStream outputStream = new FileOutputStream(classFile);
            outputStream.write(b);
            outputStream.close();
            log(injectedClasses + " classes injected");
            log((injectedMethods * 100) / Math.max(1, totalMethods) + "% of methods injected");
            log((100 - ((oldSize * 100) / newSize)) + "% code size increase");
        } catch (IOException e) {
            log(e, 0);
        }
    }
private String getShaderIncludeSource(String path) throws Exception {
        URL url = this.getClass().getResource(path);
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        boolean run = true;
        String str;
        String ret = new String();
        while (run) {
            str = in.readLine();
            if (str != null) ret += str + "\n"; else run = false;
        }
        in.close();
        return ret;
    }
protected String getLibJSCode() throws IOException {
        if (cachedLibJSCode == null) {
            InputStream is = getClass().getResourceAsStream(JS_LIB_FILE);
            StringWriter output = new StringWriter();
            IOUtils.copy(is, output);
            cachedLibJSCode = output.toString();
        }
        return cachedLibJSCode;
    }
public static void addClasses(URL url) {
        BufferedReader reader = null;
        String line;
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        try {
            reader = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if ((line.length() == 0) || line.startsWith(";")) {
                    continue;
                }
                try {
                    classes.add(Class.forName(line, true, cl));
                } catch (Throwable t) {
                }
            }
        } catch (Throwable t) {
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (Throwable t) {
                }
            }
        }
    }
public boolean loadResource(String resourcePath) {
        try {
            URL url = Thread.currentThread().getContextClassLoader().getResource(resourcePath);
            if (url == null) {
                logger.error("Cannot find the resource named: '" + resourcePath + "'. Failed to load the keyword list.");
                return false;
            }
            InputStreamReader isr = new InputStreamReader(url.openStream());
            BufferedReader br = new BufferedReader(isr);
            String ligne = br.readLine();
            while (ligne != null) {
                if (!contains(ligne.toUpperCase())) addLast(ligne.toUpperCase());
                ligne = br.readLine();
            }
            return true;
        } catch (IOException ioe) {
            logger.log(Level.ERROR, "Cannot load default SQL keywords file.", ioe);
        }
        return false;
    }
static byte[] genDigest(String pad, byte[] passwd) throws NoSuchAlgorithmException {
        MessageDigest digest = MessageDigest.getInstance(DIGEST_ALGORITHM);
        digest.update(pad.getBytes());
        digest.update(passwd);
        return digest.digest();
    }
private static boolean execute(String query) throws SQLException {
        boolean success = true;
        try {
            PreparedStatement stm = con.prepareStatement(query);
            stm.executeUpdate();
            stm.close();
            con.commit();
        } catch (SQLException e) {
            try {
                con.rollback();
            } catch (Exception rbex) {
                rbex.printStackTrace();
            }
            success = false;
            throw e;
        }
        return success;
    }
private void loadMe(final ResourceBackedScript e) {
        if (!loadedResources.containsKey(this.resourceLocation)) {
            final InputStream resourceAsStream = this.getClass().getResourceAsStream(this.resourceLocation);
            final StringWriter writer = new StringWriter();
            try {
                IOUtils.copy(resourceAsStream, writer);
            } catch (final IOException ex) {
                throw new IllegalStateException("Resource not read-able", ex);
            }
            final String loadedResource = writer.toString();
            loadedResources.put(this.resourceLocation, loadedResource);
        }
        this.setScriptBody(loadedResources.get(this.resourceLocation));
        this.hasRendered = true;
    }
public static String readFromURL(String urlStr) throws IOException {
        URL url = new URL(urlStr);
        StringBuilder sb = new StringBuilder();
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            sb.append(inputLine);
        }
        in.close();
        return sb.toString();
    }
PathElement(String path) throws MaxError {
            this.path = path;
            if (path.startsWith("http:")) {
                try {
                    url = new URL(path);
                    HttpURLConnection con = (HttpURLConnection) url.openConnection();
                    con.setRequestMethod("HEAD");
                    valid = (con.getResponseCode() == HttpURLConnection.HTTP_OK);
                } catch (Exception e) {
                    valid = false;
                }
            } else {
                if (path.startsWith("jmax:")) file = new File(Registry.resolveJMaxURI(path)); else file = new File(path);
                valid = file.exists();
            }
        }
protected Template read(URL url) throws TemplateException {
        String parent = Parent(url);
        TemplateLoaderContext context = new TemplateLoaderContext(this, parent, false);
        String contents;
        InputStream in = null;
        try {
            in = url.openStream();
            contents = this.readToString(new java.io.InputStreamReader(in));
        } catch (IOException exc) {
            throw new TemplateException(url.toString(), exc);
        } finally {
            try {
                in.close();
            } catch (IOException ignore) {
            }
        }
        TemplateParser parser = this.parser;
        if (null == parser) return (new Template(contents, context)); else return (new Template(parser, contents, context));
    }
public static void copyFile(File srcFile, File destFile) throws IOException {
        logger.debug("copyFile(srcFile={}, destFile={}) - start", srcFile, destFile);
        FileChannel srcChannel = new FileInputStream(srcFile).getChannel();
        FileChannel dstChannel = new FileOutputStream(destFile).getChannel();
        try {
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        } finally {
            srcChannel.close();
            dstChannel.close();
        }
    }
public static int executeNoQuery(String strStatement) throws SQLException {
        MyDBConnection myc = new MyDBConnection();
        myc.init();
        Statement statement = myc.getMyConnection().createStatement();
        try {
            int rows = statement.executeUpdate(strStatement);
            myc.myConnection.commit();
            return rows;
        } catch (SQLException e) {
            myc.myConnection.rollback();
            throw new SQLException("rollback e close effettuato dopo " + e.getMessage());
        } finally {
            myc.close();
        }
    }
public static String generateGuid(boolean secure) {
        MessageDigest md5 = null;
        String valueBeforeMD5 = null;
        String valueAfterMD5 = null;
        StringBuffer sbValueBeforeMD5 = new StringBuffer();
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            log.error("Error: " + e);
        }
        try {
            long time = System.currentTimeMillis();
            long rand = 0L;
            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 < 16) sb.append('0');
                sb.append(Integer.toHexString(b));
            }
            valueAfterMD5 = sb.toString();
        } catch (Exception e) {
            log.error("Error:" + e);
        }
        String raw = valueAfterMD5.toUpperCase();
        StringBuffer sb = new StringBuffer();
        sb.append(raw.substring(0, 8));
        sb.append("-");
        sb.append(raw.substring(8, 12));
        sb.append("-");
        sb.append(raw.substring(12, 16));
        sb.append("-");
        sb.append(raw.substring(16, 20));
        sb.append("-");
        sb.append(raw.substring(20));
        return sb.toString();
    }
public void run() {
        if (software == null) return;
        Jvm.hashtable(HKEY).put(software, this);
        try {
            software.setException(null);
            software.setDownloaded(false);
            software.setDownloadStartTime(System.currentTimeMillis());
            try {
                software.downloadStarted();
            } catch (Exception dsx) {
            }
            if (software.getDownloadDir() == null) {
                software.setException(new Exception("The DownloadDir is null."));
                software.setDownloadStartTime(0);
                software.setDownloaded(false);
                throw software.getException();
            }
            URL url = new URL(software.getURL());
            URLConnection con = url.openConnection();
            software.setDownloadLength(con.getContentLength());
            inputStream = con.getInputStream();
            File file = new File(software.getDownloadDir(), software.getURLFilename());
            outputStream = new FileOutputStream(file);
            int totalBytes = 0;
            byte[] buffer = new byte[8192];
            while (!cancelled) {
                int bytesRead = Jvm.copyPartialStream(inputStream, outputStream, buffer);
                if (bytesRead == -1) break;
                totalBytes += bytesRead;
                try {
                    software.downloadProgress(totalBytes);
                } catch (Exception dx) {
                }
            }
            if (!cancelled) software.setDownloaded(true);
        } catch (Exception x) {
            software.setException(x);
            software.setDownloadStartTime(0);
            software.setDownloaded(false);
        }
        try {
            software.downloadComplete();
        } catch (Exception dcx) {
        }
        Jvm.hashtable(HKEY).remove(software);
        closeStreams();
    }
protected void copyFile(final String sourceFileName, final File path) throws IOException {
        final File source = new File(sourceFileName);
        final File destination = new File(path, source.getName());
        FileChannel srcChannel = null;
        FileChannel dstChannel = null;
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            fileInputStream = new FileInputStream(source);
            srcChannel = fileInputStream.getChannel();
            fileOutputStream = new FileOutputStream(destination);
            dstChannel = fileOutputStream.getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        } finally {
            try {
                if (dstChannel != null) {
                    dstChannel.close();
                }
            } catch (Exception exception) {
            }
            try {
                if (srcChannel != null) {
                    srcChannel.close();
                }
            } catch (Exception exception) {
            }
            try {
                fileInputStream.close();
            } catch (Exception exception) {
            }
            try {
                fileOutputStream.close();
            } catch (Exception exception) {
            }
        }
    }
public boolean backupFile(File oldFile, File newFile) {
        boolean isBkupFileOK = false;
        FileChannel sourceChannel = null;
        FileChannel targetChannel = null;
        try {
            sourceChannel = new FileInputStream(oldFile).getChannel();
            targetChannel = new FileOutputStream(newFile).getChannel();
            targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        } catch (IOException e) {
            logger.log(Level.SEVERE, "IO exception occurred while copying file", e);
        } finally {
            if ((newFile != null) && (newFile.exists()) && (newFile.length() > 0)) {
                isBkupFileOK = true;
            }
            try {
                if (sourceChannel != null) {
                    sourceChannel.close();
                }
                if (targetChannel != null) {
                    targetChannel.close();
                }
            } catch (IOException e) {
                logger.info("closing channels failed");
            }
        }
        return isBkupFileOK;
    }
void copyFile(File src, File dst) throws IOException {
        FileInputStream fis = new FileInputStream(src);
        byte[] buf = new byte[10000];
        int n;
        FileOutputStream fos = new FileOutputStream(dst);
        while ((n = fis.read(buf)) > 0) fos.write(buf, 0, n);
        fis.close();
        fos.close();
        copied++;
    }
public void contextInitialized(ServletContextEvent event) {
        try {
            String osName = System.getProperty("os.name");
            if (osName != null && osName.toLowerCase().contains("windows")) {
                URL url = new URL("http://localhost/");
                URLConnection urlConn = url.openConnection();
                urlConn.setDefaultUseCaches(false);
            }
        } catch (Throwable t) {
        }
    }
@Test
    public void testValidLogConfiguration() throws IOException, IllegalArgumentException {
        URL url = ClassLoader.getSystemResource(PROPERTIES_FILE_NAME);
        if (url == null) {
            throw new IOException("Could not find configuration file " + PROPERTIES_FILE_NAME + " in class path");
        }
        Properties properties = new Properties();
        properties.load(url.openStream());
        LogLevel logLevel = LogLevel.valueOf((String) properties.get(PROPERTY_KEY_LOGLEVEL));
        if (logLevel == null) {
            throw new IOException("Invalid configuration file " + PROPERTIES_FILE_NAME + ": no entry for " + PROPERTY_KEY_LOGLEVEL);
        }
        String loggerIdentifier = "Test logger";
        Logger logger = LoggerFactory.getLogger(loggerIdentifier);
        assertEquals("Logger has wrong log level", logLevel, logger.getLogLevel());
    }
private boolean CheckConnection() {
        boolean b = false;
        String host = "" + Settings.getHost();
        String user = "" + Settings.getUser();
        String pass = "" + Settings.getPass();
        int port = Settings.getPort();
        if (!ftp.isConnected()) {
            try {
                int reply;
                ftp.connect(host, port);
                ftp.login(user, pass);
                ftp.enterLocalPassiveMode();
                reply = ftp.getReplyCode();
                if (!FTPReply.isPositiveCompletion(reply)) {
                    ftp.disconnect();
                    Settings.out("Error, connection refused from the FTP server." + host, 4);
                    b = false;
                } else {
                    b = true;
                }
            } catch (IOException e) {
                b = false;
                Settings.out("Error : " + e.toString(), 4);
                if (ftp.isConnected()) {
                    try {
                        ftp.disconnect();
                    } catch (IOException ioe) {
                    }
                }
            }
        } else {
            b = true;
        }
        return b;
    }
static List<String> listProperties(final MetadataType type) {
        List<String> props = new ArrayList<String>();
        try {
            File adapter = File.createTempFile("adapter", null);
            InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(type.adapter);
            if (stream == null) {
                throw new IllegalStateException("Could not load adapter Jar: " + type.adapter);
            }
            FileOutputStream out = new FileOutputStream(adapter);
            IOUtils.copyLarge(stream, out);
            out.close();
            JarFile jar = new JarFile(adapter);
            Enumeration<JarEntry> entries = jar.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                if (entry.getName().endsWith("dtd")) {
                    InputStream inputStream = jar.getInputStream(entry);
                    Scanner s = new Scanner(inputStream);
                    while (s.hasNextLine()) {
                        String nextLine = s.nextLine();
                        if (nextLine.startsWith("<!ELEMENT")) {
                            String prop = nextLine.split(" ")[1];
                            props.add(prop);
                        }
                    }
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return props;
    }
private void generateDocFile(String srcFileName, String s, String destFileName) {
        try {
            ZipFile docxFile = new ZipFile(new File(srcFileName));
            ZipEntry documentXML = docxFile.getEntry("word/document.xml");
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            InputStream documentXMLIS1 = docxFile.getInputStream(documentXML);
            Document doc = dbf.newDocumentBuilder().parse(documentXMLIS1);
            Transformer t = TransformerFactory.newInstance().newTransformer();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            t.transform(new DOMSource(doc), new StreamResult(baos));
            ZipOutputStream docxOutFile = new ZipOutputStream(new FileOutputStream(destFileName));
            Enumeration<ZipEntry> entriesIter = (Enumeration<ZipEntry>) docxFile.entries();
            while (entriesIter.hasMoreElements()) {
                ZipEntry entry = entriesIter.nextElement();
                if (entry.getName().equals("word/document.xml")) {
                    docxOutFile.putNextEntry(new ZipEntry(entry.getName()));
                    byte[] datas = s.getBytes("UTF-8");
                    docxOutFile.write(datas, 0, datas.length);
                    docxOutFile.closeEntry();
                } else if (entry.getName().equals("word/media/image1.png")) {
                    InputStream incoming = new FileInputStream("c:/aaa.jpg");
                    byte[] data = new byte[incoming.available()];
                    int readCount = incoming.read(data, 0, data.length);
                    docxOutFile.putNextEntry(new ZipEntry(entry.getName()));
                    docxOutFile.write(data, 0, readCount);
                    docxOutFile.closeEntry();
                } else {
                    InputStream incoming = docxFile.getInputStream(entry);
                    byte[] data = new byte[incoming.available()];
                    int readCount = incoming.read(data, 0, data.length);
                    docxOutFile.putNextEntry(new ZipEntry(entry.getName()));
                    docxOutFile.write(data, 0, readCount);
                    docxOutFile.closeEntry();
                }
            }
            docxOutFile.close();
        } catch (Exception e) {
        }
    }
public static String md5(String s) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(s.getBytes());
            byte[] md5sum = digest.digest();
            BigInteger bigInt = new BigInteger(1, md5sum);
            String output = bigInt.toString(16);
            return prepad(output, 32, '0');
        } catch (NoSuchAlgorithmException e) {
            System.err.println("No MD5 algorithm. we are sunk.");
            return s;
        }
    }
public String transformByMD5(String password) throws XSServiceException {
        MessageDigest md5;
        byte[] output;
        StringBuffer bufferPass;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            logger.warn("DataAccessException thrown while getting MD5 algorithm:" + e.getMessage(), e);
            throw new XSServiceException("Database error while saving user");
        }
        md5.reset();
        md5.update(password.getBytes());
        output = md5.digest();
        bufferPass = new StringBuffer();
        for (byte b : output) {
            bufferPass.append(Integer.toHexString(0xff & b).length() == 1 ? "0" + Integer.toHexString(0xff & b) : Integer.toHexString(0xff & b));
        }
        return bufferPass.toString();
    }