semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private synchronized void loadDDL() throws IOException {
        try {
            conn.createStatement().executeQuery("SELECT * FROM non_generic_favs").close();
        } catch (SQLException e) {
            Statement stmt = null;
            if (!e.getMessage().matches(ERR_MISSING_TABLE)) {
                e.printStackTrace(System.out);
                throw new IOException("Error on initial data store read");
            }
            String[] qry = { "CREATE TABLE non_generic_favs (id INT NOT NULL PRIMARY KEY)", "CREATE TABLE ignore_chan_favs (id INT NOT NULL PRIMARY KEY, chanlist LONG VARCHAR)", "CREATE TABLE settings (var VARCHAR(32) NOT NULL, val VARCHAR(255) NOT NULL, PRIMARY KEY(var))", "INSERT INTO settings (var, val) VALUES ('schema', '1')" };
            try {
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                for (String q : qry) stmt.executeUpdate(q);
                conn.commit();
            } catch (SQLException e2) {
                try {
                    conn.rollback();
                } catch (SQLException e3) {
                    e3.printStackTrace(System.out);
                }
                e2.printStackTrace(new PrintWriter(System.out));
                throw new IOException("Error initializing data store");
            } finally {
                if (stmt != null) {
                    try {
                        stmt.close();
                    } catch (SQLException e4) {
                        e4.printStackTrace(System.out);
                        throw new IOException("Unable to cleanup data store resources");
                    }
                }
                try {
                    conn.setAutoCommit(true);
                } catch (SQLException e3) {
                    e3.printStackTrace(System.out);
                    throw new IOException("Unable to reset data store auto commit");
                }
            }
        }
        return;
    }
public static Object transmitObject(String servletURL, Object obj) throws IOException {
        URL url;
        URLConnection conn;
        InputStream is;
        OutputStream os;
        try {
            if (servletURL.startsWith("https") || servletURL.startsWith("HTTPS")) {
                System.out.println(Jvm.class.getName() + ".transmitObject is initializing ssl");
                Jvm.initSSL();
            }
        } catch (Throwable t) {
            System.out.println(Jvm.class.getName() + ".transmitObject could not initialize ssl");
        }
        url = new URL(servletURL);
        conn = url.openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestProperty("Content-Type", "application/octet-stream");
        conn.setUseCaches(false);
        os = conn.getOutputStream();
        writeSerial(obj, os);
        os.flush();
        os.close();
        try {
            is = conn.getInputStream();
            Object rcvObj = readSerial(is);
            is.close();
            return rcvObj;
        } catch (IOException x2) {
            x2.printStackTrace();
            return null;
        } catch (ClassNotFoundException cnfe) {
            cnfe.printStackTrace();
            return null;
        }
    }
public void initialize(AtomPropsMenu menu) {
        propertiesMenu = menu;
        if (shieldings == null) {
            try {
                URL url = this.getClass().getClassLoader().getResource(RF);
                InputStreamReader isr = new InputStreamReader(url.openStream());
                BufferedReader br = new BufferedReader(isr);
                SharcReader sr1 = new SharcReader(br);
                shieldings = new Hashtable();
                while (sr1.hasNext()) {
                    SharcShielding ss1 = sr1.next();
                    shieldings.put(ss1.getMethod(), ss1);
                }
                String[] shieldingNames = new String[shieldings.size()];
                int i = 0;
                Enumeration k = shieldings.keys();
                while (k.hasMoreElements()) {
                    shieldingNames[i] = (String) k.nextElement();
                    i++;
                }
                dialog = new SelectSharcReference(null, shieldingNames, true);
            } catch (Exception ex) {
                shieldings = null;
            }
        }
    }
private void copyFiles(File oldFolder, File newFolder) {
        for (File fileToCopy : oldFolder.listFiles()) {
            File copiedFile = new File(newFolder.getAbsolutePath() + "\\" + fileToCopy.getName());
            try {
                FileInputStream source = new FileInputStream(fileToCopy);
                FileOutputStream destination = new FileOutputStream(copiedFile);
                FileChannel sourceFileChannel = source.getChannel();
                FileChannel destinationFileChannel = destination.getChannel();
                long size = sourceFileChannel.size();
                sourceFileChannel.transferTo(0, size, destinationFileChannel);
                source.close();
                destination.close();
            } catch (Exception exc) {
                exc.printStackTrace();
            }
        }
    }
private void copyOneFile(String oldPath, String newPath) {
        File copiedFile = new File(newPath);
        try {
            FileInputStream source = new FileInputStream(oldPath);
            FileOutputStream destination = new FileOutputStream(copiedFile);
            FileChannel sourceFileChannel = source.getChannel();
            FileChannel destinationFileChannel = destination.getChannel();
            long size = sourceFileChannel.size();
            sourceFileChannel.transferTo(0, size, destinationFileChannel);
            source.close();
            destination.close();
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    }
public void run() {
        int requestCount = 0;
        long i0 = System.currentTimeMillis();
        while (requestCount != maxRequests) {
            long r0 = System.currentTimeMillis();
            try {
                url = new URL(requestedUrl);
                logger.debug("Requesting Url, " + url.toString());
                BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                while ((httpResponse = in.readLine()) != null) {
                    logger.trace("Http Response = " + httpResponse);
                }
            } catch (Exception e) {
                logger.fatal("Exception thrown retrievng Url = " + requestedUrl + ", " + e);
                notification.setNotification(e.toString());
            }
            long r1 = System.currentTimeMillis();
            requestedElapsedTime = r1 - r0;
            logger.debug("Request(" + this.getName() + "/" + this.getId() + ") #" + requestCount + " processed, took " + requestedElapsedTime + "ms");
            requestCount++;
        }
        long i1 = System.currentTimeMillis();
        iterationElapsedTime = i1 - i0;
        logger.trace("Iteration elapsed time is " + iterationElapsedTime + "ms for thread ID " + this.getId());
        status.incrementIterationsComplete();
        logger.info("Iteration for Url = " + requestedUrl + ", (" + this.getName() + "/" + this.getId() + ") took " + iterationElapsedTime + "ms");
        try {
            logger.debug("Joining thread(" + this.getId() + ")");
            this.join(100);
        } catch (Exception e) {
            logger.fatal(e);
            notification.setNotification(e.toString());
        }
    }
public static String hashStringMD5(String string) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(string.getBytes());
        byte byteData[] = md.digest();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < byteData.length; i++) {
            sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
        }
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < byteData.length; i++) {
            String hex = Integer.toHexString(0xff & byteData[i]);
            if (hex.length() == 1) hexString.append('0');
            hexString.append(hex);
        }
        return hexString.toString();
    }
private void loadDBConfig(final String adapter) throws IOException {
        final URL url = getClass().getClassLoader().getResource("adapter/" + adapter + ".properties");
        _props = new Properties();
        _props.load(url.openStream());
        _init = true;
    }
public void unzip(String resource) {
        File f = new File(resource);
        if (!f.exists()) throw new RuntimeException("The specified resources does not exist (" + resource + ")");
        String parent = f.getParent().toString();
        try {
            BufferedOutputStream dest = null;
            FileInputStream fis = new FileInputStream(resource);
            ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
            ZipEntry entry;
            while ((entry = zis.getNextEntry()) != null) {
                log.info("Extracting archive entry: " + entry);
                String entryPath = new StringBuilder(parent).append(System.getProperty("file.separator")).append(entry.getName()).toString();
                if (entry.isDirectory()) {
                    log.info("Creating directory: " + entryPath);
                    (new File(entryPath)).mkdir();
                    continue;
                }
                int count;
                byte data[] = new byte[BUFFER];
                FileOutputStream fos = new FileOutputStream(entryPath);
                dest = new BufferedOutputStream(fos, BUFFER);
                while ((count = zis.read(data, 0, BUFFER)) != -1) dest.write(data, 0, count);
                dest.flush();
                dest.close();
            }
            zis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static Reader createReader(TreeLogger logger, URL url) throws UnableToCompleteException {
        try {
            return new InputStreamReader(url.openStream());
        } catch (IOException e) {
            logger.log(TreeLogger.ERROR, "Unable to open resource: " + url, e);
            throw new UnableToCompleteException();
        }
    }
public void readFully(String urlS) throws Exception {
            URL url = new URL(urlS);
            URLConnection conn = url.openConnection();
            InputStream is = conn.getInputStream();
            byte[] data = new byte[10240];
            int b = is.read(data);
            while (b > 0) {
                size += b;
                b = is.read(data);
            }
            is.close();
        }
private static void writeBinaryFile(String filename, String target) throws IOException {
        File outputFile = new File(target);
        AgentFilesystem.forceDir(outputFile.getParent());
        FileOutputStream output = new FileOutputStream(new File(target));
        FileInputStream inputStream = new FileInputStream(filename);
        byte[] buffer = new byte[4096];
        int bytesRead = 0;
        while ((bytesRead = inputStream.read(buffer)) > -1) output.write(buffer, 0, bytesRead);
        inputStream.close();
        output.close();
    }
public static String getFileContentFromPlugin(String path) {
        URL url = getURLFromPlugin(path);
        StringBuffer sb = new StringBuffer();
        try {
            Scanner scanner = new Scanner(url.openStream());
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                sb.append(line + "\n");
            }
            scanner.close();
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return sb.toString();
    }
public static boolean copyFile(File sourceFile, File destFile) {
        FileChannel srcChannel = null;
        FileChannel dstChannel = null;
        try {
            srcChannel = new FileInputStream(sourceFile).getChannel();
            dstChannel = new FileOutputStream(destFile).getChannel();
            long pos = 0;
            long count = srcChannel.size();
            if (count > MAX_BLOCK_SIZE) {
                count = MAX_BLOCK_SIZE;
            }
            long transferred = Long.MAX_VALUE;
            while (transferred > 0) {
                transferred = dstChannel.transferFrom(srcChannel, pos, count);
                pos = transferred;
            }
        } catch (IOException e) {
            return false;
        } finally {
            if (srcChannel != null) {
                try {
                    srcChannel.close();
                } catch (IOException e) {
                }
            }
            if (dstChannel != null) {
                try {
                    dstChannel.close();
                } catch (IOException e) {
                }
            }
        }
        return true;
    }
public boolean synch(boolean verbose) {
        try {
            this.verbose = verbose;
            if (verbose) System.out.println(" -- Synchronizing: " + destDir + " to " + urlStr);
            URLConnection urc = new URL(urlStr + "/" + MANIFEST).openConnection();
            InputStream is = urc.getInputStream();
            BufferedReader r = new BufferedReader(new InputStreamReader(is));
            while (true) {
                String str = r.readLine();
                if (str == null) {
                    break;
                }
                dealWith(str);
            }
            is.close();
        } catch (Exception ex) {
            System.out.println("Synchronization of " + destDir + " failed.");
            ex.printStackTrace();
            return false;
        }
        return true;
    }
private void dealWith(String line) throws Exception {
        if (line.startsWith("#") || (line.length() == 0)) {
            return;
        }
        String sarr[];
        sarr = StringUtil.split(line, '\t');
        String path = destDir + File.separator + sarr[0];
        boolean copyFile = true;
        if (sarr.length == 2) {
            try {
                String serverHash = sarr[1];
                String fileHash = loadFileHash(destDir + File.separator + sarr[0]);
                if (fileHash != null) {
                    if (serverHash.equalsIgnoreCase(fileHash)) {
                        copyFile = false;
                    } else {
                        if (verbose) {
                            System.out.println(" -- " + sarr[0] + " has changed");
                        }
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.println(ex.getMessage());
                System.exit(2);
            }
        }
        if (copyFile) {
            int idx = path.lastIndexOf('/');
            if (idx > 0) {
                String dir = path.substring(0, idx);
                File f = new File(dir);
                f.mkdirs();
            }
            FileOutputStream os = new FileOutputStream(path);
            byte buf[] = new byte[1024];
            URLConnection urc = new URL(urlStr + "/" + sarr[0]).openConnection();
            InputStream is = urc.getInputStream();
            boolean done = false;
            while (!done) {
                int read = is.read(buf, 0, 1024);
                if (read == -1) {
                    done = true;
                } else {
                    os.write(buf, 0, read);
                }
            }
            os.close();
            is.close();
            if (verbose) {
                System.out.println(" -- Copied: " + sarr[0]);
            }
        }
    }
public Bitmap retrieveBitmap(String urlString) {
        Log.d(Constants.LOG_TAG, "making HTTP trip for image:" + urlString);
        Bitmap bitmap = null;
        try {
            URL url = new URL(urlString);
            URLConnection conn = url.openConnection();
            conn.setConnectTimeout(3000);
            conn.setReadTimeout(5000);
            bitmap = BitmapFactory.decodeStream(conn.getInputStream());
        } catch (MalformedURLException e) {
            Log.e(Constants.LOG_TAG, "Exception loading image, malformed URL", e);
        } catch (IOException e) {
            Log.e(Constants.LOG_TAG, "Exception loading image, IO error", e);
        }
        return bitmap;
    }
public Font getFont(String urlToFont) {
        Font testFont = null;
        try {
            InputStream inps = (new URL(urlToFont)).openStream();
            testFont = Font.createFont(Font.TRUETYPE_FONT, inps);
        } catch (FontFormatException ffe) {
            ffe.printStackTrace();
        } catch (IOException ioe) {
            JOptionPane.showMessageDialog(null, "Could not load font - " + urlToFont, "Unable to load font", JOptionPane.WARNING_MESSAGE);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return testFont;
    }
public static String digestString(String data) {
        String result = null;
        if (data != null) {
            try {
                MessageDigest _md = MessageDigest.getInstance("MD5");
                _md.update(data.getBytes());
                byte[] _digest = _md.digest();
                String _ds = toHexString(_digest, 0, _digest.length);
                result = _ds;
            } catch (NoSuchAlgorithmException e) {
                result = null;
            }
        }
        return result;
    }
protected List<Datastream> getDatastreams(final DepositCollection pDeposit) throws IOException, SWORDException {
        LOG.debug("copying file");
        String tTempFileName = this.getTempDir() + "uploaded-file.tmp";
        IOUtils.copy(pDeposit.getFile(), new FileOutputStream(tTempFileName));
        Datastream tDatastream = new LocalDatastream(this.getGenericFileName(pDeposit), this.getContentType(), tTempFileName);
        List<Datastream> tDatastreams = new ArrayList<Datastream>();
        tDatastreams.add(tDatastream);
        return tDatastreams;
    }
public InputStream getResourceAsStream(String name) {
        InputStream is = parent.getResourceAsStream(name);
        if (is == null) {
            URL url = findResource(name);
            if (url != null) {
                try {
                    is = url.openStream();
                } catch (IOException e) {
                    is = null;
                }
            }
        }
        return is;
    }
protected byte[] generateHashBytes() {
        String s = createString(false);
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException nsa) {
            System.out.println("Can't get MD5 implementation " + nsa);
            throw new RuntimeException("DynanmicAddress2: Can't get MD5 implementation");
        }
        if (m_key != null) md.update(m_key.getBytes(), 0, m_key.length());
        md.update(s.getBytes(), 0, s.length());
        byte[] hash = md.digest();
        return hash;
    }
@Transient
    private String md5sum(String text) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.reset();
            md.update(text.getBytes());
            byte messageDigest[] = md.digest();
            return bufferToHex(messageDigest, 0, messageDigest.length);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
public static Model downloadModel(String url) {
        Model model = ModelFactory.createDefaultModel();
        try {
            URLConnection connection = new URL(url).openConnection();
            if (connection instanceof HttpURLConnection) {
                HttpURLConnection httpConnection = (HttpURLConnection) connection;
                httpConnection.setRequestProperty("Accept", "application/rdf+xml, */*;q=.1");
                httpConnection.setRequestProperty("Accept-Language", "en");
            }
            InputStream in = connection.getInputStream();
            model.read(in, url);
            in.close();
            return model;
        } catch (MalformedURLException e) {
            cat.debug("Unable to download model from " + url, e);
            throw new RuntimeException(e);
        } catch (IOException e) {
            cat.debug("Unable to download model from " + url, e);
            throw new RuntimeException(e);
        }
    }
public static File jar(File in, String outArc, File tempDir, PatchConfigXML conf) {
        FileOutputStream arcFile = null;
        JarOutputStream jout = null;
        DirectoryScanner ds = null;
        ds = new DirectoryScanner();
        ds.setCaseSensitive(true);
        ds.setBasedir(in);
        ds.scan();
        ds.setCaseSensitive(true);
        String[] names = ds.getIncludedFiles();
        ArrayList exName = new ArrayList();
        if (names == null || names.length < 1) return null;
        File tempArc = new File(tempDir, outArc.substring(0, outArc.length()));
        try {
            Manifest mf = null;
            List v = new ArrayList();
            for (int i = 0; i < names.length; i++) {
                if (names[i].toUpperCase().indexOf("MANIFEST.MF") > -1) {
                    FileInputStream fis = new FileInputStream(in.getAbsolutePath() + "/" + names[i].replace('\\', '/'));
                    mf = new Manifest(fis);
                } else v.add(names[i]);
            }
            String[] toJar = new String[v.size()];
            v.toArray(toJar);
            tempArc.createNewFile();
            arcFile = new FileOutputStream(tempArc);
            if (mf == null) jout = new JarOutputStream(arcFile); else jout = new JarOutputStream(arcFile, mf);
            byte[] buffer = new byte[1024];
            for (int i = 0; i < toJar.length; i++) {
                if (conf != null) {
                    if (!conf.allowFileAction(toJar[i], PatchConfigXML.OP_CREATE)) {
                        exName.add(toJar[i]);
                        continue;
                    }
                }
                String currentPath = in.getAbsolutePath() + "/" + toJar[i];
                String entryName = toJar[i].replace('\\', '/');
                JarEntry currentEntry = new JarEntry(entryName);
                jout.putNextEntry(currentEntry);
                FileInputStream fis = new FileInputStream(currentPath);
                int len;
                while ((len = fis.read(buffer)) >= 0) jout.write(buffer, 0, len);
                fis.close();
                jout.closeEntry();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                jout.close();
                arcFile.close();
            } catch (IOException e1) {
                throw new RuntimeException(e1);
            }
        }
        return tempArc;
    }
public static void main(String[] args) throws Exception {
        System.out.println("Opening destination cbrout.jizz");
        OutputStream out = new BufferedOutputStream(new FileOutputStream("cbrout.jizz"));
        System.out.println("Opening source output.jizz");
        InputStream in = new CbrLiveStream(new BufferedInputStream(new FileInputStream("output.jizz")), System.currentTimeMillis() + 10000, 128);
        System.out.println("Starting read/write loop");
        boolean started = false;
        int len;
        byte[] buf = new byte[4 * 1024];
        while ((len = in.read(buf)) > -1) {
            if (!started) {
                System.out.println("Starting at " + new Date());
                started = true;
            }
            out.write(buf, 0, len);
        }
        System.out.println("Finished at " + new Date());
        out.close();
        in.close();
    }
public static Document getDocument(URL url, boolean validate) throws QTIParseException {
        try {
            return getDocument(new InputSource(url.openStream()), validate, null);
        } catch (IOException ex) {
            throw new QTIParseException(ex);
        }
    }