semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void testJPEGBuffImage() throws MalformedURLException, IOException {
        System.out.println("JPEGCodec BufferedImage:");
        long start = Calendar.getInstance().getTimeInMillis();
        for (int i = 0; i < images.length; i++) {
            String url = Constants.getDefaultURIMediaConnectorBasePath() + "albums/hund/" + images[i];
            InputStream istream = (new URL(url)).openStream();
            JPEGImageDecoder dec = JPEGCodec.createJPEGDecoder(istream);
            BufferedImage image = dec.decodeAsBufferedImage();
            int width = image.getWidth();
            int height = image.getHeight();
            istream.close();
            System.out.println("w: " + width + " - h: " + height);
        }
        long stop = Calendar.getInstance().getTimeInMillis();
        System.out.println("zeit: " + (stop - start));
    }
public void testJPEGRaster() throws MalformedURLException, IOException {
        System.out.println("JPEGCodec RasterImage:");
        long start = Calendar.getInstance().getTimeInMillis();
        for (int i = 0; i < images.length; i++) {
            String url = Constants.getDefaultURIMediaConnectorBasePath() + "albums/hund/" + images[i];
            InputStream istream = (new URL(url)).openStream();
            JPEGImageDecoder dec = JPEGCodec.createJPEGDecoder(istream);
            Raster raster = dec.decodeAsRaster();
            int width = raster.getWidth();
            int height = raster.getHeight();
            istream.close();
            System.out.println("w: " + width + " - h: " + height);
        }
        long stop = Calendar.getInstance().getTimeInMillis();
        System.out.println("zeit: " + (stop - start));
    }
public static void copy(FileInputStream source, FileOutputStream dest) throws IOException {
        FileChannel in = null, out = null;
        try {
            in = source.getChannel();
            out = dest.getChannel();
            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
            out.write(buf);
        } finally {
            if (in != null) in.close();
            if (out != null) out.close();
        }
    }
private void addPNMLFileToLibrary(File selected) {
        try {
            FileChannel srcChannel = new FileInputStream(selected.getAbsolutePath()).getChannel();
            FileChannel dstChannel = new FileOutputStream(new File(matchingOrderXML).getParent() + "/" + selected.getName()).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
            order.add(new ComponentDescription(false, selected.getName().replaceAll(".pnml", ""), 1.0));
            updateComponentList();
        } catch (IOException ioe) {
            JOptionPane.showMessageDialog(dialog, "Could not add the PNML file " + selected.getName() + " to the library!");
        }
    }
