當前位置: 首頁>>代碼示例>>Python>>正文


Python BufferedReader.close方法代碼示例

本文整理匯總了Python中java.io.BufferedReader.close方法的典型用法代碼示例。如果您正苦於以下問題:Python BufferedReader.close方法的具體用法?Python BufferedReader.close怎麽用?Python BufferedReader.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.BufferedReader的用法示例。


在下文中一共展示了BufferedReader.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: readWebPage

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
def readWebPage( webpageURL ):
    webpageURL = webpageURL.strip()
    log(VERBOSE_, "readWebpage webpageURL=" + webpageURL)
    url = URL(webpageURL)
    conn = url.openConnection()
    conn.setConnectTimeout(30000)
    conn.setReadTimeout(10000)
    conn.connect()
    responseCode = conn.getResponseCode()
    cookie = conn.getHeaderField("Set-Cookie")
    cookiePath = None
    pathDiscr = " Path="
    if cookie and cookie.find(pathDiscr) > 0:
        cookiePath = cookie[cookie.index(pathDiscr) + len(pathDiscr):]
    respLines = []
    if responseCode >= 400:
        log(ERROR_, "HTTP ERROR " + `responseCode` + ": " + `conn.getResponseMessage()`)
    else:
        log(VERBOSE_, "WebPageResponse status=" + `responseCode` + " reason=" + `conn.getResponseMessage()`)
        #log(DEBUG_,"WebPageResponse resp="+`resp` )
        reader = BufferedReader(InputStreamReader(conn.getInputStream()))
        inputLine = reader.readLine()
        while inputLine is not None:
            respLines.append(inputLine)
            inputLine = reader.readLine()

        reader.close()
    return respLines, cookiePath
開發者ID:ammula88,項目名稱:WebsphereConfigLib,代碼行數:30,代碼來源:application.py

示例2: _reader

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
 def _reader(self):
     stream = getResourceAsStream(self._path)
     reader = BufferedReader(InputStreamReader(stream, 'UTF-8'))
     try:
         yield reader
     finally:
         reader.close()
開發者ID:HelioGuilherme66,項目名稱:RIDE,代碼行數:9,代碼來源:jartemplate.py

示例3: get

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
def get(targetURL, params, username=None):

    paramStr = ""
    for aKey in params.keys():
        paramStr+=aKey+"="+URLEncoder.encode(params[aKey], "UTF-8")+"&"
    paramStr=paramStr[:-1]
    url = URL(targetURL+"?"+paramStr)
    print url
    connection = url.openConnection()

    if username!=None:    
        userpass = username
        basicAuth = "Basic " + base64.b64encode(userpass);
        #print basicAuth
        connection.setRequestProperty ("Authorization", basicAuth);
    
    connection.setRequestMethod("GET")    
    connection.setRequestProperty("Content-Language", "en-GB")
    connection.setUseCaches(0)
    connection.setDoOutput(2)
    
    inStream= connection.getInputStream()
    rd= BufferedReader(InputStreamReader(inStream))
    response = ""
    line = rd.readLine()
    while line != None:
        response +=line+"\r"
        line = rd.readLine()
    rd.close()
    return response
開發者ID:revolutionarysystems,項目名稱:common-test,代碼行數:32,代碼來源:HttpCall.py

示例4: run

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
 def run(self):
     reader = BufferedReader(InputStreamReader(self.getStream()))
     try:
         line = reader.readLine()
         while line:
             self.output += line
             line = reader.readLine()
     finally:
         reader.close()
開發者ID:Alex-CS,項目名稱:sonify,代碼行數:11,代碼來源:test_bat_jy.py

示例5: cluster

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
def cluster(algorithm, filename, options = ''):
    reader = BufferedReader(FileReader(filename))
    data = Instances(reader)
    reader.close()
    cl = algorithm()
    cl.setOptions(options.split())
    cl.buildClusterer(data)
    returnData = []
    for instance in data.enumerateInstances(): returnData.append(cl.clusterInstance(instance))
    print returnData
開發者ID:Nishchita,項目名稱:library,代碼行數:12,代碼來源:clusterers.py

示例6: readInputStreamToString

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
def readInputStreamToString(inStream):
    if(inStream == None):
        return "";
    rd= BufferedReader(InputStreamReader(inStream))
    response = ""
    line = rd.readLine()
    while line != None:
        response +=line+"\r"
        line = rd.readLine()
    rd.close()
    return response
