id
stringlengths
36
36
text
stringlengths
1
1.25M
647a3e4e-8ae9-4563-9f60-6e12ddd6aa8b
public void addCustomerAround(String name) { System.out.println("Add customer Around is running ......With name as "+name); }
5133310c-d851-43ee-acf4-d02e6a1af0fc
public void addCustomerThrowException() throws Exception { System.out.println("Add customer method throws Exception ......"); throw new Exception("Exception thrown from here"); }
923a890c-b952-4c72-af0a-cb136b2a7ba9
@After("execution (* com.springaop.service.CustomerService.addCustomer(..))") public void logAfter(JoinPoint jpt){ System.out.println("************logAfter() is running!************"); System.out.println("hijacked : " + jpt.getSignature().getName()); System.out.println("**************************************...
f4316cdc-79a4-458a-90ea-a62bce9a7db8
@Before("execution (* com.springaop.service.CustomerService.addCustomer(..))") public void logBefore(JoinPoint jpt){ System.out.println("************logBefore() is running!************"); System.out.println("hijacked : " + jpt.getSignature().getName()); System.out.println("*****************Now logBefore()...
c4ff9a4f-6822-4dc7-b136-c7be9a93a86b
@AfterReturning( pointcut="execution (* com.springaop.service.CustomerService.addCustomerReturn(..))",returning="result") public void logAfterReturn(JoinPoint jpt,Object result){ System.out.println("************logAfterReturn() is running!************"); System.out.println("hijacked : " + jpt.getSignature()...
551c5fa6-30dd-404d-a08a-eb348e743d58
@AfterThrowing( pointcut="execution (* com.springaop.service.CustomerService.addCustomerReturn(..))",throwing="error") public void logAfterThrowException(JoinPoint jpt,Throwable error){ System.out.println("************logAfterThrowException() is running!************"); System.out.println("hijacked : " + jpt...
fea9a708-99fe-40cc-8d28-a90e986e5fa4
@Around("execution (* com.springaop.service.CustomerService.addCustomerAround(..))") public void logAround(ProceedingJoinPoint proceedjpt) throws Throwable{ System.out.println("************logAround() is running!************"); System.out.println("hijacked : " + proceedjpt.getSignature().getName()); System...
c869ef28-5c1d-4627-bfb0-51741f1f7dc7
public static void main( String[] args ) { ApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] { "springaop-Aspect.xml" }); CustomerService customer = (CustomerService) appContext.getBean("customerservcImpl"); //Call this method to call @after and @before for ...
946c6921-71af-4e7d-9be0-4acd53647c22
public AppTest( String testName ) { super( testName ); }
ff85a94f-7e90-47da-a559-aff52d370e09
public static Test suite() { return new TestSuite( AppTest.class ); }
b34ac16f-192c-4528-80ef-6505c8c523de
public void testApp() { assertTrue( true ); }
b9f20856-84b2-491d-a681-43b75b654718
public SqliteConverter(LogWriter inLogWriter) { logWriter = inLogWriter; }
b614e63b-27e8-488f-b8a0-16131f84bcbf
public Boolean init(File dbFile) { logWriter.logAppend("Sqlite database load commencing"); try { Class.forName("org.sqlite.JDBC"); dbConn = DriverManager.getConnection("jdbc:sqlite:" + dbFile.getPath()); tableHandlers = processSchema(); } catch (ClassNotFoundException e) { logWriter .logAp...
ce890e81-68b6-4963-bdb0-e37ca2aa2de4
public Boolean deInit() { try { if (dbConn != null) dbConn.close(); } catch (SQLException e) { return (false); } dbConn = null; tableHandlers = null; logWriter.logAppend("Sqlite database closed"); return (true); }
0f8cd49f-5409-4670-9dfa-adac10dd69b4
private Vector processSchema() throws SQLException { Vector tableHandlers = new Vector(); // Get the table names Statement dbStat = dbConn.createStatement(); ResultSet rs = dbStat .executeQuery("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"); try { while (rs.next()) { String ta...
1e50fee8-82db-41f3-8bb1-440f04d7a5e6
public Boolean export(File outFile, int format) { return (export(outFile, format, new SqliteConverterExportConfig())); }
922b1633-894a-4541-9011-d1ace9b198d0
public final Boolean export$$Base(File outFile, int format, SqliteConverterExportConfig config) { return true; }
086cdbcc-4f63-4bd1-a31e-d61472160ba1
private Boolean exportToJson(File jsonFile, SqliteConverterExportConfig config) { logWriter.logAppend("JSON export commencing"); // Handle the export... try { FileWriter fStream = new FileWriter(jsonFile); BufferedWriter fOut = new BufferedWriter(fStream); JSONObject jsonOut = new JSONObject(); e...
63334914-d7f9-4813-b258-7adf3054edea
private void exportTablesToJson(JSONObject jsonOut, SqliteConverterExportConfig config) { for (int i = 0; i < tableHandlers.size(); i++) // for( Object tableHandler : tableHandlers ) { Object tableHandler = tableHandlers.elementAt(i); try { logWriter.logAppend(String.format( "Exporting contents...
75e67aef-f246-4068-996f-338a22c57f05
public Boolean export(File outFile, int format, SqliteConverterExportConfig config) { export$$Base(outFile,format,config); if (format == JSON) return (exportToJson(outFile, config)); else return false; }
9439d96f-94c8-489a-badd-e9cefe4785c1
public static String getClassPath( Class targetClass ) { String classFilePath = targetClass.getProtectionDomain().getCodeSource().getLocation().getPath(); Matcher pathMatcher = classPathNamePattern.matcher( classFilePath ); if( pathMatcher.groupCount() > 0 ) return( pathMatcher.group(1) ); return( cla...
0065a297-ee26-4596-9941-7e1346a00cc8
public static String getWorkingPath() { return( System.getProperty("user.dir") ); }
469869d2-c6fa-4857-af2a-c6d03e916001
public PanelFileSelection( String label, FileNameExtensionFilter inFileNameFilter, boolean inIsInputFile, int textFieldColumns ) { super(); eventListeners = new EventListenerList(); changeEvent = new ChangeEvent( this ); logWriter = null; fileNameFilter = inFileNameFilter; isInputFile = inIsInputF...
c70cae23-f177-4752-ae39-69cbf0858866
public PanelFileSelection( String label, FileNameExtensionFilter inFileNameFilter, boolean isInputFile ) { this( label, inFileNameFilter, isInputFile, 48 ); }
a111892e-3df4-4b19-99ff-eccb3f9def62
public void addChangeListener( ChangeListener listener ) { eventListeners.add( ChangeListener.class, listener ); }
9b0ee14c-cff3-4e86-bde4-39bf63a1e5be
public void removeChangeListener( ChangeListener listener ) { eventListeners.remove( ChangeListener.class, listener ); }
3f89dd9a-c9fd-4cbb-9bad-1431c8ee1483
public void setLogWriter( LogWriter inLogWriter ) { logWriter = inLogWriter; }
3182da90-c233-451a-947c-07d5259519df
public void setLastSelectedFile( String filePath ) { textField.setText( filePath ); }
c5c1b6a9-ca70-4e79-812f-302cc61f19f8
public void setLastSelectedFile( File inFile ) { textField.setText( inFile.getAbsolutePath() ); }
265b4cdf-f61a-4717-a5aa-d6036f981e4c
public File getLastSelectedFile() { String filePath = textField.getText(); if( filePath.length() <= 0 ) return( null ); return( new File(filePath) ); }
d554fae9-5357-4439-82da-02be789aea9f
public String getLastSelectedFilePath() { return( textField.getText() ); }
1dcbdf1d-f183-4f82-bc17-6b4851a0f95c
@Override public void actionPerformed(ActionEvent evt) { if( evt.getSource() == button ) { handleShowFileChooser(); } }
b0fe96c2-9eb1-4b59-ab22-3502238dbb61
private void handleShowFileChooser() { JFileChooser fileChooser = new JFileChooser(); if( fileNameFilter != null ) fileChooser.setFileFilter( fileNameFilter ); File lastSelectedFile = getLastSelectedFile(); if( lastSelectedFile != null ) { fileChooser.setSelectedFile( lastSelectedFile ); } //...
33e3753e-cb1a-414a-ba65-a650b9b1af66
private void fireChangeEvent() { ChangeListener[] listeners = eventListeners.getListeners( ChangeListener.class ); for( int i=0; i < listeners.length; i++ ) //for( ChangeListener currListener : listeners ) { listeners[i].stateChanged( changeEvent ); } }
50f0c2bb-a645-4af4-b509-92e39cbc28c0
private void addLogText( String logText ) { if( logWriter == null ) return; logWriter.logAppend( logText ); }
1314e7ae-1d97-45bd-8bf8-eb7cbf95bdc8
@Override public void setUpLogger(Object obj) { log = (JTextArea)obj; }
65f6b767-eadc-486e-ba5d-d08397dd4116
public void logAppend(String logText) { log.append(logText + "\n"); log.setCaretPosition(log.getDocument().getLength()); }
34369035-acc2-461b-a592-85e4310f277b
public static String readFileAsString( String filePath, int bytesMax ) { return( readFileAsString(filePath, bytesMax, null) ); }
68fbfe78-18e1-4f06-a1ee-9bccec07c2f5
public static String readFileAsString( String filePath, int lengthMax, String charEncoding ) { try { InputStreamReader inputStream; if( charEncoding == null ) inputStream = new InputStreamReader( new FileInputStream(filePath) ); else inputStream = new InputStreamReader( new FileInputStream(filePat...
71e0b715-1a3f-480b-b8c4-fc974f0bbb8d
void setUpLogger(Object obj);
07d08aa0-dcc9-4d6a-b72a-ee405977c977
void logAppend(String logText);
eb432ab9-82a3-429d-bff2-ecfcc3c3e13f
public SqliteConverterExportConfig( JSONObject jsonConfig ) { init( null, null ); add( jsonConfig ); }
9092eba9-a48d-4125-82da-45cd0451df29
public SqliteConverterExportConfig( SqliteConverterExportConfig src ) { excludeList = new ArrayList( src.excludeList ); tablePrimaryKeys = new Hashtable( src.tablePrimaryKeys ); }
a6244581-56b9-4ad6-bb12-8ec96a788678
public SqliteConverterExportConfig( List inExcludeList, Map inTablePrimaryKeys ) { init( inExcludeList, inTablePrimaryKeys ); }
25e713b1-bb56-44b4-a580-3d556ce063d5
public SqliteConverterExportConfig( String[] inExcludeList, Map inTablePrimaryKeys ) { init( Arrays.asList( inExcludeList ), inTablePrimaryKeys ); }
4bf702a2-d6dc-40e3-b809-6d7780a95195
public SqliteConverterExportConfig( Map inTablePrimaryKeys ) { init( null, inTablePrimaryKeys ); }
a4268a5c-5dc7-48eb-99a2-424ab3ba9dc4
public SqliteConverterExportConfig( List inExcludeList ) { init( inExcludeList, null ); }
c1d5c620-dcf4-434a-a46a-26650680a9ff
public SqliteConverterExportConfig( String[] inExcludeList ) { init( Arrays.asList( inExcludeList ), null ); }
cb42f996-290e-4192-8fd0-e7032c9cb4d7
public SqliteConverterExportConfig() { init( null, null ); }
c474c8d5-d4d7-492d-b004-da9a69ccd232
public void add( SqliteConverterExportConfig source ) { tablePrimaryKeys.putAll( source.tablePrimaryKeys ); excludeList.addAll( source.excludeList ); }
d613747a-f442-4cda-9f47-a0db4f3d1286
public void add( JSONObject jsonConfig ) { // Import the key map information (if available)... JSONObject keyMap = jsonConfig.optJSONObject( "keys" ); if( keyMap != null ) { Iterator keys = keyMap.keys(); while( keys.hasNext() ) { String currKey = (String)keys.next(); try { tablePrima...
1341d979-9590-4f7c-b9d4-4867a01290f1
public List getExcludeList() { return( excludeList ); }
1032dfee-c790-452d-905b-9ab985d77fc5
public Map getTablePrimaryKeys() { return( tablePrimaryKeys ); }
5697422f-5a87-42a9-abfc-e9c22cad7263
private void init( List inExcludeList, Map inTablePrimaryKeys ) { excludeList = inExcludeList; if( excludeList == null ) excludeList = new ArrayList(); tablePrimaryKeys = inTablePrimaryKeys; if( tablePrimaryKeys == null ) tablePrimaryKeys = new Hashtable(); }
084de04f-1261-4cdc-bcab-e8f04dcde11b
SqliteExporterFrame() { super(); { { } { window = new JPanel( new BorderLayout() ); setupButtons(); exportButton = new JButton( "Sqlite Export" ); exportButton.addActionListener( this ); topPanel.add( exportButton ); window.add( topPanel, BorderLayout.PAGE_STA...
fe6223e3-90cd-4183-b833-ab463783c4e1
public static void main(String args[]) { doMain(args); }
0380e08e-2d38-49ba-a06b-bba936bfeada
public static void doMain(String args[]) { //Create and set up the window. JFrame frame = new JFrame("SQLite Exporter"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add content to the window. SqliteExporterFrame exporterFrame = new SqliteExporterFrame(); fr...
9ac7cc14-3997-40b3-8ca1-a062597b2db0
static void centerWindow( JFrame frame ) { // Get the size of the screen Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // Determine the new location of the window int w = frame.getSize().width; int h = frame.getSize().height; int x = (screenSize.width - w) / 2; int y = (screenSi...
beb778c2-bf83-48c3-90be-5951a46c245e
private final void setupButtons$$GUI() { topPanel.setLayout( new BoxLayout(topPanel, BoxLayout.PAGE_AXIS) ); dbFileInSelection = new PanelFileSelection( "Input DB...", fileFilterSqlite, true ); dbFileInSelection.addChangeListener( this ); dbFileInSelection.setLogWriter( logWriter ); topPanel.add( dbFileIn...
396026bb-7221-4ded-ad3c-33884fdab1be
private final void restorePrefs$$GUI() { prefs = Preferences.userNodeForPackage(this.getClass()); dbFileInSelection.setLastSelectedFile( prefs.get(PREF_FILEPATH_DB, "") ); configFileInSelection.setLastSelectedFile( prefs.get(PREF_FILEPATH_CONFIG, "") ); }
9f77f42e-61a0-427c-bd47-f913036b939f
public void actionPerformed(ActionEvent evt) { if( evt.getSource() == exportButton ) { handleExportGui(); endExport(); } }
220f317a-112e-4422-84d6-c5a5c94db1e1
public final void stateChanged$$GUI(ChangeEvent evt) { if( evt.getSource() == dbFileInSelection ) { addLogText( String.format("Selected SQLite file '%1$s' for import", dbFileInSelection.getLastSelectedFilePath()) ); prefs.put( PREF_FILEPATH_DB, dbFileInSelection.getLastSelectedFilePath() ); return; } ...
caf55288-8f9e-4617-a913-172a25a05f84
public final void handleExportGui$$GUI() { // Set up the common export configuration SqliteConverterExportConfig commonConfig = new SqliteConverterExportConfig(); JSONObject exportConfig = getExportConfig(); if( exportConfig != null ) { JSONObject jsonConfigCommon = exportConfig.optJSONObject( "common" );...
cc38f407-260c-4535-9e13-cd4d7fc06563
private JSONObject getExportConfig() { File configFileIn = configFileInSelection.getLastSelectedFile(); if( configFileIn == null ) return( null ); String configString = WappFile.readFileAsString(configFileIn.getAbsolutePath(), CONFIGFILE_SIZE_MAX ); if( configString == null ) return( null ); try ...
3f1c9f3f-25fe-4eda-ab71-e0441daa2e88
private void setupLogger() { log = new JTextArea(20,40); log.setMargin(new Insets(5,5,5,5)); log.setEditable(false); log.setLineWrap( true ); log.setWrapStyleWord( true ); JScrollPane logScrollPane = new JScrollPane(log); window.add(logScrollPane, BorderLayout.CE...
486883be-180a-4f94-b321-41392aaf14bf
private void setupButtons() { setupButtons$$GUI(); jsonFileOutSelection = new PanelFileSelection( "Output JSON...", fileFilterJson, false ); jsonFileOutSelection.addChangeListener( this ); jsonFileOutSelection.setLogWriter( logWriter ); topPanel.add( jsonFileOutSelection ); }
323eaae2-9fb4-4d0b-a6c5-c1dd5cda8e09
private void restorePrefs() { restorePrefs$$GUI(); jsonFileOutSelection.setLastSelectedFile( prefs.get(PREF_FILEPATH_JSON, "") ); }
0821d045-a1d9-407f-9e7f-e51bae34824d
public void stateChanged(ChangeEvent evt) { stateChanged$$GUI(evt); if( evt.getSource() == jsonFileOutSelection ) { addLogText( String.format("Selected JSON export target as '%1$s'", jsonFileOutSelection.getLastSelectedFilePath()) ); prefs.put( PREF_FILEPATH_JSON, jsonFileOutSelection.getLastSelectedFil...
e6b88f60-2e4a-43a4-aa6e-bfab37b52e7a
public void handleExportGui() { handleExportGui$$GUI(); // Set up the common export configuration SqliteConverterExportConfig commonConfig = new SqliteConverterExportConfig(); JSONObject exportConfig = getExportConfig(); if( exportConfig != null ) { JSONObject jsonConfigCommon = exportConfig.optJSONObj...
648d16e2-b65b-4680-933a-d1cefc5fc946
public SqliteExporter() { { } { setLogWriter((LogWriter)(new LogWriterWindow())); } }
1cf50335-fd9a-40dc-8662-24a5aa2a34f1
public void setLogWriter(LogWriter inLogWriter) { logWriter = inLogWriter; }
a9ccd128-e329-4704-b594-c8577e2d2852
protected boolean beginExport(File dbFile) { if (converter != null) { addLogText("Attempting to start another export while an existing one is in progress. Skipping..."); return (false); } converter = new SqliteConverter(logWriter); if (!converter.init(dbFile)) { addLogText("Sqlite DB file is invalid. ...
ca3ae925-f8ef-4eb5-af2b-8ad815b208da
protected boolean export(File exportFile, int format, SqliteConverterExportConfig exportConfig) { if (converter == null) { addLogText(String .format("Trying to export to file '%s' without starting up export. Aborting... ", exportFile.getAbsolutePath())); return (false); } if (!converter.expo...
3c61cfad-af92-4068-a151-9df9c46a02da
protected void endExport() { if (converter == null) return; converter.deInit(); converter = null; }
8eda9646-43bc-4910-aa3d-c6d6025c8021
protected void addLogText(String logText) { if (logWriter == null) return; logWriter.logAppend(logText); }
352fc9d5-1652-4cef-b199-1a18cd58662c
public SqliteTableHandler(String inTableName, Connection inDbConn, LogWriter inLogWriter) throws SQLException { logWriter = inLogWriter; dbConn = inDbConn; tableName = inTableName; fieldInfo = new Hashtable(); logWriter.logAppend(String.format( "Reading column names for table '%1$s'", tableName)); ...
c2f4d990-c5fd-4b27-88d7-826e90ed8993
public String getName() { return (tableName); }
8cbc921c-cef3-422a-bad1-588875ca4b79
private int fieldTypeStringToFieldType(String ident) { if (ident.equals("INTEGER") || ident.equals("NUMERIC")) return (INTEGER); if (ident.equals("FLOAT") || ident.equals("REAL")) return (FLOAT); return (STRING); }
a5bde2d8-dfe4-4407-9010-c5794b27246a
private void addLogText(String logText) { logWriter.logAppend(logText); }
7da358f2-7cef-4943-a71e-1af41ff36d49
public Boolean exportTableToJson(JSONObject jsonOut, SqliteConverterExportConfig config) throws SQLException { List excludeList = config.getExcludeList(); if (excludeList.contains(tableName)) return (true); if (excludeList.size() == 0) excludeList = null; String primaryKey = (String) config.getTablePr...
8973fcb3-456c-4169-abd2-55c254888310
private JSONArray getRecordsAsJsonArray(List excludeList) throws SQLException { Statement dbStat = dbConn.createStatement(); ResultSet rs = dbStat.executeQuery(String.format( "select * from '%1$s';", tableName)); JSONArray jsonRecords = new JSONArray(); try { while (rs.next()) { Boolean saveRecor...
95312977-fbbd-4111-8df4-37ca03bf2150
private JSONObject getRecordsAsJsonObject(List excludeList, String primaryKey) throws SQLException { Statement dbStat = dbConn.createStatement(); ResultSet rs = dbStat.executeQuery(String.format( "select * from '%1$s';", tableName)); JSONObject jsonRecords = new JSONObject(); int recordIndex = 0; try ...
e548a43e-dcad-4d76-831a-16b1dc2eb209
private void addFieldToJson(JSONObject jsonDest, ResultSet rs, Object fieldInfo) throws JSONException, SQLException { String fieldName = (String) ((Map.Entry) fieldInfo).getKey(); switch ((Integer) (((Map.Entry) fieldInfo).getValue())) { case INTEGER: jsonDest.put(fieldName, rs.getLong(fieldName)); break...
3cb80853-a994-4507-9fab-fe3852ed1b28
public String processInput(String theInput) { String theOutput = null; if (state == WAITING) { theOutput = "Knock! Knock!"; state = SENTKNOCKKNOCK; } else if (state == SENTKNOCKKNOCK) { if (theInput.equalsIgnoreCase("Who's there?")) { theOutpu...
01fc6d7b-57b6-419a-99ef-49ad1d019870
public static void main(String[] args) throws IOException { Socket echoSocket = null; PrintWriter out = null; BufferedReader in = null; try { echoSocket = new Socket("taranis", 7); out = new PrintWriter(echoSocket.getOutputStream(), true); in = new B...
a3549d03-1ffb-4d6b-9fe3-90ac2ba20a4c
public static void main(String[] args) throws IOException { Socket kkSocket = null; PrintWriter out = null; BufferedReader in = null; try { kkSocket = new Socket("Shunjis-MacBook-Air.local", 4444); out = new PrintWriter(kkSocket.getOutputStream(), true); ...
8206fbbe-4ff1-4edb-8aec-c45fa38b06ed
public static void main(String[] args) throws IOException { String computername=InetAddress.getLocalHost().getHostName(); System.out.println(computername); ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(4444); } catch (IOException e) { ...
af21c3d3-9bc6-4545-bd9f-8e3578af2a58
public ThreadQueue(int maxSize){ this.max = maxSize; }
b93988d8-3765-4870-8e57-920258e9ff11
public synchronized boolean Enqueue(ServerThread t){ //Add a new thread to the queue. if (count == max){ this.poll().KillYourSelf(); count = count-1; //System.out.println("the server is full, killed the oldest thread"); } this.add(t); count = count + 1; latestThread = t; return true; }
651d3b6f-8317-4932-a8e1-4bd19fdd288d
public synchronized boolean Dequeue(){ //Dequeue the thread. count = count -1; this.poll(); return true; }
6f793ec4-bd60-4f96-ac66-ff8762555420
public static void main(String[] args) { // TODO Auto-generated method stub }
5eb60822-7b73-4361-8eaa-2f74655561e8
public static void main(String[] args) throws IOException { String computername=InetAddress.getLocalHost().getHostName(); System.out.println(computername); boolean listening = true; int maxConnection = Integer.parseInt(args[0]); String rootDir = args[1]; String userDir = args[2]; //System.out.println(a...
f503faa3-50ee-4091-b218-72e3db8dc3f0
public HTTPProcessor(String request, String root, String user){ //Constructor method setDir(root); this.userDir = user; this.request = request; }
7718aa85-5907-455a-b978-1f6bbe0ddcbc
public byte[] process(){ //this is the method call to process the request once a new HTTPProcessor is initiated. try { hostName =InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e1) { System.err.println("Unknow Host"); } String[] requestArray = request.split(" "); if(requestAr...
89cdff31-cea3-490c-8e12-59c899e3ddbb
public byte[] requestHandler(String request){ //This is the request handler to all the request except the image and gif class. String[] requestArray = request.split(" "); String requestType; String relativePath = requestArray[2];; if( requestArray[1].equals("GET")){ requestType = "GET"; }else if (reque...
4e7f5e85-6eca-4559-8882-49f5a2cc8e04
public static String reformatPath(String relativePath){ //This method is to reformat the relative path so that it is server friendly to be used. if (relativePath.endsWith("/")) relativePath = relativePath+ "index.html"; if(isUserDir(relativePath)){ int start = relativePath.indexOf("~"); int end = relativeP...
d6c3ecaf-b372-407e-994e-51ded359d1ac
public static boolean isUserDir(String relativePath){ //This method checks if we should use the userDir or rootDir if(relativePath.startsWith("/~")){ return true; } return false; }
7ebba899-81a1-420f-bcca-05aa118b7d73
public static String headerGenerator(String relativePath, String content){ //This method generates the header of a response for a valid request. String output = "HTTP/1.1 200 OK \r\n" + getDateString()+ "\r\n" + "Content-Type:"+ getMIME(relativePath)+"\r\n" + "Content-Length:"+content.length()+ "\r\n...
b8724129-a604-47a1-bc20-1dbef11cdd80
public static String getMIME(String str){ //This method gets the MIME according to the extension. if(str.endsWith("/")) return "text/html"; String extension = str.substring(str.lastIndexOf(".")+1); switch (extension){ case "html": return "text/html"; case "htm": return "text/html"; case "jpeg": ...
c1d097c6-09ca-42d8-8022-09305b647a0e
public byte[] imageToByte (String relativePath, String dir) throws FileNotFoundException{ //This method converts images to byte arrays. File file = new File(dir+ relativePath); InputStream ios = new FileInputStream(file); ByteArrayOutputStream ous = new ByteArrayOutputStream(); try { byte []buffer = ne...