use of java.io.EOFException in project android_frameworks_base by ResurrectionRemix.
the class BackupManagerService method parseLeftoverJournals.
private void parseLeftoverJournals() {
for (File f : mJournalDir.listFiles()) {
if (mJournal == null || f.compareTo(mJournal) != 0) {
// This isn't the current journal, so it must be a leftover. Read
// out the package names mentioned there and schedule them for
// backup.
RandomAccessFile in = null;
try {
Slog.i(TAG, "Found stale backup journal, scheduling");
in = new RandomAccessFile(f, "r");
while (true) {
String packageName = in.readUTF();
if (MORE_DEBUG)
Slog.i(TAG, " " + packageName);
dataChangedImpl(packageName);
}
} catch (EOFException e) {
// no more data; we're done
} catch (Exception e) {
Slog.e(TAG, "Can't read " + f, e);
} finally {
// close/delete the file
try {
if (in != null)
in.close();
} catch (IOException e) {
}
f.delete();
}
}
}
}
use of java.io.EOFException in project android_frameworks_base by ResurrectionRemix.
the class BackupManagerService method initPackageTracking.
private void initPackageTracking() {
if (MORE_DEBUG)
Slog.v(TAG, "` tracking");
// Remember our ancestral dataset
mTokenFile = new File(mBaseStateDir, "ancestral");
try {
RandomAccessFile tf = new RandomAccessFile(mTokenFile, "r");
int version = tf.readInt();
if (version == CURRENT_ANCESTRAL_RECORD_VERSION) {
mAncestralToken = tf.readLong();
mCurrentToken = tf.readLong();
int numPackages = tf.readInt();
if (numPackages >= 0) {
mAncestralPackages = new HashSet<String>();
for (int i = 0; i < numPackages; i++) {
String pkgName = tf.readUTF();
mAncestralPackages.add(pkgName);
}
}
}
tf.close();
} catch (FileNotFoundException fnf) {
// Probably innocuous
Slog.v(TAG, "No ancestral data");
} catch (IOException e) {
Slog.w(TAG, "Unable to read token file", e);
}
// Keep a log of what apps we've ever backed up. Because we might have
// rebooted in the middle of an operation that was removing something from
// this log, we sanity-check its contents here and reconstruct it.
mEverStored = new File(mBaseStateDir, "processed");
File tempProcessedFile = new File(mBaseStateDir, "processed.new");
// Ignore it -- we'll validate "processed" against the current package set.
if (tempProcessedFile.exists()) {
tempProcessedFile.delete();
}
// file to continue the recordkeeping.
if (mEverStored.exists()) {
RandomAccessFile temp = null;
RandomAccessFile in = null;
try {
temp = new RandomAccessFile(tempProcessedFile, "rws");
in = new RandomAccessFile(mEverStored, "r");
// Loop until we hit EOF
while (true) {
String pkg = in.readUTF();
try {
// is this package still present?
mPackageManager.getPackageInfo(pkg, 0);
// if we get here then yes it is; remember it
mEverStoredApps.add(pkg);
temp.writeUTF(pkg);
if (MORE_DEBUG)
Slog.v(TAG, " + " + pkg);
} catch (NameNotFoundException e) {
// nope, this package was uninstalled; don't include it
if (MORE_DEBUG)
Slog.v(TAG, " - " + pkg);
}
}
} catch (EOFException e) {
// old one with the new one then reopen the file for continuing use.
if (!tempProcessedFile.renameTo(mEverStored)) {
Slog.e(TAG, "Error renaming " + tempProcessedFile + " to " + mEverStored);
}
} catch (IOException e) {
Slog.e(TAG, "Error in processed file", e);
} finally {
try {
if (temp != null)
temp.close();
} catch (IOException e) {
}
try {
if (in != null)
in.close();
} catch (IOException e) {
}
}
}
synchronized (mQueueLock) {
// Resume the full-data backup queue
mFullBackupQueue = readFullBackupSchedule();
}
// Register for broadcasts about package install, etc., so we can
// update the provider list.
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addDataScheme("package");
mContext.registerReceiver(mBroadcastReceiver, filter);
// Register for events related to sdcard installation.
IntentFilter sdFilter = new IntentFilter();
sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
mContext.registerReceiver(mBroadcastReceiver, sdFilter);
}
use of java.io.EOFException in project android_frameworks_base by ResurrectionRemix.
the class SettingsBackupAgent method readOldChecksums.
private long[] readOldChecksums(ParcelFileDescriptor oldState) throws IOException {
long[] stateChecksums = new long[STATE_SIZE];
DataInputStream dataInput = new DataInputStream(new FileInputStream(oldState.getFileDescriptor()));
try {
int stateVersion = dataInput.readInt();
if (stateVersion > STATE_VERSION) {
// Constrain the maximum state version this backup agent
// can handle in case a newer or corrupt backup set existed
stateVersion = STATE_VERSION;
}
for (int i = 0; i < STATE_SIZES[stateVersion]; i++) {
stateChecksums[i] = dataInput.readLong();
}
} catch (EOFException eof) {
// With the default 0 checksum we'll wind up forcing a backup of
// any unhandled data sets, which is appropriate.
}
dataInput.close();
return stateChecksums;
}
use of java.io.EOFException in project tdi-studio-se by Talend.
the class JSONFileStep1Form method addFieldsListeners.
/**
* Main Fields addControls.
*/
@Override
protected void addFieldsListeners() {
// fileFieldXsd : Event modifyText
// fileFieldXsd.addModifyListener(new ModifyListener() {
//
// public void modifyText(final ModifyEvent e) {
// getConnection().setXsdFilePath(fileFieldXsd.getText());
// treePopulator.populateTree(fileFieldXsd.getText(), treeNode);
// checkFieldsValue();
// }
// });
// fileFieldJSON.addSelectionListener(new SelectionListener() {
//
// public void widgetSelected(SelectionEvent event) {
// if (fileFieldJSON.getResult() == null) {
// return;
// }
// String text = fileFieldJSON.getText();
// if (isContextMode()) {
// ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(
// connectionItem.getConnection(), true);
// text = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, text));
// }
// // getConnection().setJSONFilePath(PathUtils.getPortablePath(JSONXsdFilePath.getText()));
// File file = new File(text);
// if (file.exists()) {
// if (file.exists()) {
// String tempxml = JSONUtil.changeJsonToXml(text);
// JSONFileStep1Form.this.wizard.setTempJsonPath(tempxml);
// valid = treePopulator.populateTree(tempxml, treeNode);
// }
// // add for bug TDI-20432
// checkFieldsValue();
// }
//
// }
//
// public void widgetDefaultSelected(SelectionEvent e) {
//
// }
// });
readbyCombo.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
EJsonReadbyMode eJsonReadbyMode = EJsonReadbyMode.getEJsonReadbyModeByDisplayName(readbyCombo.getText());
if (eJsonReadbyMode == null) {
eJsonReadbyMode = getDefaultJsonReadbyMode();
}
String readbyMode = eJsonReadbyMode.getValue();
JSONFileStep1Form.this.wizard.setReadbyMode(readbyMode);
String jsonPath = fileFieldJSON.getText();
String text = validateJsonFilePath(jsonPath);
if (text == null || text.isEmpty()) {
return;
}
String tempxml = null;
if (EJsonReadbyMode.JSONPATH.getValue().equals(readbyMode)) {
tempxml = text;
} else {
tempxml = JSONUtil.changeJsonToXml(text);
}
JSONFileStep1Form.this.wizard.setTempJsonPath(tempxml);
switchPopulator(readbyMode, tempxml);
}
});
// fileFieldJSON : Event modifyText
fileFieldJSON.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent e) {
String jsonPath = fileFieldJSON.getText();
String _jsonPath = jsonPath;
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
jsonPath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, jsonPath));
}
String text = validateJsonFilePath(jsonPath);
if (text == null || text.isEmpty()) {
return;
}
String tempxml = null;
String readbyMode = JSONFileStep1Form.this.wizard.getReadbyMode();
if (EJsonReadbyMode.JSONPATH.getValue().equals(readbyMode)) {
tempxml = text;
} else {
tempxml = JSONUtil.changeJsonToXml(text);
}
File file = new File(text);
if (!file.exists()) {
file = new File(JSONUtil.tempJSONXsdPath);
}
JSONFileStep1Form.this.wizard.setTempJsonPath(tempxml);
String limitString = commonNodesLimitation.getText();
try {
limit = Integer.valueOf(limitString);
labelLimitation.setToolTipText(MessageFormat.format(Messages.JSONLimitToolTip, limit));
} catch (Exception excpt) {
// nothing need to do
}
switchPopulator(readbyMode, tempxml);
// }
// add for bug TDI-20432
checkFieldsValue();
if (getConnection().getJSONFilePath() != null && !getConnection().getJSONFilePath().equals(text)) {
getConnection().getLoop().clear();
xsdPathChanged = true;
} else {
xsdPathChanged = false;
}
if (isContextMode()) {
jsonPath = _jsonPath;
}
if (Path.fromOSString(jsonPath).toFile().isFile()) {
getConnection().setJSONFilePath(PathUtils.getPortablePath(jsonPath));
} else {
getConnection().setJSONFilePath(jsonPath);
}
JSONWizard wizard = ((JSONWizard) getPage().getWizard());
wizard.setTreeRootNode(treeNode);
BufferedReader in = null;
try {
Charset guessedCharset = CharsetToolkit.guessEncoding(file, 4096);
String str;
in = new BufferedReader(new InputStreamReader(new FileInputStream(file), guessedCharset.displayName()));
while ((str = in.readLine()) != null) {
if (str.contains("encoding")) {
//$NON-NLS-1$
//$NON-NLS-1$
String regex = "^<\\?JSON\\s*version=\\\"[^\\\"]*\\\"\\s*encoding=\\\"([^\\\"]*)\\\"\\?>$";
Perl5Compiler compiler = new Perl5Compiler();
Perl5Matcher matcher = new Perl5Matcher();
Pattern pattern = null;
try {
pattern = compiler.compile(regex);
if (matcher.contains(str, pattern)) {
MatchResult matchResult = matcher.getMatch();
if (matchResult != null) {
encoding = matchResult.group(1);
}
}
} catch (MalformedPatternException malE) {
ExceptionHandler.process(malE);
}
}
}
} catch (Exception ex) {
String fileStr = text;
String msgError = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"JSON" + " \"" + fileStr.replace("\\\\", "\\") + //$NON-NLS-1$
"\"\n";
if (ex instanceof FileNotFoundException) {
msgError = msgError + "is not found";
} else if (ex instanceof EOFException) {
msgError = msgError + "have an incorrect character EOF";
} else if (ex instanceof IOException) {
msgError = msgError + "is locked by another soft";
} else {
msgError = msgError + "doesn't exist";
}
if (!isReadOnly()) {
updateStatus(IStatus.ERROR, msgError);
}
// ExceptionHandler.process(ex);
} finally {
try {
if (in != null) {
in.close();
}
} catch (Exception ex2) {
ExceptionHandler.process(ex2);
}
}
if (getConnection().getEncoding() == null || "".equals(getConnection().getEncoding())) {
//$NON-NLS-1$
getConnection().setEncoding(encoding);
if (encoding != null && !("").equals(encoding)) {
//$NON-NLS-1$
encodingCombo.setText(encoding);
} else {
//$NON-NLS-1$
encodingCombo.setText("UTF-8");
}
}
// if (tempJSONXsdPath != null && getConnection().getFileContent() != null
// && getConnection().getFileContent().length > 0 && !isModifing) {
// valid = treePopulator.populateTree(tempJSONXsdPath, treeNode);
// } else {
// valid = treePopulator.populateTree(text, treeNode);
// }
checkFieldsValue();
isModifing = true;
}
});
// Event encodingCombo
encodingCombo.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent e) {
getConnection().setEncoding(encodingCombo.getText());
checkFieldsValue();
}
});
}
use of java.io.EOFException in project tdi-studio-se by Talend.
the class JSONFileStep2Form method checkFilePathAndManageIt.
/**
* checkFileFieldsValue active fileViewer if file exist.
*
* @throws IOException
*/
private void checkFilePathAndManageIt() {
updateStatus(IStatus.OK, null);
filePathIsDone = false;
if (getConnection().getJSONFilePath() == "") {
//$NON-NLS-1$
fileJSONText.setText("When Filepath is specified, you can read here the" + " " + TreePopulator.getMaximumRowsToPreview() + " " + "first rows of the file.");
} else {
fileJSONText.setText("Check if the file exist ...");
StringBuilder previewRows = new StringBuilder();
BufferedReader in = null;
//$NON-NLS-1$
String pathStr = "";
try {
if (tempJSONXsdPath != null) {
pathStr = tempJSONXsdPath;
} else {
pathStr = getConnection().getJSONFilePath();
}
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
pathStr = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, pathStr));
}
File file = new File(pathStr);
if (!file.exists()) {
file.createNewFile();
FileOutputStream outStream;
try {
outStream = new FileOutputStream(file);
outStream.write(getConnection().getFileContent());
outStream.close();
} catch (FileNotFoundException e1) {
ExceptionHandler.process(e1);
} catch (IOException e) {
ExceptionHandler.process(e);
}
}
Charset guessedCharset = CharsetToolkit.guessEncoding(file, 4096);
String str;
in = new BufferedReader(new InputStreamReader(new FileInputStream(pathStr), guessedCharset.displayName()));
while ((str = in.readLine()) != null) {
//$NON-NLS-1$
previewRows.append(str + "\n");
}
// show lines
fileJSONText.setText(new String(previewRows));
filePathIsDone = true;
} catch (Exception e) {
String msgError = "File" + " \"" + fileJSONText.getText().replace("\\\\", "\\") + "\"\n";
if (e instanceof FileNotFoundException) {
msgError = msgError + "is not found";
} else if (e instanceof EOFException) {
msgError = msgError + "have an incorrect character EOF";
} else if (e instanceof IOException) {
msgError = msgError + "is locked by another soft";
} else {
msgError = msgError + "doesn't exist";
}
fileJSONText.setText(msgError);
if (!isReadOnly()) {
updateStatus(IStatus.ERROR, msgError);
}
//$NON-NLS-1$
log.error(msgError + " " + e.getMessage());
} finally {
String msgError = "File" + " \"" + fileJSONText.getText().replace("\\\\", "\\") + "\"\n";
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
msgError = msgError + "is locked by another soft";
}
}
checkFieldsValue();
}
}
Aggregations