開發者ID:revolutionarysystems,項目名稱:o-test,代碼行數:13,代碼來源:HttpCall.py

示例7: process

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
 def process(self, input) :
     try :
         reader = InputStreamReader(input)
         bufferedReader = BufferedReader(reader)
         self.__line = bufferedReader.readLine()
     except :
         print "Exception in Reader:"
         print '-' * 60
         traceback.print_exc(file=sys.stdout)
         print '-' * 60
         raise
     finally :
         if bufferedReader is not None :
             bufferedReader.close()
         if reader is not None :
             reader.close()
開發者ID:573196010,項目名稱:nifi,代碼行數:18,代碼來源:read_first_line.py

示例8: delete

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
def delete(targetURL, params):
    url = URL(targetURL)
    connection = url.openConnection()
    connection.setRequestMethod("DELETE")    
    connection.setRequestProperty("Content-Language", "en-GB")
    connection.setUseCaches(0)
    connection.setDoOutput(2)
    inStream= connection.getInputStream()
    rd= BufferedReader(InputStreamReader(inStream))
    response = ""
    line = rd.readLine()
    while line != None:
        response +=line+"\r"
        line = rd.readLine()
    rd.close()
    return response
開發者ID:revolutionarysystems,項目名稱:common-test,代碼行數:18,代碼來源:HttpCall.py

示例9: executeExternalApplication

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
def executeExternalApplication(command):
    try:
        pb = ProcessBuilder(command)
        pb.redirectErrorStream(true)
        process = pb.start()
        inputStream = process.getInputStream()
        bufferedReader = BufferedReader(InputStreamReader(inputStream))
        s = bufferedReader.readLine()
        while s != None:
            print (s)
            s = bufferedReader.readLine()
        if bufferedReader != None:
            bufferedReader.close()
    except Exception, e:
        print (e)
        if bufferedReader != None:
            bufferedReader.close()
開發者ID:ranjeethr,項目名稱:virtual7-adf-usecases,代碼行數:19,代碼來源:wltasks.py

示例10: post

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
def post(targetURL, params, contentType="text/xml", username=None):

    #paramStr = params["data"]
    paramStr = ""
    for aKey in params.keys():
        paramStr+=aKey+"="+URLEncoder.encode(params[aKey], "UTF-8")+"&"
    paramStr=paramStr[:-1]
    url = URL(targetURL)
    print targetURL
    print paramStr
    print contentType
    url = URL(targetURL+"?"+paramStr)
    print url

    connection = url.openConnection()
    if username!=None:    
        userpass = username
        basicAuth = "Basic " + base64.b64encode(userpass);
        connection.setRequestProperty ("Authorization", basicAuth);
    connection.setRequestMethod("POST")
    if contentType != None:
        connection.setRequestProperty("Content-Type", contentType)
    connection.setRequestProperty("Content-Length", str(len(paramStr)))
    connection.setRequestProperty("Content-Language", "en-GB")
    connection.setUseCaches(0)
    connection.setDoInput(1)
    connection.setDoOutput(2)
    
    #wr= DataOutputStream(connection.getOutputStream())
    #wr.writeBytes(paramStr)
    #wr.flush()
    #wr.close()
    
    inStream= connection.getInputStream()
    rd= BufferedReader(InputStreamReader(inStream))
    response = ""
    line = rd.readLine()
    while line != None:
        response +=line+"\r"
        line = rd.readLine()
    rd.close()
    return response
開發者ID:revolutionarysystems,項目名稱:common-test,代碼行數:44,代碼來源:HttpCall.py

示例11: read_from_jar

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
def read_from_jar(relative_path):
    '''
    reads a file from within a jar. returns the file content
    '''
    from java.lang import ClassLoader
    from java.io import InputStreamReader, BufferedReader

    loader = ClassLoader.getSystemClassLoader()
    stream = loader.getResourceAsStream(relative_path)
    reader = BufferedReader(InputStreamReader(stream))
    
    line = reader.readLine()
    buf = ''
    while line is not None:
        buf += line
        line = reader.readLine()
        
    reader.close()
    stream.close()
    return buf
開發者ID:Schnitzl42,項目名稱:JLibcloud,代碼行數:22,代碼來源:utils.py

示例12: __init__

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
 def __init__(self):
     sessionDuration = grinder.properties.getInt("player.sessionDurationInSeconds", 0)
     self.password = grinder.properties.getProperty("player.password")
     players_url = grinder.properties.getProperty("player.source-url")
     passwordHash = URLEncoder.encode(grinder.properties.getProperty("player.passwordHash"), "UTF-8")
     workers = grinder.properties.getInt("grinder.processes", 0)
     threads = grinder.properties.getInt("grinder.threads", 0)
     workerIndex = grinder.processNumber - grinder.firstProcessNumber
     threadsPerAgent = workers * threads
     agentIndex = grinder.agentNumber
     start = agentIndex * threadsPerAgent + workerIndex * threads
     if isLogEnabled:
         log("Worker will handle %s players starting from %d" % (threads, start))
     playerRange = (start, threads)
     self.workerPlayers = []
     params = "passwordHash=%s&minimumBalance=%s&startRow=%s&limit=%s" % (
         passwordHash,
         str(sessionDuration / 5),
         str(playerRange[0]),
         str(threads),
     )
     urlStr = players_url + "?" + params
     try:
         data = StringBuffer()
         url = URL(urlStr)
         conn = url.openConnection()
         rd = BufferedReader(InputStreamReader(conn.getInputStream()))
         line = rd.readLine()
         while line is not None:
             data.append(line)
             line = rd.readLine()
         rd.close()
         if isLogEnabled:
             log(data.toString())
         message = JSONValue.parse(str(String(data.toString(), "UTF-8")))
         for entry in message:
             self.workerPlayers.append((entry.get(0), entry.get(1)))
     except Exception:
         raise Exception("Couldn't fetch players from %s: %s" % (urlStr, traceback.format_exc()))
     if isLogEnabled:
         log(str(self.workerPlayers))
開發者ID:ShahakBH,項目名稱:jazzino-master,代碼行數:43,代碼來源:yazino.py

示例13: _parse_and_rewrite_svg_file

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
def _parse_and_rewrite_svg_file(svg_input_path, svg_output_path):
    write_str = ""
    file_reader = FileReader(svg_input_path)
    buffered_reader = BufferedReader(file_reader)
    read_line = ""

    while True:
        read_line = buffered_reader.readLine()

        if read_line is None:
            break

        if "viewBox" in read_line:
            view_box_content = _get_viewbox_content(read_line)
            view_box_values = _get_viewbox_values(view_box_content)
            if view_box_values[0] != 0:
                view_box_values[2] += view_box_values[0]
                view_box_values[0] = 0

            if view_box_values[1] != 0:
                view_box_values[3] += view_box_values[1]
                view_box_values[1] = 0

            new_view_box = str(view_box_values[0]) + " " + str(view_box_values[1]) + " " + \
                           str(view_box_values[2]) + " " + str(view_box_values[3])
            read_line = re.sub(r"viewBox=\"[\-|0-9| ]+\"", "viewBox=\""
                               + new_view_box + "\"", read_line, 1)
            read_line = re.sub(r"width=\"[0-9]+\"", "width=\""+ str(view_box_values[2]) + "\"",
                               read_line, 1)
            read_line = re.sub(r"height=\"[0-9]+\"", "height=\""+ str(view_box_values[3]) + "\"",
                               read_line, 1)

        write_str += read_line + "\n"

    buffered_reader.close()
    file_reader.close()
    file_writer = PrintWriter(svg_output_path)
    file_writer.print(write_str)
    file_writer.close()
開發者ID:ReinhardHuetter,項目名稱:ScratchToCatrobat,代碼行數:41,代碼來源:svgtopng.py

