Skip to content

Commit

Permalink
Trip stops generating > OOM > use SQL prepared statements
Browse files Browse the repository at this point in the history
  • Loading branch information
mmathieum committed Feb 16, 2024
1 parent 7c3dcf6 commit 0c28a3a
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 353 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ dependencies {
//noinspection DependencyNotationArgument // fixed in AGP 8.3.0 https://issuetracker.google.com/issues/295282939
implementation(libs.bundles.kotlin)

implementation(libs.androidx.collection)

api(libs.bundles.commons)
api(libs.xerial.SQLiteJDBC)

Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/mtransit/parser/FileUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.mtransit.parser;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

@SuppressWarnings("unused")
public final class FileUtils {
Expand Down Expand Up @@ -30,4 +33,24 @@ public static void delete(@NotNull File file) {
throw new MTLog.Fatal("Deletion of the directory '%s' failed!", file);
}
}

@Nullable
public static Long size(@NotNull File file) {
try {
return Files.size(file.toPath());
} catch (IOException ioe) {
MTLog.logNonFatal(ioe, "Error while reading size of %s!", file);
return null;
}
}

@Nullable
public static String sizeToDiplayString(@Nullable Long size) {
try {
return org.apache.commons.io.FileUtils.byteCountToDisplaySize(size == null ? 0L : size);
} catch (Exception e) {
MTLog.logNonFatal(e, "Error while converting size of %s!", size);
return null;
}
}
}
13 changes: 13 additions & 0 deletions src/main/java/org/mtransit/parser/MTLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ public static void logFatal(@NotNull Throwable t, @NotNull String format, @Nulla
System.exit(-1);
}

public static void waitForEnter() {
if (DefaultAgencyTools.IS_CI) {
return;
}
System.out.println("\nPress Enter to continue...");
try {
//noinspection ResultOfMethodCallIgnored
System.in.read(new byte[2]); // requires run { standardInput = System.in } in build.gradle
} catch (Exception e) {
throw new MTLog.Fatal(e, "Error while waiting for Enter!");
}
}

public static class Fatal extends RuntimeException {
public Fatal(@NotNull String format, @Nullable Object... args) {
super();
Expand Down
Loading

0 comments on commit 0c28a3a

Please sign in to comment.