private boolean runValidation(PropertyMap map, URL url, URL schema) {
        ValidationDriver vd = new ValidationDriver(map);
        try {
            vd.loadSchema(new InputSource(schema.openStream()));
            return vd.validate(new InputSource(url.openStream()));
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
public void copyFile(String oldPathFile, String newPathFile) {
        try {
            int bytesum = 0;
            int byteread = 0;
            File oldfile = new File(oldPathFile);
            if (oldfile.exists()) {
                InputStream inStream = new FileInputStream(oldPathFile);
                FileOutputStream fs = new FileOutputStream(newPathFile);
                byte[] buffer = new byte[1444];
                while ((byteread = inStream.read(buffer)) != -1) {
                    bytesum += byteread;
                    System.out.println(bytesum);
                    fs.write(buffer, 0, byteread);
                }
                inStream.close();
            }
        } catch (Exception e) {
            message = ("���Ƶ����ļ���������");
        }
    }
private String copyAndHash(InputStream input, File into) throws IOException {
        MessageDigest digest = createMessageDigest();
        DigestInputStream dis = new DigestInputStream(input, digest);
        IOException ex;
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(into);
            IOUtils.copyLarge(dis, fos);
            byte[] hash = digest.digest();
            Formatter formatter = new Formatter();
            for (byte b : hash) {
                formatter.format("%02x", b);
            }
            return formatter.toString();
        } catch (IOException e) {
            ex = e;
        } finally {
            IOUtils.closeQuietly(dis);
            IOUtils.closeQuietly(fos);
        }
        if (logger.isWarnEnabled()) logger.warn("Couldn't retrieve data from input!", ex);
        deleteTempFile(into);
        throw ex;
    }
private static Long statusSWGCraftTime() {
        long current = System.currentTimeMillis() / 1000L;
        if (current < (previousStatusCheck + SWGCraft.STATUS_CHECK_DELAY)) return previousStatusTime;
        URL url = null;
        try {
            synchronized (previousStatusTime) {
                if (current >= previousStatusCheck + SWGCraft.STATUS_CHECK_DELAY) {
                    url = SWGCraft.getStatusTextURL();
                    String statusTime = ZReader.read(url.openStream());
                    previousStatusTime = Long.valueOf(statusTime);
                    previousStatusCheck = current;
                }
                return previousStatusTime;
            }
        } catch (UnknownHostException e) {
            SWGCraft.showUnknownHostDialog(url, e);
        } catch (Throwable e) {
            SWGAide.printDebug("cmgr", 1, "SWGResourceManager:statusSWGCraftTime:", e.toString());
        }
        return Long.valueOf(0);
    }
public static String compressFile(String fileName) throws IOException {
        String newFileName = fileName + ".gz";
        FileInputStream fis = new FileInputStream(fileName);
        FileOutputStream fos = new FileOutputStream(newFileName);
        GZIPOutputStream gzos = new GZIPOutputStream(fos);
        byte[] buf = new byte[10000];
        int bytesRead;
        while ((bytesRead = fis.read(buf)) > 0) gzos.write(buf, 0, bytesRead);
        fis.close();
        gzos.close();
        return newFileName;
    }
public static void compressWithZip(Vector fileList, String zipFileName) throws IOException {
        if (fileList == null || fileList.size() == 0) return;
        FileOutputStream fos = new FileOutputStream(zipFileName);
        ZipOutputStream zos = new ZipOutputStream(fos);
        Iterator iter = fileList.iterator();
        while (iter.hasNext()) {
            String fileName = (String) iter.next();
            int ind = Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'));
            String shortName = "unknown";
            if (ind < fileName.length() - 1) shortName = fileName.substring(ind + 1);
            zos.putNextEntry(new ZipEntry(shortName));
            FileInputStream fis = new FileInputStream(fileName);
            byte[] buf = new byte[10000];
            int bytesRead;
            while ((bytesRead = fis.read(buf)) > 0) zos.write(buf, 0, bytesRead);
            fis.close();
            zos.closeEntry();
        }
        zos.close();
    }
public static String sha1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[40];
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
    }
private void saveStateAsLast(URL url) {
        InputStream sourceStream = null;
        OutputStream destinationStream = null;
        File lastBundlesTxt = getLastBundleInfo();
        try {
            try {
                destinationStream = new FileOutputStream(lastBundlesTxt);
                sourceStream = url.openStream();
                SimpleConfiguratorUtils.transferStreams(sourceStream, destinationStream);
            } finally {
                if (destinationStream != null) destinationStream.close();
                if (sourceStream != null) sourceStream.close();
            }
        } catch (IOException e) {
        }
    }
public static String stringToHash(String text) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA-1");
            md.update(text.getBytes("iso-8859-1"), 0, text.length());
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("Should not happened: SHA-1 algorithm is missing.");
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException("Should not happened: Could not encode text bytes '" + text + "' to iso-8859-1.");
        }
        return new String(Base64.encodeBase64(md.digest()));
    }
private String encryptPassword(String password) throws NoSuchAlgorithmException {
        StringBuffer encryptedPassword = new StringBuffer();
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.reset();
        md5.update(password.getBytes());
        byte digest[] = md5.digest();
        for (int i = 0; i < digest.length; i++) {
            String hex = Integer.toHexString(0xFF & digest[i]);
            if (hex.length() == 1) {
                encryptedPassword.append('0');
            }
            encryptedPassword.append(hex);
        }
        return encryptedPassword.toString();
    }
