📄 sunspotproperties.java
字号:
/* * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is * described in this document. In particular, and without limitation, these intellectual property rights may * include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents * or pending patent applications in the U.S. and in other countries. * * U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. * standard license agreement and applicable provisions of the FAR and its supplements. * * Use is subject to license terms. * * This distribution may include materials developed by third parties. Sun, Sun Microsystems, the Sun logo and * Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. * * Copyright (c) 2006 Sun Microsystems, Inc. Tous droits r?serv?s. * * Sun Microsystems, Inc. d?tient les droits de propri?t? intellectuels relatifs ? la technologie incorpor?e dans * le produit qui est d?crit dans ce document. En particulier, et ce sans limitation, ces droits de propri?t? * intellectuelle peuvent inclure un ou plus des brevets am?ricains list?s ? l'adresse http://www.sun.com/patents * et un ou les brevets suppl?mentaires ou les applications de brevet en attente aux Etats - Unis et dans les * autres pays. * * L'utilisation est soumise aux termes du contrat de licence. * * Cette distribution peut comprendre des composants d?velopp?s par des tierces parties. * Sun, Sun Microsystems, le logo Sun et Java sont des marques de fabrique ou des marques d?pos?es de Sun * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */package com.sun.spot.spotworld.usb.spotselector;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.io.StringWriter;import java.util.Properties;public class SunSpotProperties { boolean useSunSpotProperties; Properties sunSpotProperties; File sunSpotPropertiesFile; boolean isVerbose; public SunSpotProperties() { this(false); } public SunSpotProperties(boolean isVerbose) { this.isVerbose = isVerbose; sunSpotProperties = new Properties(); String userHome = System.getProperty("user.home"); String fileSeparator=System.getProperty("file.separator"); sunSpotPropertiesFile = new File(userHome + fileSeparator+".sunspot.properties"); if (this.isVerbose) SpotSelector.infoOut.println("Loading default.basestation property..."); try { FileInputStream sunSpotPropertiesFileInputStream = new FileInputStream(sunSpotPropertiesFile); sunSpotProperties.load(sunSpotPropertiesFileInputStream); useSunSpotProperties = true; } catch (IOException e) { // TODO Auto-generated catch block SpotSelector.infoOut.println("Warning: sunspot properties not found. (" + sunSpotPropertiesFile.getName() + ")"); useSunSpotProperties = false; } } public String readProperty(String key) { if (useSunSpotProperties) return sunSpotProperties.getProperty(key); else return null; } public void writeProperty(String key, String value) { writeProperty(key, value, ""); } private String getNewPropertyString(String key,String value, String comment, String lineseparator) { String newPropertyString=""; if ((comment!=null)&&(!comment.equals(""))) { newPropertyString="# " + comment + lineseparator; } newPropertyString+=key + "=" + value; return newPropertyString; } public void writeProperty(String key, String value, String comment) { String lineSeparator=System.getProperty("line.separator","\n"); if (useSunSpotProperties) { if (isVerbose) SpotSelector.infoOut.println("Saving " + value + " as new " + key + " property to " + sunSpotPropertiesFile.getName()); sunSpotProperties.setProperty(key, value); try { StringWriter sw=new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); BufferedReader br = new BufferedReader(new FileReader(sunSpotPropertiesFile)); String line; boolean replaced=false; while ((line = br.readLine()) != null) { if (line.startsWith(key)) { line=getNewPropertyString(key, value, comment,lineSeparator); replaced=true; } if (!line.equals("# "+comment)) { bw.write(line+lineSeparator); } } if (!replaced) { bw.write(getNewPropertyString(key, value, comment,lineSeparator)); } bw.flush(); br.close(); FileWriter sunspotPropertiesFileWriter = new FileWriter(sunSpotPropertiesFile); sunspotPropertiesFileWriter.write(sw.toString()); sunspotPropertiesFileWriter.close(); sw.close(); } catch (IOException e) { SpotSelector.infoOut.println("Warning: could not save new " + key + "=" + value + " to SunSPOT property file. (" + sunSpotPropertiesFile.getName() + ")"); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -