use of au.com.bytecode.opencsv.CSVWriter in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class RealmHelper method prepareOpenCellUploadData.
/**
* Prepares the CSV file used to upload new data to the OCID server.
* <p/>
* OCID CSV upload format:
* <p/>
* "cellid" = CID (in UMTS long format)
* "measured_at" = time
* "rating" = gpsd_accu
* "act" = RAT (TEXT):
* 1xRTT, CDMA, eHRPD, IS95A, IS95B, EVDO_0, EVDO_A, EVDO_B,
* UMTS, HSPA+, HSDPA, HSUPA, HSPA, LTE, EDGE, GPRS, GSM
*/
public boolean prepareOpenCellUploadData(Realm realm) {
boolean result;
File dir = new File(mExternalFilesDirPath + "OpenCellID/");
if (!dir.exists()) {
result = dir.mkdirs();
if (!result) {
return false;
}
}
File file = new File(dir, "aimsicd-ocid-data.csv");
try {
// Get data not yet submitted:
RealmResults<Measure> c;
c = getOCIDSubmitData(realm);
// Check if we have something to upload:
if (c.size() > 0) {
if (!file.exists()) {
result = file.createNewFile();
if (!result) {
return false;
}
// OCID CSV upload format and items
// mcc,mnc,lac,cellid,lon,lat,signal,measured_at,rating,speed,direction,act,ta,psc,tac,pci,sid,nid,bid
CSVWriter csvWrite = new CSVWriter(new FileWriter(file));
// TODO: Add "act"
csvWrite.writeNext("mcc,mnc,lac,cellid,lon,lat,signal,measured_at,rating");
int size = c.size();
log.debug("OCID UPLOAD: row count = " + size);
for (Measure measure : c) {
csvWrite.writeNext(String.valueOf(measure.getBaseStation().getMobileCountryCode()), String.valueOf(measure.getBaseStation().getMobileNetworkCode()), String.valueOf(measure.getBaseStation().getLocationAreaCode()), String.valueOf(measure.getBaseStation().getCellId()), String.valueOf(measure.getGpsLocation().getLongitude()), String.valueOf(measure.getGpsLocation().getLatitude()), String.valueOf(measure.getRxSignal()), String.valueOf(measure.getTime().getTime()), String.valueOf(measure.getGpsLocation().getAccuracy()));
}
csvWrite.close();
}
return true;
}
return false;
} catch (Exception e) {
log.error("prepareOpenCellUploadData(): Error creating OpenCellID Upload Data: ", e);
return false;
}
}
use of au.com.bytecode.opencsv.CSVWriter in project play-cookbook by spinscale.
the class CsvHelper method delete.
public <T extends CsvModel> void delete(T model) {
if (model._key() == null) {
return;
}
try {
File out = File.createTempFile(model.getClass().getSimpleName(), null);
CSVWriter writer = new CSVWriter(new FileWriter(out), separator);
List<String[]> entries = getEntriesFromFile();
for (String[] fields : entries) {
if (!fields[0].equals(model._key().toString())) {
writer.writeNext(fields);
}
}
writer.close();
moveDataFile(out);
} catch (Exception e) {
Logger.error(e, "Error in csv helper");
}
}
use of au.com.bytecode.opencsv.CSVWriter in project play-cookbook by spinscale.
the class CsvHelper method save.
public synchronized <T extends CsvModel> T save(T model) {
try {
File out = File.createTempFile(model.getClass().getSimpleName(), null);
CSVWriter writer = new CSVWriter(new FileWriter(out), separator);
if (dataFile.exists()) {
List<String[]> myEntries = getEntriesFromFile();
for (String[] fields : myEntries) {
// update it
if (fields[0].equals(model._key())) {
String[] arrayObject = createArrayFromObject(model, model._key().toString());
if (arrayObject != null) {
writer.writeNext(arrayObject);
}
} else {
writer.writeNext(fields);
}
}
}
// insert it if it was not updated...
if (model._key() == null) {
Long id = getNewId();
String[] arrayObject = createArrayFromObject(model, id.toString());
writer.writeNext(arrayObject);
model.id = id;
}
writer.close();
moveDataFile(out);
} catch (Exception e) {
Logger.error(e, "Error in csv helper");
}
return model;
}
use of au.com.bytecode.opencsv.CSVWriter in project dbeaver by serge-rider.
the class PostgreUtils method generateObjectString.
public static String generateObjectString(Object[] values) throws DBCException {
String[] line = new String[values.length];
for (int i = 0; i < values.length; i++) {
final Object value = values[i];
line[i] = value == null ? "NULL" : value.toString();
}
StringWriter out = new StringWriter();
final CSVWriter writer = new CSVWriter(out);
writer.writeNext(line);
try {
writer.flush();
} catch (IOException e) {
log.warn(e);
}
return "(" + out.toString().trim() + ")";
}
use of au.com.bytecode.opencsv.CSVWriter in project ORCID-Source by ORCID.
the class OrgManagerImpl method writeAmbiguousOrgs.
@Override
public void writeAmbiguousOrgs(Writer writer) {
@SuppressWarnings("resource") CSVWriter csvWriter = new CSVWriter(writer);
csvWriter.writeNext(AMBIGUOUS_ORGS_HEADER);
int firstResult = 0;
List<AmbiguousOrgEntity> chunk = null;
do {
chunk = getAmbiguousOrgs(firstResult, CHUNK_SIZE);
for (AmbiguousOrgEntity orgEntity : chunk) {
String[] line = new String[] { String.valueOf(orgEntity.getId()), orgEntity.getSourceOrcid(), orgEntity.getName(), orgEntity.getCity(), orgEntity.getRegion(), orgEntity.getCountry().value(), String.valueOf(orgEntity.getUsedCount()) };
csvWriter.writeNext(line);
}
firstResult += chunk.size();
} while (!chunk.isEmpty());
}
Aggregations