public FTPUtil(final String server) {
        log.debug("~ftp.FTPUtil() : Creating object");
        ftpClient = new FTPClient();
        try {
            ftpClient.connect(server);
            ftpClient.login("anonymous", "");
            ftpClient.setConnectTimeout(120000);
            ftpClient.setSoTimeout(120000);
            final int reply = ftpClient.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                final String errMsg = "Non-positive completion connecting FTPClient";
                log.warn("~ftp.FTPUtil() : [" + errMsg + "]");
            }
        } catch (IOException ioe) {
            final String errMsg = "Cannot connect and login to ftpClient [" + ioe.getMessage() + "]";
            log.warn("~ftp.FTPUtil() : [" + errMsg + "]");
            ioe.printStackTrace();
        }
    }
protected Set<String> moduleNamesFromReader(URL url) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        Set<String> names = new HashSet<String>();
        String line;
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            Matcher m = nonCommentPattern.matcher(line);
            if (m.find()) {
                names.add(m.group().trim());
            }
        }
        return names;
    }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/plain;charset=UTF-8");
        request.setCharacterEncoding("utf-8");
        HttpURLConnection httpConn = null;
        byte[] result = null;
        try {
            byte[] bytes = HttpUtil.getHttpURLReturnData(request);
            if (-1 == bytes.length || 23 > bytes.length) throw new Exception();
            MsgPrint.showMsg("========byte length" + bytes.length);
            String userTag = request.getParameter("userTag");
            String isEncrypt = request.getParameter("isEncrypt");
            URL httpurl = new URL(ProtocolContanst.TRANSFERS_URL + userTag + "&isEncrypt=" + isEncrypt);
            httpConn = (HttpURLConnection) httpurl.openConnection();
            httpConn.setDoOutput(true);
            httpConn.setRequestProperty("Content-Length", String.valueOf(bytes.length));
            OutputStream outputStream = httpConn.getOutputStream();
            outputStream.write(bytes);
            outputStream.close();
            InputStream is = httpConn.getInputStream();
            if (0 >= httpConn.getContentLength()) {
                throw new Exception();
            }
            byte[] resultBytes = new byte[httpConn.getContentLength()];
            byte[] tempByte = new byte[1024];
            int length = 0;
            int index = 0;
            while ((length = is.read(tempByte)) != -1) {
                System.arraycopy(tempByte, 0, resultBytes, index, length);
                index += length;
            }
            is.close();
            result = resultBytes;
        } catch (Exception e) {
        }
        ServletOutputStream sos = response.getOutputStream();
        if (null != result) {
            response.setContentLength(result.length);
            sos.write(result);
        } else {
            response.setContentLength(26);
            sos.write(new byte[] { 48, 48, 55, -23, 3, 56, 49, 54, 57, 55, 49, 51, 54, 72, 71, 52, 48, 1, 3, 3, 48, 48, 48, 48, 48, 48 });
        }
        sos.flush();
        sos.close();
    }
public File sendPayload(SoapEnvelope payload, URL url) throws IOException {
        URLConnection conn = null;
        File tempFile = null;
        Logger l = Logger.instance();
        String className = getClass().getName();
        l.log(Logger.DEBUG, loggerPrefix, className + ".sendPayload", "sending payload to " + url.toString());
        try {
            conn = url.openConnection();
            conn.setDoOutput(true);
            payload.writeTo(conn.getOutputStream());
            tempFile = readIntoTempFile(conn.getInputStream());
        } catch (IOException ioe) {
            l.log(Logger.ERROR, loggerPrefix, className + ".sendPayload", ioe);
            throw ioe;
        } finally {
            conn = null;
        }
        l.log(Logger.DEBUG, loggerPrefix, className + ".sendPayload", "received response");
        return tempFile;
    }
