-
Notifications
You must be signed in to change notification settings - Fork 0
Java02. ДЗ 02, Васильев Роман #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| group 'com.github.nizshee' | ||
| version '1.0-SNAPSHOT' | ||
|
|
||
| apply plugin: 'java' | ||
|
|
||
| sourceCompatibility = 1.8 | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| compile group: 'berkeleydb', name: 'je', version: '3.2.76' | ||
| testCompile group: 'junit', name: 'junit', version: '4.11' | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #Fri Sep 16 16:31:37 MSK 2016 | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| rootProject.name = 'lazy-factory' | ||
| rootProject.name = 'hw11' | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package com.github.nizshee; | ||
|
|
||
|
|
||
| import com.github.nizshee.cvs.CVS; | ||
| import com.github.nizshee.exception.StateException; | ||
| import com.github.nizshee.exception.WorkspaceException; | ||
| import com.github.nizshee.frontend.Frontend; | ||
| import com.github.nizshee.index.InMemoryIndex; | ||
| import com.github.nizshee.tags.InMemoryTags; | ||
| import com.github.nizshee.tags.Tags; | ||
| import com.github.nizshee.workspace.FileWorkspace; | ||
|
|
||
| import java.io.*; | ||
| import java.nio.file.Paths; | ||
| import java.util.*; | ||
|
|
||
| public class Main { | ||
|
|
||
| private final static String CVS = ".cvs"; | ||
| private final static String TAGS = ".tags"; | ||
| private final static String WORKDIR = "workdir"; | ||
|
|
||
| @SuppressWarnings("ResultOfMethodCallIgnored") | ||
| public static void main(String args[]) throws Exception { | ||
|
|
||
| Paths.get(WORKDIR).toFile().mkdirs(); | ||
|
|
||
| Tags tags = restoreTags(); | ||
| CVS cvs = restoreCVS(); | ||
|
|
||
|
|
||
| Frontend frontend = new Frontend(tags, cvs); | ||
| frontend.eval(args); | ||
|
|
||
| if (cvs.current() != null) { | ||
| dumpTags(tags); | ||
| dumpCVS(cvs); | ||
| } | ||
| } | ||
|
|
||
| private static CVS restoreCVS() throws IOException, ClassNotFoundException, WorkspaceException, StateException { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. см restoreTags |
||
| try (FileInputStream fis = new FileInputStream(WORKDIR + "/" + CVS)) { | ||
| ObjectInputStream ois = new ObjectInputStream(fis); | ||
| return (CVS) ois.readObject(); | ||
| } catch (FileNotFoundException ignore) { | ||
| return new CVS(new FileWorkspace(WORKDIR), new InMemoryIndex(new HashMap<>()), | ||
| Arrays.asList(CVS, TAGS)); | ||
| } | ||
| } | ||
|
|
||
| private static void dumpCVS(CVS cvs) throws IOException { | ||
| FileOutputStream fos = new FileOutputStream(WORKDIR + "/" + CVS); | ||
| ObjectOutputStream oos = new ObjectOutputStream(fos); | ||
| oos.writeObject(cvs); | ||
| fos.close(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. см dumpTags |
||
| } | ||
|
|
||
| private static Tags restoreTags() throws IOException, ClassNotFoundException { | ||
| try (FileInputStream fis = new FileInputStream(WORKDIR + "/" + TAGS)) { | ||
| ObjectInputStream ois = new ObjectInputStream(fis); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. без fis можно обойтись |
||
| return (Tags) ois.readObject(); | ||
| } catch (FileNotFoundException ignore) { | ||
| return new InMemoryTags(); | ||
| } | ||
| } | ||
|
|
||
| private static void dumpTags(Tags tags) throws IOException { | ||
| FileOutputStream fos = new FileOutputStream(WORKDIR + "/" + TAGS); | ||
| ObjectOutputStream oos = new ObjectOutputStream(fos); | ||
| oos.writeObject(tags); | ||
| fos.close(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не всегда исполнение дойдет до сюда -0.5 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oos нужно как минимум флашить в такой реализации и лучше переменную fos не заводить, можно oos обойтись |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зачем подавлять для всего метода?