示例14: doInBackground

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]
    def doInBackground(self):
        """Download errors data
        """
        #Download and parse errors
        self.tool = self.app.downloadingTool
        self.checks = self.app.downloadingChecks

        #Initialize progress property.
        progress = 0
        self.super__setProgress(progress)

        progress = 1
        self.super__setProgress(progress)

        #debug
        offline = False
        writeToFile = False

        if offline or self.tool.isLocal:
            if offline and not self.tool.isLocal:
                fileName = File.separator.join([self.app.SCRIPTDIR,
                                                "%s_errors.gfs" % self.tool.name])
            else:
                fileName = self.tool.fileName
            print "\n  read errors from file: %s" % fileName

            inFile = open(fileName, "r")
            self.app.errorsData = inFile.read()
            inFile.close()
        else:
            try:
                print "\n  url: ", self.app.downloadingUrl
                url = URL(self.app.downloadingUrl)
                uc = url.openConnection()
                ins = uc.getInputStream()
                inb = BufferedReader(InputStreamReader(ins, Utils.UTF_8))
                builder = StringBuilder()
                line = inb.readLine()
                while line is not None and not self.isCancelled():
                    builder.append(line)
                    builder.append(System.getProperty("line.separator"))
                    line = inb.readLine()
                if self.isCancelled():
                    if inb is not None:
                        inb.close()
                    if uc is not None:
                        uc.disconnect()
                    return
                inb.close()
                uc.disconnect()
                self.app.errorsData = builder.toString()
            except (UnknownHostException, FileNotFoundException, IOException, SocketException):
                msg = self.app.strings.getString("connection_not_working")
                self.app.downloadAndReadDlg.progressBar.setIndeterminate(False)
                self.app.downloadAndReadDlg.dispose()
                JOptionPane.showMessageDialog(Main.parent, msg)
                self.cancel(True)
                return

        if writeToFile:
            f = open(File.separator.join([self.app.SCRIPTDIR,
                                          "%s_errors.gfs" % self.tool.name]), "w")
            f.write(self.app.errorsData.encode("utf-8"))
            f.close()
            print "errors file saved", File.separator.join([self.app.SCRIPTDIR,
                                                            "%s_errors.gfs" % self.tool.name])
開發者ID:alex85k,項目名稱:qat_script,代碼行數:68,代碼來源:download_and_parse.py

示例15: __init__

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import close [as 別名]

#.........這裏部分代碼省略.........

        self.__isHeaderLineProcessed = 0

    def setQuoteSymbol(self, symbol):
        '''
        Set the quote symbol
        @param symbol: the quote symbol
        '''
        self.__quotesymb = symbol or self.DEFAULT_QUOTE_SYMB

    def getQuoteSymbol(self):
        return self.__quotesymb

    def setRowToStartIndex(self, index):
        '''
        Set the index, that indicates row number from
        witch parsing will be started.
        Fist row has index 0 and so on.
        @param index: index of row to start
        '''
        self.__rowToStartIndex = index or Parser.DEFAULT_ROW_TO_START_INDEX

    def getRowToStartIndex(self):
        return self.__rowToStartIndex

    def parseNext(self):
        '''
        Parse next line
        @return: tokens of parsed line
        '''
        line = self.__readNextLine()
        tokens = None
        if line is not None:
            tokens = line.strip() and self.__parseLine(line) or []
        return tokens

    def __readNextLine(self):
        if not self.__isHeaderLineProcessed and self.__rowToStartIndex:
            for i in range(0, self.__rowToStartIndex):
                self.__reader.readLine()
            self.__isHeaderLineProcessed = 1
        return self.__reader.readLine()

    def __isEscaped(self, charIndex, line):
        'int, str -> bool'
        escapeSymbIdx = charIndex - len(self.__escapeSeq)
        return (escapeSymbIdx > -1
                and line[escapeSymbIdx: charIndex] == self.__escapeSeq)

    def __parseLine(self, line):
        tokensOnThisLine = []

        sb = ''
        inQuotes = 0
        while 1:
            if inQuotes:
                sb += "\n"
                line = self.__readNextLine()
                if line is None:
                    break

            i = 0
            while i < len(line):
                c = line[i]
                if c == self.__quotesymb:
                    # escape quote
                    if self.__isEscaped(i, line):
                        sb = sb[:-len(self.__escapeSeq)]
                        sb += c
                    # treat two quote symbols as one
                    elif (len(line) > (i+1)
                        and line[i+1] == self.__quotesymb):
                            sb += c
                            i+=1
                    else:
                        inQuotes = not inQuotes
                elif c == self.__delimiter and not inQuotes:
                    # escape delimiter
                    if self.__isEscaped(i, line):
                        sb = sb[:-len(self.__escapeSeq)]
                        sb += c
                    else:
                        #save token and process next
                        tokensOnThisLine.append(sb)
                        sb = ''
                else:
                    sb += c
                i+=1
            #do-while condition
            if not inQuotes:
                break

        tokensOnThisLine.append(sb)
        return tokensOnThisLine

    def close(self):
        '''
        Close reader
        '''
        self.__reader.close()
開發者ID:ddonnelly19,項目名稱:dd-git,代碼行數:104,代碼來源:csvParser.py


注:本文中的java.io.BufferedReader.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。