public File getURL(URL url) throws IOException {
        URLConnection conn = null;
        File tempFile = null;
        Logger l = Logger.instance();
        String className = getClass().getName();
        l.log(Logger.DEBUG, loggerPrefix, className + ".getURL", "GET URL " + url.toString());
        try {
            conn = url.openConnection();
            tempFile = readIntoTempFile(conn.getInputStream());
        } catch (IOException ioe) {
            l.log(Logger.ERROR, loggerPrefix, className + ".getURL", ioe);
            throw ioe;
        } finally {
            conn = null;
        }
        l.log(Logger.DEBUG, loggerPrefix, className + ".getURL", "received URL");
        return tempFile;
    }
public void testRetrieve() throws DigitalObjectManager.DigitalObjectNotFoundException, URISyntaxException, IOException {
        DigitalObjectManager man = new FedoraObjectManager("fedoraAdmin", "fedoraAdminPass", "http://localhost:7910/fedora");
        DigitalObject r = man.retrieve(new URI("demo:dc2mods.1"));
        String title = r.getTitle();
        List<Metadata> met = r.getMetadata();
        InputStream content = r.getContent().read();
        StringWriter theString = new StringWriter();
        IOUtils.copy(content, theString);
        assertNotNull(theString.toString(), "Content should not be null");
        assertNotNull(title, "The title should be set");
        assertNotNull(met.get(0).getContent(), "There should be some metadata");
    }
public static void copyFile(File in, File out) throws IOException {
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) {
                inChannel.close();
            }
            if (outChannel != null) {
                outChannel.close();
            }
        }
    }
protected void innerProcess(ProcessorURI curi) throws InterruptedException {
        Pattern regexpr = curi.get(this, STRIP_REG_EXPR);
        ReplayCharSequence cs = null;
        try {
            cs = curi.getRecorder().getReplayCharSequence();
        } catch (Exception e) {
            curi.getNonFatalFailures().add(e);
            logger.warning("Failed get of replay char sequence " + curi.toString() + " " + e.getMessage() + " " + Thread.currentThread().getName());
            return;
        }
        MessageDigest digest = null;
        try {
            try {
                digest = MessageDigest.getInstance(SHA1);
            } catch (NoSuchAlgorithmException e1) {
                e1.printStackTrace();
                return;
            }
            digest.reset();
            String s = null;
            if (regexpr != null) {
                s = cs.toString();
            } else {
                Matcher m = regexpr.matcher(cs);
                s = m.replaceAll(" ");
            }
            digest.update(s.getBytes());
            byte[] newDigestValue = digest.digest();
            curi.setContentDigest(SHA1, newDigestValue);
        } finally {
            if (cs != null) {
                try {
                    cs.close();
                } catch (IOException ioe) {
                    logger.warning(TextUtils.exceptionToString("Failed close of ReplayCharSequence.", ioe));
                }
            }
        }
    }
public byte[] getCoded(String name, String pass) {
        byte[] digest = null;
        if (pass != null && 0 < pass.length()) {
            try {
                MessageDigest md = MessageDigest.getInstance("SHA-1");
                md.update(name.getBytes());
                md.update(pass.getBytes());
                digest = md.digest();
            } catch (Exception e) {
                e.printStackTrace();
                digest = null;
            }
        }
        return digest;
    }
protected static String getInitialUUID() {
        if (myRand == null) {
            myRand = new Random();
        }
        long rand = myRand.nextLong();
        String sid;
        try {
            sid = InetAddress.getLocalHost().toString();
        } catch (UnknownHostException e) {
            sid = Thread.currentThread().getName();
        }
        StringBuffer sb = new StringBuffer();
        sb.append(sid);
        sb.append(":");
        sb.append(Long.toString(rand));
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
        }
        md5.update(sb.toString().getBytes());
        byte[] array = md5.digest();
        StringBuffer sb2 = new StringBuffer();
        for (int j = 0; j < array.length; ++j) {
            int b = array[j] & 0xFF;
            sb2.append(Integer.toHexString(b));
        }
        int begin = myRand.nextInt();
        if (begin < 0) begin = begin * -1;
        begin = begin % 8;
        return sb2.toString().substring(begin, begin + 18).toUpperCase();
    }
