本文整理汇总了Java中java.io.ObjectInputStream.available方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectInputStream.available方法的具体用法?Java ObjectInputStream.available怎么用?Java ObjectInputStream.available使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.ObjectInputStream
的用法示例。
在下文中一共展示了ObjectInputStream.available方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadStats
import java.io.ObjectInputStream; //导入方法依赖的package包/类
/**
* Loads the statistics from a file
*/
protected static void loadStats(){
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new FileNameExtensionFilter("Keys per second statistics file", "kpsstats"));
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if(chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION){
return;
}
try{
ObjectInputStream in = new ObjectInputStream(new FileInputStream(chooser.getSelectedFile()));
TotPanel.hits = in.readInt();
avg = in.readDouble();
max = in.readInt();
n = in.readLong();
prev = in.readInt();
tmp.set(in.readInt());
while(in.available() > 0){
Key key = keys.get(in.readInt());
Key obj = ((Key)in.readObject());
if(key != null){
key.count = obj.count;
}
}
in.close();
frame.repaint();
graphFrame.repaint();
JOptionPane.showMessageDialog(null, "Statistics succesfully loaded", "Keys per second", JOptionPane.INFORMATION_MESSAGE);
}catch(IOException | ClassNotFoundException e){
JOptionPane.showMessageDialog(null, "Failed to load the statistics!", "Keys per second", JOptionPane.ERROR_MESSAGE);
}
}
示例2: loadLegacyFormat
import java.io.ObjectInputStream; //导入方法依赖的package包/类
/**
* Loads a legacy configuration file
* @param saveloc The save location
* @return Whether or not the config was loaded successfully
*/
@SuppressWarnings("unchecked")
private final boolean loadLegacyFormat(File saveloc){
try {
ObjectInputStream objin = new ObjectInputStream(new FileInputStream(saveloc));
keyinfo = (List<KeyInformation>) objin.readObject();
showMax = objin.readBoolean();
showCur = objin.readBoolean();
showAvg = objin.readBoolean();
showGraph = objin.readBoolean();
graphAvg = objin.readBoolean();
backlog = objin.readInt();
updateRate = objin.readInt();
double version = 3.0D;
if(objin.available() > 0){
customColors = objin.readBoolean();
background = (Color)objin.readObject();
foreground = (Color)objin.readObject();
if(objin.available() > 0){
trackAll = objin.readBoolean();
showKeys = objin.readBoolean();
if(objin.available() > 0){
version = objin.readDouble();
}
}
}
if(version >= 3.9){
precision = objin.readInt();
}
if(version >= 3.10){
opacitybg = objin.readFloat();
opacityfg = objin.readFloat();
}
if(version >= 4.0D){
size = objin.readDouble();
}
if(version >= 4.2D){
overlay = objin.readBoolean();
}
objin.close();
for(KeyInformation info : keyinfo){
if(version < 3.7D){
info.visible = true;
}
if(info.index > KeyInformation.autoIndex){
KeyInformation.autoIndex = info.index + 1;
}
}
return true;
} catch (Exception e1) {
e1.printStackTrace();
return false;
}
}