def removeFollower(self, username, follower): """removeFollower username follower""" following_fn = "following:" + follower with Transaction() as fs: yield fs.begin() content = (yield fs.read(following_fn)) if content is None: yield Op.FollowerChangeResult.FAILURE content = Utility.byteArrayToString(content) out = StringBuffer() absent = True for line in lines(content): followed_user, timestamp = line.split("\t") if followed_user == username: absent = False else: out.append(line + "\n") fs.overwrite(following_fn, Utility.stringToByteArray(out.toString())) if not (yield fs.commit()): yield Op.FollowerChangeResult.FAILURE elif absent: yield Op.FollowerChangeResult.DOES_NOT_EXIST else: yield Op.FollowerChangeResult.SUCCESS
def _get_deflate_data(deflater): buf = jarray.zeros(1024, 'b') sb = StringBuffer() while not deflater.finished(): l = deflater.deflate(buf) if l == 0: break sb.append(String(buf, 0, 0, l)) return sb.toString()
def _get_deflate_data(deflater): buf = jarray.zeros(1024, 'b') sb = StringBuffer() while not deflater.finished(): l = deflater.deflate(buf) if l == 0: break sb.append(String(buf, 0, 0, l)) return sb.toString()
def toString(self): s = StringBuffer() s.append("name=" + self.name + "\t") s.append("value=" + str(self.value) + "\t") s.append("type=" + self.type + "\t") s.append("units=" + self.units + "\t") s.append("spoof=" + self.spoof + "\t") for name, value in self.correlatedData.iteritems(): s.append(name + "=" + value + "\t") return s.toString()
def _get_inflate_data(inflater, max_length=0): buf = jarray.zeros(1024, 'b') sb = StringBuffer() total = 0 while not inflater.finished(): if max_length: l = inflater.inflate(buf, 0, min(1024, max_length - total)) else: l = inflater.inflate(buf) if l == 0: break total += l sb.append(String(buf, 0, 0, l)) if max_length and total == max_length: break return sb.toString()
def _get_inflate_data(inflater, max_length=0): buf = jarray.zeros(1024, 'b') sb = StringBuffer() total = 0 while not inflater.finished(): if max_length: l = inflater.inflate(buf, 0, min(1024, max_length - total)) else: l = inflater.inflate(buf) if l == 0: break total += l sb.append(String(buf, 0, 0, l)) if max_length and total == max_length: break return sb.toString()
class HistoryTaskRunnable (Runnable): def __init__(self, textArea, br): self.textArea = textArea self.br = br self.sbf = StringBuffer() #@Override def run(self): while True: line = self.br.readLine() if line != None: self.sbf.append(line + "\n") # self.textArea.appendText(line + "\n") - Very slow else: break #Add Text to TextArea self.textArea.setText(self.sbf.toString()) self.textArea.appendText("") #Used to trigger event handler #Close Buffered Reader br.close()
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))
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))
def _get_response_msg(self, url_conn): """Функция, возвращающая тело ответа""" get_input_stream = url_conn.responseCode < HttpURLConnection.HTTP_BAD_REQUEST if get_input_stream: in_stream = url_conn.getInputStream() else: in_stream = url_conn.getErrorStream() response = "" if in_stream: in_stream = BufferedReader(InputStreamReader(in_stream, 'utf-8')) response = StringBuffer() while True: inputLine = in_stream.readLine() if not inputLine: break response.append(inputLine) in_stream.close() return unicode(response)
class JESLogBuffer: ################################################################################ # Function name: __init__ # Return: # An instance of the JESLogBuffer class. # Description: # Creates a new instance of the JESLogBuffer. ################################################################################ def __init__(self, program): self.saveBoolean = (1 == 1); self.CurrentBuffer=StringBuffer(); self.CurrentBuffer.append("<file_created time=\""); self.CurrentBuffer.append((Date(System.currentTimeMillis())).toString()); self.CurrentBuffer.append("\">\n"); ################################################################################ # Function name: resetBuffer # Parameters: # None. # Description: # This function clears the log buffer. ################################################################################ def resetBuffer(self): self.CurrentBuffer=StringBuffer(); self.CurrentBuffer.append("<file_created time=\""); self.CurrentBuffer.append((Date(System.currentTimeMillis())).toString()); self.CurrentBuffer.append("\">\n"); ################################################################################ # Function name: addCommand # Parameters: # newString: the command that is to be added into the log # Description: # This function adds a command into the log file ################################################################################ def addCommand(self, newString): self.CurrentBuffer.append("<command_run time=\""); self.CurrentBuffer.append((Date(System.currentTimeMillis())).toString()); self.CurrentBuffer.append("\">"); self.CurrentBuffer.append(newString); self.CurrentBuffer.setCharAt(self.CurrentBuffer.length()-1, '>'); self.CurrentBuffer.append("</command_run>\n"); ################################################################################ # Function name: addMenuOption # Parameters: # newString: the name of the menu option to be added to the log # Description: # This function adds a menu option into the log ################################################################################ def addMenuOption(self, newString): self.CurrentBuffer.append("<menu_button time=\""); self.CurrentBuffer.append((Date(System.currentTimeMillis())).toString()); self.CurrentBuffer.append("\">"); self.CurrentBuffer.append(newString); self.CurrentBuffer.append("</menu_button>\n"); ################################################################################ # Function name: openLogFile # Parameters: # fileName: the file name to open # Description: # This function clears the log buffer and replaces it with the logfile that # is in the filename specified. ################################################################################ def openLogFile(self, fileName): self.CurrentBuffer= StringBuffer(); try: file=open(fileName+"log", "rt"); self.CurrentBuffer.append(file.read()); if self.CurrentBuffer.length()>16: self.CurrentBuffer=StringBuffer(self.CurrentBuffer.substring(0, self.CurrentBuffer.length()-16)); self.CurrentBuffer.append("<file_opened time=\""); self.CurrentBuffer.append((Date(System.currentTimeMillis())).toString()); self.CurrentBuffer.append("\">"); self.CurrentBuffer.append(fileName); self.CurrentBuffer.append("</file_opened>"); self.CurrentBuffer.append("\n"); except: self.resetBuffer(); self.CurrentBuffer.append("<Could not find "+fileName+ "log,"); self.CurrentBuffer.append(" creating a new logfile>\n"); ################################################################################ # Function name: saveLogFile # Parameters: # fileName: the filename to save to # Description: # This function dumps the log buffer into the specified file ################################################################################ def saveLogFile(self, fileName): if self.saveBoolean==(1==0): return; logfile=open(fileName+"log", "wt"); self.CurrentBuffer.append("<file_saved time=\""); self.CurrentBuffer.append((Date(System.currentTimeMillis())).toString()); self.CurrentBuffer.append("\">"); self.CurrentBuffer.append(fileName); self.CurrentBuffer.append("</file_saved>"); self.CurrentBuffer.append("\n"); self.CurrentBuffer.append("</file_created>\n"); logfile.write(self.CurrentBuffer.toString()); logfile.close(); ################################################################################ # Function name: dumpLogToTerm # Parameters: # None. # Description: # This funcion dumps the log buffer to the terminal. Intended for debugging # use primarily. ################################################################################ def dumpLogToTerm(self): System.out.println(self.CurrentBuffer.toString());
import sys from java.lang import StringBuffer, System sb = StringBuffer(100) # Preallocate StringBuffer size for performance. sb.append('The platform is: ') sb.append(sys.platform) # Python property sb.append(' time for an omelette.') sb.append('\n') # Newline sb.append('Home directory: ') sb.append( System.getProperty('user.home') ) sb.append('\n') # Newline sb.append('Some numbers: ') sb.append(44.1) sb.append(', ') sb.append(42) sb.append(' ') # Try appending a tuple. tup=( 'Red', 'Green', 'Blue', 255, 204, 127 ) sb.append(tup) print(sb.toString()) # Treat java.util.Properties as Python dictionary. props = System.getProperties()
class JESLogBuffer: ################################################################################ # Function name: __init__ # Return: # An instance of the JESLogBuffer class. # Description: # Creates a new instance of the JESLogBuffer. ################################################################################ def __init__(self, program): self.saveBoolean = (1 == 1) self.CurrentBuffer = StringBuffer() self.CurrentBuffer.append("<file_created time=\"") self.CurrentBuffer.append( (Date(System.currentTimeMillis())).toString()) self.CurrentBuffer.append("\">\n") ################################################################################ # Function name: resetBuffer # Parameters: # None. # Description: # This function clears the log buffer. ################################################################################ def resetBuffer(self): self.CurrentBuffer = StringBuffer() self.CurrentBuffer.append("<file_created time=\"") self.CurrentBuffer.append( (Date(System.currentTimeMillis())).toString()) self.CurrentBuffer.append("\">\n") ################################################################################ # Function name: addCommand # Parameters: # newString: the command that is to be added into the log # Description: # This function adds a command into the log file ################################################################################ def addCommand(self, newString): self.CurrentBuffer.append("<command_run time=\"") self.CurrentBuffer.append( (Date(System.currentTimeMillis())).toString()) self.CurrentBuffer.append("\">") self.CurrentBuffer.append(newString) self.CurrentBuffer.setCharAt(self.CurrentBuffer.length() - 1, '>') self.CurrentBuffer.append("</command_run>\n") ################################################################################ # Function name: addMenuOption # Parameters: # newString: the name of the menu option to be added to the log # Description: # This function adds a menu option into the log ################################################################################ def addMenuOption(self, newString): self.CurrentBuffer.append("<menu_button time=\"") self.CurrentBuffer.append( (Date(System.currentTimeMillis())).toString()) self.CurrentBuffer.append("\">") self.CurrentBuffer.append(newString) self.CurrentBuffer.append("</menu_button>\n") ################################################################################ # Function name: openLogFile # Parameters: # fileName: the file name to open # Description: # This function clears the log buffer and replaces it with the logfile that # is in the filename specified. ################################################################################ def openLogFile(self, fileName): self.CurrentBuffer = StringBuffer() try: file = open(fileName + "log", "rt") self.CurrentBuffer.append(file.read()) if self.CurrentBuffer.length() > 16: self.CurrentBuffer = StringBuffer( self.CurrentBuffer.substring( 0, self.CurrentBuffer.length() - 16)) self.CurrentBuffer.append("<file_opened time=\"") self.CurrentBuffer.append( (Date(System.currentTimeMillis())).toString()) self.CurrentBuffer.append("\">") self.CurrentBuffer.append(fileName) self.CurrentBuffer.append("</file_opened>") self.CurrentBuffer.append("\n") except: self.resetBuffer() self.CurrentBuffer.append("<Could not find " + fileName + "log,") self.CurrentBuffer.append(" creating a new logfile>\n") ################################################################################ # Function name: saveLogFile # Parameters: # fileName: the filename to save to # Description: # This function dumps the log buffer into the specified file ################################################################################ def saveLogFile(self, fileName): if self.saveBoolean == (1 == 0): return logfile = open(fileName + "log", "wt") self.CurrentBuffer.append("<file_saved time=\"") self.CurrentBuffer.append( (Date(System.currentTimeMillis())).toString()) self.CurrentBuffer.append("\">") self.CurrentBuffer.append(fileName) self.CurrentBuffer.append("</file_saved>") self.CurrentBuffer.append("\n") self.CurrentBuffer.append("</file_created>\n") logfile.write(self.CurrentBuffer.toString()) logfile.close() ################################################################################ # Function name: dumpLogToTerm # Parameters: # None. # Description: # This funcion dumps the log buffer to the terminal. Intended for debugging # use primarily. ################################################################################ def dumpLogToTerm(self): System.out.println(self.CurrentBuffer.toString())
def space(number): from java.lang import StringBuffer buf = StringBuffer(number) for i in range(number): buf.append(' ') return buf.toString()
#!/usr/bin/env python # vim: set fileencoding=utf-8 from java.awt import Color from java.lang import StringBuffer from java.awt import Button print("\nString buffer") s = StringBuffer() print(s) print(s.length()) s.append("hello world!") print(s) print(s.length()) s.setLength(10) print(s) print(s.length()) # nebude fungovat s.length = 5 print(s) print(s.length())
import sys from java.lang import StringBuffer, System sb = StringBuffer(100) # Preallocate StringBuffer size for performance. sb.append('The platform is: ') sb.append(sys.platform) # Python property sb.append(' time for an omelette.') sb.append('\n') # Newline sb.append('Home directory: ') sb.append( System.getProperty('user.home') ) sb.append('\n') # Newline sb.append('Some numbers: ') sb.append(44.1) sb.append(', ') sb.append(42) sb.append(' ') # Try appending a tuple. tup=( 'Red', 'Green', 'Blue', 255, 204, 127 ) sb.append(tup) print(sb.toString()) # Treat java.util.Properties as Python dictionary. props = System.getProperties()