@SuppressWarnings("unchecked")
    public static <T> List<T> getServices(String service) {
        String serviceUri = "META-INF/services/" + service;
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        try {
            Enumeration<URL> urls = loader.getResources(serviceUri);
            if (urls.hasMoreElements()) {
                List<T> services = new ArrayList<T>(1);
                do {
                    URL url = urls.nextElement();
                    _LOG.finest("Processing:{0}", url);
                    try {
                        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                        try {
                            while (true) {
                                String line = in.readLine();
                                if (line == null) break;
                                T instance = (T) _parseLine(loader, line);
                                if (instance != null) services.add(instance);
                            }
                        } finally {
                            in.close();
                        }
                    } catch (Exception e) {
                        _LOG.warning("ERR_PARSING_URL", url);
                        _LOG.warning(e);
                    }
                } while (urls.hasMoreElements());
                if (services.size() == 1) return Collections.singletonList(services.get(0));
                return Collections.unmodifiableList(services);
            }
        } catch (IOException e) {
            _LOG.severe("ERR_LOADING_RESROUCE", serviceUri);
            _LOG.severe(e);
        }
        return Collections.emptyList();
    }
private static String format(String check) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        check = check.replaceAll(" ", "");
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(check.getBytes("ISO-8859-1"));
        byte[] end = md5.digest();
        String digest = "";
        for (int i = 0; i < end.length; i++) {
            digest += ((end[i] & 0xff) < 16 ? "0" : "") + Integer.toHexString(end[i] & 0xff);
        }
        return digest;
    }
private static synchronized void find(String name) throws SAXException, IOException {
        if (c_cache.containsKey(name)) return;
        CustomHandler handler = null;
        URL url = null;
        String validatorFiles = (String) Config.getProperty(Config.PROP_RULES_ENGINE_VALIDATORS_URL_LIST, XML_FILE);
        for (StringTokenizer strtknzr = new StringTokenizer(validatorFiles, ","); strtknzr.hasMoreTokens(); ) {
            String validatorFile = strtknzr.nextToken();
            try {
                url = URLHelper.newExtendedURL(validatorFile);
            } catch (MalformedURLException e) {
                url = null;
            }
            if (url == null) throw new FileNotFoundException("File not found - " + validatorFile);
            try {
                handler = new CustomHandler(name);
                XMLReader reader = XMLReaderFactory.createXMLReader(PARSER_NAME);
                reader.setContentHandler(handler);
                reader.setEntityResolver(new DefaultEntityResolver());
                reader.setErrorHandler(new DefaultErrorHandler());
                reader.parse(new InputSource(url.openStream()));
            } catch (SAXException e) {
                if (SUCCESS_MESSAGE.equals(e.getMessage()) && handler != null) break; else throw e;
            } catch (IOException e) {
                throw e;
            }
            if (handler.getFieldValidatorMetaData() != null) break;
        }
        c_cache.put(name, handler != null ? handler.getFieldValidatorMetaData() : null);
    }
@Test
    public void shouldDownloadFileUsingPublicLink() throws Exception {
        String bucketName = "test-" + UUID.randomUUID();
        Service service = new WebClientService(credentials);
        service.createBucket(bucketName);
        File file = folder.newFile("foo.txt");
        FileUtils.writeStringToFile(file, UUID.randomUUID().toString());
        service.createObject(bucketName, file.getName(), file, new NullProgressListener());
        String publicUrl = service.getPublicUrl(bucketName, file.getName(), new DateTime().plusDays(5));
        File saved = folder.newFile("saved.txt");
        InputStream input = new URL(publicUrl).openConnection().getInputStream();
        FileOutputStream output = new FileOutputStream(saved);
        IOUtils.copy(input, output);
        output.close();
        assertThat("Corrupted download", Files.computeMD5(saved), equalTo(Files.computeMD5(file)));
        service.deleteObject(bucketName, file.getName());
        service.deleteBucket(bucketName);
    }
public static String encryptSHA(String pwd) throws NoSuchAlgorithmException {
        MessageDigest d = java.security.MessageDigest.getInstance("SHA-1");
        d.reset();
        d.update(pwd.getBytes());
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(d.digest());
    }